Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: avoid unnecessary release builds #5191

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 13 additions & 12 deletions .github/workflows/build-and-tests.yml
Expand Up @@ -81,37 +81,37 @@ jobs:
target: x86_64-apple-darwin
build: >-
set -e &&
npm run build:napi -- --release &&
npm run build:napi &&
strip -x *.node
- host: windows-latest
build: npm run build:napi -- --release
build: npm run build:napi
target: x86_64-pc-windows-msvc
- host: windows-latest
build: >-
set -e &&
rustup target add i686-pc-windows-msvc &&
npm run build:napi -- --release --target i686-pc-windows-msvc
npm run build:napi -- --target i686-pc-windows-msvc
target: i686-pc-windows-msvc
- host: ubuntu-latest
target: x86_64-unknown-linux-gnu
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
build: >-
set -e &&
rustup target add x86_64-unknown-linux-gnu &&
npm run build:napi -- --release --target x86_64-unknown-linux-gnu &&
npm run build:napi -- --target x86_64-unknown-linux-gnu &&
strip *.node
- host: ubuntu-latest
target: x86_64-unknown-linux-musl
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
build: >-
set -e &&
npm run build:napi -- --release && strip *.node
npm run build:napi && strip *.node
- host: macos-latest
target: aarch64-apple-darwin
build: >-
set -e &&
rustup target add aarch64-apple-darwin &&
npm run build:napi -- --release --target aarch64-apple-darwin &&
npm run build:napi -- --target aarch64-apple-darwin &&
strip -x *.node
- host: ubuntu-latest
target: aarch64-unknown-linux-gnu
Expand All @@ -121,7 +121,7 @@ jobs:
export JEMALLOC_SYS_WITH_LG_PAGE=16 &&
rustup default nightly-2023-10-05 &&
rustup target add aarch64-unknown-linux-gnu &&
npm run build:napi -- --release --target aarch64-unknown-linux-gnu &&
npm run build:napi -- --target aarch64-unknown-linux-gnu &&
aarch64-unknown-linux-gnu-strip *.node
- host: ubuntu-latest
target: armv7-unknown-linux-gnueabihf
Expand All @@ -131,19 +131,19 @@ jobs:
sudo apt-get install gcc-arm-linux-gnueabihf -y
build: >-
set -e &&
npm run build:napi -- --release --target armv7-unknown-linux-gnueabihf &&
npm run build:napi -- --target armv7-unknown-linux-gnueabihf &&
arm-linux-gnueabihf-strip *.node
- host: ubuntu-latest
target: aarch64-linux-android
build: >-
set -e &&
npm run build:napi -- --release --target aarch64-linux-android &&
npm run build:napi -- --target aarch64-linux-android &&
${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip *.node
- host: ubuntu-latest
target: armv7-linux-androideabi
build: >-
set -e &&
npm run build:napi -- --release --target armv7-linux-androideabi &&
npm run build:napi -- --target armv7-linux-androideabi &&
${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip *.node
- host: ubuntu-latest
target: aarch64-unknown-linux-musl
Expand All @@ -153,11 +153,11 @@ jobs:
export JEMALLOC_SYS_WITH_LG_PAGE=16 &&
rustup default nightly-2023-10-05 &&
rustup target add aarch64-unknown-linux-musl &&
RUSTFLAGS='-C target-feature=-crt-static -C linker=aarch64-linux-musl-gcc' npm run build:napi -- --release --target aarch64-unknown-linux-musl &&
RUSTFLAGS='-C target-feature=-crt-static -C linker=aarch64-linux-musl-gcc' npm run build:napi -- --target aarch64-unknown-linux-musl &&
/aarch64-linux-musl-cross/bin/aarch64-linux-musl-strip *.node
- host: windows-latest
target: aarch64-pc-windows-msvc
build: npm run build:napi -- --release --target aarch64-pc-windows-msvc
build: npm run build:napi -- --target aarch64-pc-windows-msvc
name: Build ${{ matrix.settings.name || matrix.settings.target }}
runs-on: ${{ matrix.settings.host }}
timeout-minutes: 30
Expand Down Expand Up @@ -311,6 +311,7 @@ jobs:
needs:
- test
- lint
- build
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As test needs build, this should not be needed (but of course does not hurt, either)

# This needs to be adapted for Rollup 5
if: startsWith(github.ref_name, 'v4')
steps:
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/repl-artefacts.yml
Expand Up @@ -53,7 +53,9 @@ jobs:
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci --ignore-scripts
- name: Build artefacts
run: npm exec -- concurrently -c green,blue,yellow 'npm:build:napi -- --release' 'npm run build:wasm' 'npm:build:cjs' && npm run build:copy-native && npm run build:bootstrap
env:
BUILD_ARTEFACTS: 'build'
run: npm exec -- concurrently -c green,blue,yellow 'npm:build:napi' 'npm run build:wasm' 'npm:build:cjs' && npm run build:copy-native && npm run build:bootstrap
- name: Upload "${{ github.event.number }}/rollup.browser.js" to bucket
uses: zdurham/s3-upload-github-action@master
with:
Expand Down
7 changes: 4 additions & 3 deletions package.json
Expand Up @@ -34,9 +34,10 @@
"scripts": {
"build": "npm run build:wasm && concurrently -c green,blue \"npm run build:napi -- --release\" \"npm:build:js\" && npm run build:copy-native",
"build:quick": "concurrently -c green,blue 'npm:build:napi' 'npm:build:cjs' && npm run build:copy-native",
"build:napi": "napi build --platform --dts native.d.ts --js false --cargo-cwd rust -p bindings_napi --cargo-name bindings_napi",
"build:wasm": "wasm-pack build rust/bindings_wasm --out-dir ../../wasm --target web --no-pack && shx rm wasm/.gitignore",
"build:wasm:node": "wasm-pack build rust/bindings_wasm --out-dir ../../wasm-node --target nodejs --no-pack && shx rm wasm-node/.gitignore",
"build:napi": "npm run build:binding -- --binding=napi",
"build:wasm": "npm run build:binding -- --binding=wasm",
"build:wasm:node": "npm run build:binding -- --binding=wasm-node",
"build:binding": "node scripts/build-bindings.js",
"update:napi": "npm run build:napi && npm run build:copy-native",
"build:js": "rollup --config rollup.config.ts --configPlugin typescript",
"build:js:node": "rollup --config rollup.config.ts --configPlugin typescript --configIsBuildNode",
Expand Down
54 changes: 54 additions & 0 deletions scripts/build-bindings.js
@@ -0,0 +1,54 @@
#!/usr/bin/env node

import { exec } from 'node:child_process';
import { env, exit } from 'node:process';
import argsParser from 'yargs-parser';

const parsedArguments = argsParser(process.argv.slice(2));
const binding = parsedArguments.binding;
const target = parsedArguments.target;

const isRelease = env.ROLLUP_RELEASE === 'releasing' || env.BUILD_ARTEFACTS === 'build';

const buildCommands = {
napi: {
dev: 'napi build --platform --dts native.d.ts --js false --cargo-cwd rust -p bindings_napi --cargo-name bindings_napi',
release:
'napi build --platform --dts native.d.ts --js false --cargo-cwd rust -p bindings_napi --cargo-name bindings_napi --release'
},
wasm: {
dev: 'wasm-pack build rust/bindings_wasm --dev --out-dir ../../wasm --target web --no-pack',
postBuild: 'shx rm wasm/.gitignore',
release: 'wasm-pack build rust/bindings_wasm --out-dir ../../wasm --target web --no-pack'
},
'wasm-node': {
dev: 'wasm-pack build rust/bindings_wasm --dev --out-dir ../../wasm-node --target nodejs --no-pack',
postBuild: 'shx rm wasm-node/.gitignore',
release:
'wasm-pack build rust/bindings_wasm --out-dir ../../wasm-node --target nodejs --no-pack'
}
};

const commandToRun = (() => {
const buildCommand = buildCommands[binding][isRelease ? 'release' : 'dev'];
const commandWithTarget = target ? `${buildCommand} --target ${target}` : buildCommand;
const postBuild = buildCommands[binding].postBuild;
return postBuild ? `${commandWithTarget} && ${postBuild}` : commandWithTarget;
})();

console.log(`
command to run: ${commandToRun}
release or dev: ${isRelease ? 'release' : 'dev'}
binding: ${binding}
target: ${target}
`);

exec(commandToRun, (error, stdout, stderr) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using exec, there is a nice runWithEcho helper in scripts/helpers.js that has the advantage that it prints output while the command is running instead of waiting for the end. You would need to turn the arguments into an array, though, but it should make for a better experience when developing locally.
Also, it promisifies the output, which means instead of a force exit, you can just top-level await the function so that errors will abort the script automatically with the full error.

if (error) {
console.error(error);
exit(1);
}

console.log(stdout);
console.error(stderr);
});