CI: output to dist/ with "node-*" prefix (#156)

* Add "--output" CLI argument

* CI: output to dist/ with "node-*" prefix

* requests: remove tempFile when download failed
This commit is contained in:
Jesse Chan 2021-04-07 17:59:50 +08:00 committed by GitHub
parent c21646bf37
commit 549db84226
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 34 additions and 16 deletions

View File

@ -37,12 +37,12 @@ jobs:
- name: Extract binaries from Docker image
run: |
tar xvf ../out.tar opt/app-root/src/.pkg-cache
tar xvf ../out.tar root/pkg-fetch/dist
- uses: actions/upload-artifact@v2
with:
name: node${{ matrix.target-node }}-linux-x64
path: opt/app-root/src/.pkg-cache/**/built-*
path: root/pkg-fetch/dist/*
linux-arm64:
runs-on: ubuntu-18.04
@ -65,7 +65,7 @@ jobs:
- run: yarn install
- run: yarn start --node-range node${{ matrix.target-node }} --arch arm64
- run: yarn start --node-range node${{ matrix.target-node }} --arch arm64 --output dist
env:
CC: /usr/bin/aarch64-linux-gnu-gcc-8
CXX: /usr/bin/aarch64-linux-gnu-g++-8
@ -81,4 +81,4 @@ jobs:
- uses: actions/upload-artifact@v2
with:
name: node${{ matrix.target-node }}-linux-arm64
path: /home/runner/.pkg-cache/**/built-*
path: dist/*

View File

@ -26,9 +26,9 @@ jobs:
- run: yarn install
- run: yarn start --node-range node${{ matrix.target-node }}
- run: yarn start --node-range node${{ matrix.target-node }} --output dist
- uses: actions/upload-artifact@v2
with:
name: node${{ matrix.target-node }}-macos-x64
path: /Users/runner/.pkg-cache/**/built-*
path: dist/*

View File

@ -29,14 +29,14 @@ jobs:
- run: choco install nasm
- run: yarn start --node-range node${{ matrix.target-node }} --arch ${{ matrix.target-arch }}
- run: yarn start --node-range node${{ matrix.target-node }} --arch ${{ matrix.target-arch }} --output dist
env:
PKG_BUILD_PATH: build
- uses: actions/upload-artifact@v2
with:
name: node${{ matrix.target-node }}-windows-${{ matrix.target-arch }}
path: C:\\Users\\runneradmin\\.pkg-cache\\**\\built-*
path: dist\\*
windows-vs2019:
runs-on: windows-2019
@ -59,9 +59,9 @@ jobs:
- run: choco install nasm
- run: yarn start --node-range node${{ matrix.target-node }} --arch ${{ matrix.target-arch }}
- run: yarn start --node-range node${{ matrix.target-node }} --arch ${{ matrix.target-arch }} --output dist
- uses: actions/upload-artifact@v2
with:
name: node${{ matrix.target-node }}-windows-${{ matrix.target-arch }}
path: C:\\Users\\runneradmin\\.pkg-cache\\**\\built-*
path: dist\\*

View File

@ -19,4 +19,4 @@ RUN npm install -g yarn
RUN yarn install
RUN yarn start --node-range $PKG_FETCH_OPTION_n
RUN yarn start --node-range $PKG_FETCH_OPTION_n --output dist

View File

@ -24,6 +24,7 @@ async function main() {
type: 'boolean',
})
.conflicts('force-fetch', 'force-build')
.option('output', { alias: 'o', type: 'string' })
.version(version)
.alias('v', 'version')
.help()
@ -36,6 +37,7 @@ async function main() {
test,
'force-fetch': forceFetch,
'force-build': forceBuild,
output,
} = argv;
const local = await need({
@ -44,6 +46,7 @@ async function main() {
arch,
forceFetch,
forceBuild,
output,
});
log.info(local);

View File

@ -47,6 +47,7 @@ interface NeedOptions {
forceFetch?: boolean;
forceBuild?: boolean;
dryRun?: boolean;
output?: string;
nodeRange: string;
platform: string;
arch: string;
@ -54,7 +55,7 @@ interface NeedOptions {
export async function need(opts: NeedOptions) {
// eslint-disable-line complexity
const { forceFetch, forceBuild, dryRun } = opts || {};
const { forceFetch, forceBuild, dryRun, output } = opts || {};
let { nodeRange, platform, arch } = opts || {};
if (!nodeRange) throw wasReported('nodeRange not specified');
@ -96,6 +97,7 @@ export async function need(opts: NeedOptions) {
nodeVersion,
platform,
version,
output,
});
const built = localPlace({
from: 'built',
@ -103,6 +105,7 @@ export async function need(opts: NeedOptions) {
nodeVersion,
platform,
version,
output,
});
const remote = remotePlace({ arch, nodeVersion, platform, version });

View File

@ -23,20 +23,31 @@ interface PlaceOptions {
interface LocalPlaceOptions extends PlaceOptions {
from: string;
output?: string;
}
export function localPlace({
from,
output,
version,
nodeVersion,
platform,
arch,
}: LocalPlaceOptions) {
const binDir = IGNORE_TAG
? path.join(cachePath)
: path.join(cachePath, tagFromVersion(version));
let binDir: string;
return path.resolve(binDir, `${from}-${nodeVersion}-${platform}-${arch}`);
if (output) {
binDir = path.resolve(output);
} else {
binDir = IGNORE_TAG
? path.join(cachePath)
: path.join(cachePath, tagFromVersion(version));
}
return path.resolve(
binDir,
`${output ? 'node' : from}-${nodeVersion}-${platform}-${arch}`
);
}
export interface Remote {

View File

@ -38,6 +38,7 @@ export async function downloadUrl(url: string, file: string) {
})
.catch((e: AxiosError) => {
log.disableProgress();
fs.rmSync(tempFile);
if (e.response) {
throw wasReported(`${e.response.status}`);
} else {