Skip to content

Commit 598bd85

Browse files
authored
ci: setup release flow (#137)
<!-- By contributing, you agree to the terms of the license, available in the LICENSE.ARTISTIC file, and of the code of conduct, available in the CODE_OF_CONDUCT.md file. Furthermore, you agree to release under CC0, also available in the LICENSE file, until Notify has fully transitioned to Artistic 2.0. --> <!-- After creating this pull request, the test suite will run. It is expected that if any failures occur in the builds, you either: - fix the errors, - ask for help, or - note that the failures are expected with a detailed explanation. If you do not, a maintainer may prompt you and/or do it themselves, but do note that it will take longer for your contribution to be reviewed if the build does not pass. Running `cargo fmt` and/or `cargo clippy` is NOT required but appreciated! You can remove this text. -->
1 parent b98f42c commit 598bd85

5 files changed

Lines changed: 296 additions & 2 deletions

File tree

‎.editorconfig‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ charset = utf-8
88
trim_trailing_whitespace = true
99
insert_final_newline = true
1010

11+
[*.mjs]
12+
indent_size = 2
13+
1114
[*.toml]
1215
indent_size = 2
1316

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Check version
2+
3+
description: Check if package version has changed
4+
5+
inputs:
6+
file-name:
7+
required: true
8+
description: Path to the package.json file to check
9+
10+
file-url:
11+
required: false
12+
description: URL to compare version against (e.g., https://unpkg.com/@rolldown/notify@latest/package.json)
13+
14+
diff-search:
15+
required: false
16+
default: "false"
17+
description: Use git diff to check for version changes instead of comparing with an external URL (pass 'true' or 'false' as string)
18+
19+
outputs:
20+
version:
21+
description: The version from the package.json
22+
value: ${{ steps.version.outputs.version }}
23+
version_changed:
24+
description: Whether the version has changed
25+
value: ${{ steps.version.outputs.changed }}
26+
27+
runs:
28+
using: composite
29+
steps:
30+
- name: Check version changes
31+
uses: EndBug/version-check@095362f3cd50f690c8fa0e6afeea81834bd8d320 # v3.0.0
32+
id: version
33+
with:
34+
static-checking: ${{ inputs.diff-search != 'true' && 'localIsNew' || '' }}
35+
diff-search: ${{ inputs.diff-search }}
36+
file-url: ${{ inputs.file-url }}
37+
file-name: ${{ inputs.file-name }}
38+
39+
- name: Print version
40+
if: steps.version.outputs.changed == 'true'
41+
shell: bash
42+
env:
43+
VERSION_NUMBER: ${{ steps.version.outputs.version }}
44+
VERSION_TYPE: ${{ steps.version.outputs.type }}
45+
run: |
46+
echo "Version change found! New version: ${VERSION_NUMBER} (${VERSION_TYPE})"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env node
2+
3+
import { readFileSync } from "node:fs";
4+
import { join } from "node:path";
5+
import { setTimeout } from "node:timers/promises";
6+
7+
async function waitForPackage(packageDir) {
8+
const { name, version } = JSON.parse(readFileSync(join(packageDir, "package.json"), "utf8"));
9+
const spec = `${name}@${version}`;
10+
const metadataUrl = `https://registry.npmjs.org/${encodeURIComponent(name)}/${encodeURIComponent(version)}`;
11+
const deadline = Date.now() + 24 * 60 * 60 * 1000;
12+
13+
while (Date.now() < deadline) {
14+
try {
15+
const metadata = await fetch(metadataUrl, {
16+
headers: { "cache-control": "no-cache" },
17+
signal: AbortSignal.timeout(30_000),
18+
});
19+
if (!metadata.ok) throw new Error();
20+
21+
const tarball = await fetch((await metadata.json()).dist.tarball, {
22+
headers: { "cache-control": "no-cache", range: "bytes=0-0" },
23+
signal: AbortSignal.timeout(30_000),
24+
});
25+
await tarball.body?.cancel();
26+
if (!tarball.ok) throw new Error();
27+
28+
console.log(`✓ ${spec} is available.`);
29+
return;
30+
} catch {
31+
await setTimeout(10_000);
32+
}
33+
}
34+
35+
throw new Error(`Timed out waiting for ${spec}.`);
36+
}
37+
38+
Promise.all(process.argv.slice(2).map(waitForPackage)).catch((error) => {
39+
console.error(`::error::${error.message}`);
40+
process.exit(1);
41+
});

‎.github/workflows/release-npm.yml‎

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
name: Release npm
2+
3+
permissions: {}
4+
5+
on:
6+
workflow_dispatch:
7+
push:
8+
branches: [main]
9+
paths:
10+
- notify-napi/package.json
11+
- .github/workflows/release-npm.yml
12+
- .github/actions/check-version/action.yml
13+
- .github/scripts/wait-for-npm-packages.mjs
14+
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.ref }}
17+
cancel-in-progress: false
18+
19+
env:
20+
CARGO_TERM_COLOR: always
21+
22+
defaults:
23+
run:
24+
shell: bash
25+
working-directory: notify-napi
26+
27+
jobs:
28+
check:
29+
name: Check version
30+
if: github.repository == 'rolldown/notify' && github.ref == 'refs/heads/main'
31+
runs-on: ubuntu-latest
32+
permissions:
33+
contents: read
34+
outputs:
35+
version_changed: ${{ steps.check.outputs.version_changed }}
36+
steps:
37+
- uses: taiki-e/checkout-action@7d1e50e93dc4fb3bba58f85018fadf77898aee8b # v1.4.2
38+
39+
- uses: ./.github/actions/check-version
40+
id: check
41+
with:
42+
file-name: notify-napi/package.json
43+
file-url: https://unpkg.com/@rolldown/notify@latest/package.json
44+
45+
build:
46+
name: Build ${{ matrix.target }}
47+
needs: check
48+
if: needs.check.outputs.version_changed == 'true'
49+
runs-on: ${{ matrix.os }}
50+
permissions:
51+
contents: read
52+
strategy:
53+
fail-fast: false
54+
matrix:
55+
include:
56+
- os: macos-latest
57+
target: aarch64-apple-darwin
58+
test: true
59+
- os: macos-latest
60+
target: x86_64-apple-darwin
61+
- os: windows-latest
62+
target: x86_64-pc-windows-msvc
63+
test: true
64+
- os: windows-latest
65+
target: aarch64-pc-windows-msvc
66+
- os: ubuntu-latest
67+
target: x86_64-unknown-linux-gnu
68+
flags: --use-napi-cross
69+
test: true
70+
- os: ubuntu-latest
71+
target: aarch64-unknown-linux-gnu
72+
flags: --use-napi-cross
73+
- os: ubuntu-latest
74+
target: x86_64-unknown-linux-musl
75+
flags: --cross-compile
76+
- os: ubuntu-latest
77+
target: aarch64-unknown-linux-musl
78+
flags: --cross-compile
79+
- os: ubuntu-latest
80+
target: wasm32-wasip1-threads
81+
test: true
82+
steps:
83+
- uses: taiki-e/checkout-action@7d1e50e93dc4fb3bba58f85018fadf77898aee8b # v1.4.2
84+
85+
- uses: oxc-project/setup-rust@3d6fb132fbe7cdcb66bf8ec193911c2945369d12 # v1.0.17
86+
with:
87+
cache-key: release-npm-${{ matrix.target }}
88+
89+
- name: Install Rust target
90+
run: rustup target add ${{ matrix.target }}
91+
92+
- uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5
93+
with:
94+
package_json_file: notify-napi/package.json
95+
96+
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
97+
with:
98+
node-version: 24
99+
cache: pnpm
100+
cache-dependency-path: notify-napi/pnpm-lock.yaml
101+
102+
- name: Install dependencies
103+
run: pnpm install --frozen-lockfile
104+
105+
- uses: goto-bus-stop/setup-zig@abea47f85e598557f500fa1fd2ab7464fcb39406 # v2.2.1
106+
if: contains(matrix.target, 'musl')
107+
with:
108+
version: 0.13.0
109+
110+
- name: Build bindings
111+
run: pnpm run build:native --target ${{ matrix.target }} ${{ matrix.flags }}
112+
113+
- name: Build JavaScript
114+
run: pnpm run build:js
115+
116+
- name: Test native bindings
117+
if: matrix.test && matrix.target != 'wasm32-wasip1-threads'
118+
run: pnpm exec vitest run
119+
120+
- name: Test WASI bindings
121+
if: matrix.target == 'wasm32-wasip1-threads'
122+
run: pnpm exec vitest run --mode wasi
123+
124+
- name: Upload bindings
125+
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
126+
with:
127+
name: bindings-${{ matrix.target }}
128+
if-no-files-found: error
129+
path: notify-napi/dist
130+
131+
publish:
132+
name: Publish npm
133+
needs: build
134+
runs-on: ubuntu-latest
135+
permissions:
136+
contents: read
137+
id-token: write
138+
env:
139+
npm_config_provenance: true
140+
steps:
141+
- uses: taiki-e/checkout-action@7d1e50e93dc4fb3bba58f85018fadf77898aee8b # v1.4.2
142+
143+
- uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5
144+
with:
145+
package_json_file: notify-napi/package.json
146+
147+
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
148+
with:
149+
node-version: 24
150+
cache: pnpm
151+
cache-dependency-path: notify-napi/pnpm-lock.yaml
152+
153+
- name: Install dependencies
154+
run: pnpm install --frozen-lockfile
155+
156+
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
157+
with:
158+
pattern: bindings-*
159+
path: notify-napi/artifacts
160+
161+
- name: Prepare packages
162+
run: |
163+
mkdir -p dist
164+
cp -R artifacts/bindings-wasm32-wasip1-threads/. dist/
165+
pnpm exec napi create-npm-dirs --npm-dir npm
166+
pnpm exec napi artifacts --output-dir artifacts --build-output-dir dist --npm-dir npm
167+
pnpm run build:js
168+
pnpm run typecheck
169+
pnpm exec napi pre-publish --npm-dir npm --no-gh-release -t npm --dry-run
170+
171+
- name: Publish platform packages
172+
run: pnpm exec napi pre-publish --npm-dir npm --no-gh-release -t npm
173+
174+
- name: Wait for platform packages
175+
run: node ../.github/scripts/wait-for-npm-packages.mjs npm/*
176+
177+
- name: Publish package
178+
run: pnpm publish --provenance --access public --no-git-checks

‎notify-napi/package.json‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
{
22
"name": "@rolldown/notify",
33
"version": "0.0.0",
4-
"private": true,
4+
"description": "Native file watching for Node.js, powered by rolldown-notify",
5+
"repository": {
6+
"type": "git",
7+
"url": "git+https://github.com/rolldown/notify.git",
8+
"directory": "notify-napi"
9+
},
10+
"engines": {
11+
"node": ">=20"
12+
},
13+
"publishConfig": {
14+
"access": "public",
15+
"registry": "https://registry.npmjs.org/"
16+
},
517
"packageManager": "pnpm@12.14.0",
618
"module": "dist/index.mjs",
719
"types": "dist/index.d.mts",
@@ -35,6 +47,20 @@
3547
"@napi-rs/wasm-runtime": "~1.2.5"
3648
},
3749
"napi": {
38-
"binaryName": "rolldown_notify"
50+
"binaryName": "rolldown_notify",
51+
"targets": [
52+
"aarch64-apple-darwin",
53+
"aarch64-pc-windows-msvc",
54+
"aarch64-unknown-linux-gnu",
55+
"aarch64-unknown-linux-musl",
56+
"wasm32-wasip1-threads",
57+
"x86_64-apple-darwin",
58+
"x86_64-pc-windows-msvc",
59+
"x86_64-unknown-linux-gnu",
60+
"x86_64-unknown-linux-musl"
61+
],
62+
"wasm": {
63+
"optionalDependency": true
64+
}
3965
}
4066
}

0 commit comments

Comments
 (0)