Skip to content

Commit 0625b8d

Browse files
authored
Merge pull request #9 from cawalch/ps/rr/build__npm_build_and_publish_gh_actions_try_3
build: npm build and publish GH actions try 3
2 parents 003a9fe + b5d17bb commit 0625b8d

File tree

2 files changed

+217
-57
lines changed

2 files changed

+217
-57
lines changed

.github/workflows/CI.yml

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -171,60 +171,3 @@ jobs:
171171
- name: Test bindings
172172
run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-slim npm test
173173

174-
publish:
175-
name: Publish to npm
176-
needs:
177-
- test-macOS-windows-binding
178-
- test-linux-x64-gnu-binding
179-
runs-on: ubuntu-latest
180-
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
181-
steps:
182-
- name: Debug tag info
183-
run: |
184-
echo "GitHub Ref: ${{ github.ref }}"
185-
echo "Event Name: ${{ github.event_name }}"
186-
echo "Is tag? ${{ startsWith(github.ref, 'refs/tags/v') }}"
187-
188-
- uses: actions/checkout@v4
189-
with:
190-
fetch-depth: 0
191-
192-
- name: Setup node
193-
uses: actions/setup-node@v4
194-
with:
195-
node-version: 20
196-
registry-url: 'https://registry.npmjs.org'
197-
cache: 'npm'
198-
199-
- name: Install dependencies
200-
run: npm install
201-
202-
- name: Download all artifacts
203-
uses: actions/download-artifact@v4
204-
with:
205-
path: artifacts
206-
207-
- name: Move artifacts to appropriate directories
208-
run: |
209-
mkdir -p npm
210-
find artifacts -name "*.node" -type f -exec cp {} . \;
211-
ls -la *.node
212-
213-
- name: Extract version from tag
214-
id: extract_version
215-
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
216-
217-
- name: Set version in package.json
218-
run: npm version ${{ steps.extract_version.outputs.VERSION }} --no-git-tag-version
219-
220-
- name: Publish to npm
221-
run: npm publish --access public
222-
env:
223-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
224-
225-
- name: Create GitHub Release
226-
uses: softprops/action-gh-release@v1
227-
with:
228-
files: |
229-
*.node
230-
generate_release_notes: true

