Skip to content

Commit c2692ab

Browse files
authored
Merge pull request #11 from cawalch/ps/rr/build__npm_build_and_publish_gh_actions_try_5
build: npm build and publish GH actions try 5
2 parents 5f1be1c + 9128772 commit c2692ab

File tree

3 files changed

+104
-237
lines changed

3 files changed

+104
-237
lines changed

.github/workflows/CI.yml

Lines changed: 103 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
name: CI
1+
name: CI/CD
22
env:
33
DEBUG: napi:*
44
APP_NAME: node-yara-x
5+
PACKAGE_NAME: yara-x
56
MACOSX_DEPLOYMENT_TARGET: '10.13'
67
permissions:
78
contents: write
@@ -22,6 +23,8 @@ permissions:
2223
- '.github/PULL_REQUEST_TEMPLATE.md'
2324
- 'examples/**'
2425
pull_request: null
26+
release:
27+
types: [published]
2528
jobs:
2629
build:
2730
if: github.event_name != 'push' || !contains(github.event.head_commit.message, 'Merge pull request')
@@ -103,12 +106,13 @@ jobs:
103106
path: ${{ env.APP_NAME }}.*.node
104107
if-no-files-found: error
105108
retention-days: 1
106-
test-macOS-windows-binding:
109+
110+
test-macOS-binding:
107111
if: |
108112
!contains(github.event.head_commit.message, 'ci skip') &&
109113
!contains(github.event.head_commit.message, 'skip ci') &&
110114
(github.event_name != 'push' || !contains(github.event.head_commit.message, 'Merge pull request'))
111-
name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
115+
name: Test bindings on macOS - node@${{ matrix.node }}
112116
needs:
113117
- build
114118
strategy:
@@ -140,6 +144,7 @@ jobs:
140144
shell: bash
141145
- name: Test bindings
142146
run: npm test
147+
143148
test-linux-x64-gnu-binding:
144149
name: Test bindings on Linux-x64-gnu - node@${{ matrix.node }}
145150
needs:
@@ -148,7 +153,6 @@ jobs:
148153
fail-fast: false
149154
matrix:
150155
node:
151-
- '18'
152156
- '20'
153157
runs-on: ubuntu-latest
154158
steps:
@@ -171,3 +175,98 @@ jobs:
171175
- name: Test bindings
172176
run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-slim npm test
173177

178+
publish:
179+
name: Publish to npm
180+
# Only run on tag pushes or release publish events
181+
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'release'
182+
needs:
183+
- test-macOS-binding
184+
- test-linux-x64-gnu-binding
185+
runs-on: ubuntu-latest
186+
steps:
187+
- name: Debug release info
188+
run: |
189+
echo "GitHub Ref: ${{ github.ref }}"
190+
echo "Event Name: ${{ github.event_name }}"
191+
echo "Release Tag: ${{ github.event.release.tag_name }}"
192+
193+
- uses: actions/checkout@v4
194+
with:
195+
fetch-depth: 0
196+
197+
- name: Setup node
198+
uses: actions/setup-node@v4
199+
with:
200+
node-version: 20
201+
registry-url: 'https://registry.npmjs.org'
202+
cache: 'npm'
203+
204+
- name: Install dependencies
205+
run: npm install
206+
207+
- name: Download all artifacts
208+
uses: actions/download-artifact@v4
209+
with:
210+
path: artifacts
211+
212+
- name: Move artifacts
213+
run: |
214+
# Create npm directory structure if it doesn't exist
215+
mkdir -p npm
216+
217+
# Move artifacts to the correct location for napi-rs
218+
find artifacts -name "*.node" -type f -exec cp {} . \;
219+
220+
# Run the artifacts script to organize files correctly
221+
npm run artifacts
222+
223+
- name: List packages
224+
run: |
225+
echo "Files in npm directories:"
226+
ls -la npm/ || echo "No npm directory"
227+
228+
echo "Files in root:"
229+
ls -la *.node || echo "No .node files in root"
230+
231+
- name: Verify package version matches release
232+
id: verify_version
233+
run: |
234+
# Determine version from tag or release
235+
if [ "${{ github.event_name }}" == "release" ]; then
236+
TAG_NAME="${{ github.event.release.tag_name }}"
237+
else
238+
TAG_NAME="${{ github.ref_name }}"
239+
fi
240+
241+
# Remove 'v' prefix if present
242+
RELEASE_VERSION="${TAG_NAME#v}"
243+
244+
# Get current version from package.json
245+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
246+
247+
echo "Release version: $RELEASE_VERSION"
248+
echo "Package version: $PACKAGE_VERSION"
249+
250+
# Skip version update if already correct
251+
if [ "$RELEASE_VERSION" = "$PACKAGE_VERSION" ]; then
252+
echo "Version already matches, no update needed"
253+
else
254+
echo "Updating version from $PACKAGE_VERSION to $RELEASE_VERSION"
255+
npm version $RELEASE_VERSION --no-git-tag-version
256+
fi
257+
258+
- name: Publish to npm
259+
run: npm publish --access public
260+
env:
261+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
262+
263+
- name: Update release with binaries
264+
uses: softprops/action-gh-release@v1
265+
with:
266+
files: |
267+
*.node
268+
# If triggered by a tag push, create a release
269+
tag_name: ${{ github.ref_name }}
270+
# Only generate release if one doesn't exist
271+
generate_release_notes: ${{ github.event_name != 'release' }}
272+

.github/workflows/publish.yml

Lines changed: 0 additions & 232 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "node-yara-x",
2+
"name": "yara-x",
33
"version": "0.1.0",
44
"main": "index.js",
55
"types": "index.d.ts",

0 commit comments

Comments
 (0)