.github/workflows/publish.yml

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
name: Publish to NPM
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
env:
8+
DEBUG: napi:*
9+
APP_NAME: node-yara-x
10+
MACOSX_DEPLOYMENT_TARGET: '10.13'
11+
12+
permissions:
13+
contents: read
14+
id-token: write
15+
16+
jobs:
17+
build:
18+
timeout-minutes: 30
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
settings:
23+
- host: macos-latest
24+
target: x86_64-apple-darwin
25+
build: npm run build -- --target x86_64-apple-darwin
26+
- host: ubuntu-latest
27+
target: x86_64-unknown-linux-gnu
28+
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
29+
build: npm run build -- --target x86_64-unknown-linux-gnu
30+
- host: macos-latest
31+
target: aarch64-apple-darwin
32+
build: npm run build -- --target aarch64-apple-darwin
33+
name: stable - ${{ matrix.settings.target }} - node@20
34+
runs-on: ${{ matrix.settings.host }}
35+
steps:
36+
- uses: actions/checkout@v4
37+
- name: Setup node
38+
uses: actions/setup-node@v4
39+
if: ${{ !matrix.settings.docker }}
40+
with:
41+
node-version: 20
42+
cache: 'npm'
43+
- name: Install
44+
uses: dtolnay/rust-toolchain@stable
45+
if: ${{ !matrix.settings.docker }}
46+
with:
47+
toolchain: stable
48+
targets: ${{ matrix.settings.target }}
49+
- name: Cache cargo
50+
uses: actions/cache@v4
51+
with:
52+
path: |
53+
~/.cargo/registry/index/
54+
~/.cargo/registry/cache/
55+
~/.cargo/git/db/
56+
.cargo-cache
57+
target/
58+
key: ${{ matrix.settings.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
59+
restore-keys: |
60+
${{ matrix.settings.target }}-cargo-
61+
- name: Cache npm dependencies
62+
uses: actions/cache@v4
63+
with:
64+
path: ~/.npm
65+
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
66+
restore-keys: |
67+
${{ runner.os }}-npm-
68+
- uses: goto-bus-stop/setup-zig@v2
69+
if: ${{ matrix.settings.target == 'armv7-unknown-linux-gnueabihf' || matrix.settings.target == 'armv7-unknown-linux-musleabihf' }}
70+
with:
71+
version: 0.13.0
72+
- name: Setup toolchain
73+
run: ${{ matrix.settings.setup }}
74+
if: ${{ matrix.settings.setup }}
75+
shell: bash
76+
- name: Install dependencies
77+
run: npm install
78+
- name: Build in docker
79+
uses: addnab/docker-run-action@v3
80+
if: ${{ matrix.settings.docker }}
81+
with:
82+
image: ${{ matrix.settings.docker }}
83+
options: '--user 0:0 -v ${{ github.workspace }}/.cargo-cache/git/db:/usr/local/cargo/git/db -v ${{ github.workspace }}/.cargo/registry/cache:/usr/local/cargo/registry/cache -v ${{ github.workspace }}/.cargo/registry/index:/usr/local/cargo/registry/index -v ${{ github.workspace }}:/build -w /build'
84+
run: ${{ matrix.settings.build }}
85+
- name: Build
86+
run: ${{ matrix.settings.build }}
87+
if: ${{ !matrix.settings.docker }}
88+
shell: bash
89+
- name: Upload artifact
90+
uses: actions/upload-artifact@v4
91+
with:
92+
name: bindings-${{ matrix.settings.target }}
93+
path: ${{ env.APP_NAME }}.*.node
94+
if-no-files-found: error
95+
retention-days: 1
96+
97+
test-macOS-windows-binding:
98+
name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
99+
needs:
100+
- build
101+
strategy:
102+
fail-fast: false
103+
matrix:
104+
settings:
105+
- host: macos-latest
106+
target: x86_64-apple-darwin
107+
node:
108+
- '20'
109+
runs-on: ${{ matrix.settings.host }}
110+
steps:
111+
- uses: actions/checkout@v4
112+
- name: Setup node
113+
uses: actions/setup-node@v4
114+
with:
115+
node-version: ${{ matrix.node }}
116+
cache: 'npm'
117+
architecture: x64
118+
- name: Install dependencies
119+
run: npm install
120+
- name: Download artifacts
121+
uses: actions/download-artifact@v4
122+
with:
123+
name: bindings-${{ matrix.settings.target }}
124+
path: .
125+
- name: List packages
126+
run: ls -R .
127+
shell: bash
128+
- name: Test bindings
129+
run: npm test
130+
131+
test-linux-x64-gnu-binding:
132+
name: Test bindings on Linux-x64-gnu - node@${{ matrix.node }}
133+
needs:
134+
- build
135+
strategy:
136+
fail-fast: false
137+
matrix:
138+
node:
139+
- '18'
140+
- '20'
141+
runs-on: ubuntu-latest
142+
steps:
143+
- uses: actions/checkout@v4
144+
- name: Setup node
145+
uses: actions/setup-node@v4
146+
with:
147+
node-version: ${{ matrix.node }}
148+
cache: 'npm'
149+
- name: Install dependencies
150+
run: npm install
151+
- name: Download artifacts
152+
uses: actions/download-artifact@v4
153+
with:
154+
name: bindings-x86_64-unknown-linux-gnu
155+
path: .
156+
- name: List packages
157+
run: ls -R .
158+
shell: bash
159+
- name: Test bindings
160+
run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-slim npm test
161+
162+
publish:
163+
name: Publish to npm
164+
needs:
165+
- test-macOS-windows-binding
166+
- test-linux-x64-gnu-binding
167+
runs-on: ubuntu-latest
168+
steps:
169+
- name: Debug release info
170+
run: |
171+
echo "GitHub Ref: ${{ github.ref }}"
172+
echo "Event Name: ${{ github.event_name }}"
173+
echo "Release Tag: ${{ github.event.release.tag_name }}"
174+
175+
- uses: actions/checkout@v4
176+
with:
177+
fetch-depth: 0
178+
179+
- name: Setup node
180+
uses: actions/setup-node@v4
181+
with:
182+
node-version: 20
183+
registry-url: 'https://registry.npmjs.org'
184+
cache: 'npm'
185+
186+
- name: Install dependencies
187+
run: npm install
188+
189+
- name: Download all artifacts
190+
uses: actions/download-artifact@v4
191+
with:
192+
path: artifacts
193+
194+
- name: Move artifacts to appropriate directories
195+
run: |
196+
mkdir -p npm
197+
find artifacts -name "*.node" -type f -exec cp {} . \;
198+
ls -la *.node
199+
200+
- name: Extract version from release
201+
id: extract_version
202+
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
203+
204+
- name: Set version in package.json
205+
run: npm version ${{ github.event.release.tag_name }} --no-git-tag-version
206+
207+
- name: Publish to npm
208+
run: npm publish --access public
209+
env:
210+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
211+
212+
- name: Update release with binaries
213+
uses: softprops/action-gh-release@v1
214+
with:
215+
tag_name: ${{ github.event.release.tag_name }}
216+
files: |
217+
*.node

0 commit comments

Comments
 (0)