-
Notifications
You must be signed in to change notification settings - Fork 5
feat(js-host-api): add npm publishing workflow #36
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
Open
simongdavies
wants to merge
2
commits into
main
Choose a base branch
from
feat/npm-publish
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,229 @@ | ||
| # yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json | ||
|
|
||
| name: Publish npm packages | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| version: | ||
| description: 'Version to publish (e.g., 0.17.0)' | ||
| required: true | ||
| type: string | ||
| dry-run: | ||
| description: 'Dry run (skip actual publish)' | ||
| required: false | ||
| type: boolean | ||
| default: false | ||
| workflow_call: | ||
| inputs: | ||
| version: | ||
| description: 'Version to publish' | ||
| required: true | ||
| type: string | ||
| dry-run: | ||
| description: 'Dry run (skip actual publish)' | ||
| required: false | ||
| type: boolean | ||
| default: false | ||
| secrets: | ||
| NPM_TOKEN: | ||
| required: true | ||
|
|
||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
|
|
||
| env: | ||
| WORKING_DIR: src/js-host-api | ||
|
|
||
| jobs: | ||
| build: | ||
| strategy: | ||
| fail-fast: true | ||
| matrix: | ||
| include: | ||
| - target: x86_64-unknown-linux-gnu | ||
| os: [self-hosted, Linux, X64, "1ES.Pool=hld-kvm-amd"] | ||
| build_name: linux-x64-gnu | ||
| - target: x86_64-unknown-linux-musl | ||
| os: [self-hosted, Linux, X64, "1ES.Pool=hld-kvm-amd"] | ||
| build_name: linux-x64-musl | ||
| - target: x86_64-pc-windows-msvc | ||
| os: [self-hosted, Windows, X64, "1ES.Pool=hld-win2022-amd"] | ||
| build_name: win32-x64-msvc | ||
| runs-on: ${{ matrix.os }} | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Hyperlight setup | ||
| uses: hyperlight-dev/ci-setup-workflow@v1.8.0 | ||
| with: | ||
| rust-toolchain: "1.89" | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
| node-version: '22' | ||
| cache: 'npm' | ||
| cache-dependency-path: 'src/js-host-api/package-lock.json' | ||
|
|
||
| - name: Install dependencies | ||
| working-directory: ${{ env.WORKING_DIR }} | ||
| run: npm ci --ignore-scripts --omit=optional | ||
|
|
||
| - name: Set package version | ||
| working-directory: ${{ env.WORKING_DIR }} | ||
| shell: bash | ||
| run: | | ||
| npm version ${{ inputs.version }} --no-git-tag-version --allow-same-version | ||
|
|
||
| - name: Install musl tools | ||
| if: contains(matrix.target, 'musl') | ||
| run: sudo apt-get update && sudo apt-get install -y musl-tools | ||
|
|
||
| - name: Add musl Rust target | ||
| if: contains(matrix.target, 'musl') | ||
| run: rustup target add x86_64-unknown-linux-musl | ||
|
|
||
| - name: Build native module | ||
| working-directory: ${{ env.WORKING_DIR }} | ||
| run: npm run build -- --target ${{ matrix.target }} | ||
|
|
||
| - name: Upload artifact | ||
| uses: actions/upload-artifact@v8 | ||
| with: | ||
| name: bindings-${{ matrix.build_name }} | ||
| path: ${{ env.WORKING_DIR }}/*.node | ||
| if-no-files-found: error | ||
|
|
||
| publish: | ||
| needs: build | ||
| runs-on: [self-hosted, Linux, X64, "1ES.Pool=hld-kvm-amd"] | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
| node-version: '22' | ||
| registry-url: 'https://registry.npmjs.org' | ||
| cache: 'npm' | ||
| cache-dependency-path: 'src/js-host-api/package-lock.json' | ||
|
|
||
| - name: Install dependencies | ||
| working-directory: ${{ env.WORKING_DIR }} | ||
| run: npm ci --ignore-scripts --omit=optional | ||
|
|
||
| - name: Download Linux GNU artifact | ||
| uses: actions/download-artifact@v8 | ||
| with: | ||
| name: bindings-linux-x64-gnu | ||
| path: ${{ env.WORKING_DIR }}/artifacts/linux-x64-gnu | ||
|
|
||
| - name: Download Linux musl artifact | ||
| uses: actions/download-artifact@v8 | ||
| with: | ||
| name: bindings-linux-x64-musl | ||
| path: ${{ env.WORKING_DIR }}/artifacts/linux-x64-musl | ||
|
|
||
| - name: Download Windows artifact | ||
| uses: actions/download-artifact@v8 | ||
| with: | ||
| name: bindings-win32-x64-msvc | ||
| path: ${{ env.WORKING_DIR }}/artifacts/win32-x64-msvc | ||
|
|
||
| - name: List artifacts | ||
| run: ls -la ${{ env.WORKING_DIR }}/artifacts/*/ | ||
|
|
||
| - name: Move artifacts to npm directories | ||
| working-directory: ${{ env.WORKING_DIR }} | ||
| run: | | ||
| # Rename artifacts to match napi-rs naming convention | ||
| mv artifacts/linux-x64-gnu/*.node npm/linux-x64-gnu/js-host-api.linux-x64-gnu.node | ||
| mv artifacts/linux-x64-musl/*.node npm/linux-x64-musl/js-host-api.linux-x64-musl.node | ||
| mv artifacts/win32-x64-msvc/*.node npm/win32-x64-msvc/js-host-api.win32-x64-msvc.node | ||
| ls -la npm/linux-x64-gnu/ | ||
| ls -la npm/linux-x64-musl/ | ||
| ls -la npm/win32-x64-msvc/ | ||
|
|
||
| - name: Set package versions | ||
| working-directory: ${{ env.WORKING_DIR }} | ||
| run: | | ||
| # Update main package version | ||
| npm version ${{ inputs.version }} --no-git-tag-version --allow-same-version | ||
|
|
||
| # Update platform package versions | ||
| cd npm/linux-x64-gnu && npm version ${{ inputs.version }} --no-git-tag-version --allow-same-version | ||
| cd ../linux-x64-musl && npm version ${{ inputs.version }} --no-git-tag-version --allow-same-version | ||
| cd ../win32-x64-msvc && npm version ${{ inputs.version }} --no-git-tag-version --allow-same-version | ||
|
|
||
| - name: Update optionalDependencies versions | ||
| working-directory: ${{ env.WORKING_DIR }} | ||
| run: | | ||
| # Update only @hyperlight platform package versions (not other optionalDeps) | ||
| node -e " | ||
| const fs = require('fs'); | ||
| const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); | ||
| for (const dep of Object.keys(pkg.optionalDependencies || {})) { | ||
| if (dep.startsWith('@hyperlight/js-host-api-')) { | ||
| pkg.optionalDependencies[dep] = '${{ inputs.version }}'; | ||
| } | ||
| } | ||
| fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n'); | ||
| " | ||
| cat package.json | ||
|
|
||
| - name: Generate JS bindings (index.js and index.d.ts) | ||
| working-directory: ${{ env.WORKING_DIR }} | ||
| run: | | ||
| # napi prepublish generates index.js and index.d.ts from the .node artifacts | ||
| npx napi prepublish -t npm --skip-gh-release | ||
| ls -la index.js index.d.ts | ||
|
|
||
| - name: Publish Linux GNU package | ||
| if: ${{ !inputs.dry-run }} | ||
| working-directory: ${{ env.WORKING_DIR }}/npm/linux-x64-gnu | ||
| run: npm publish --access public | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
|
|
||
| - name: Publish Linux musl package | ||
| if: ${{ !inputs.dry-run }} | ||
| working-directory: ${{ env.WORKING_DIR }}/npm/linux-x64-musl | ||
| run: npm publish --access public | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
|
|
||
| - name: Publish Windows package | ||
| if: ${{ !inputs.dry-run }} | ||
| working-directory: ${{ env.WORKING_DIR }}/npm/win32-x64-msvc | ||
| run: npm publish --access public | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
|
|
||
| - name: Publish main package | ||
| if: ${{ !inputs.dry-run }} | ||
| working-directory: ${{ env.WORKING_DIR }} | ||
| run: npm publish --access public | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
|
|
||
| - name: Dry run - show what would be published | ||
| if: ${{ inputs.dry-run }} | ||
| working-directory: ${{ env.WORKING_DIR }} | ||
| run: | | ||
| echo "=== DRY RUN - Would publish the following packages ===" | ||
| echo "" | ||
| echo "--- @hyperlight/js-host-api-linux-x64-gnu ---" | ||
| npm pack ./npm/linux-x64-gnu --dry-run | ||
| echo "" | ||
| echo "--- @hyperlight/js-host-api-linux-x64-musl ---" | ||
| npm pack ./npm/linux-x64-musl --dry-run | ||
| echo "" | ||
| echo "--- @hyperlight/js-host-api-win32-x64-msvc ---" | ||
| npm pack ./npm/win32-x64-msvc --dry-run | ||
| echo "" | ||
| echo "--- @hyperlight/js-host-api ---" | ||
| npm pack --dry-run | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # npm publish ignores - override .gitignore for package publishing | ||
| # Include generated files that are gitignored but needed in the package | ||
| !index.js | ||
| !index.d.ts | ||
|
|
||
| # Exclude development files | ||
| node_modules/ | ||
| target/ | ||
| Cargo.lock | ||
| *.tgz | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
| .DS_Store | ||
|
|
||
| # Exclude package-lock from published package | ||
| package-lock.json | ||
|
|
||
| # Exclude test and dev files | ||
| tests/ | ||
| examples/ | ||
| *.config.js | ||
| *.config.mjs | ||
| .prettierrc | ||
| TYPE_NAMING.md | ||
| build.rs | ||
| src/ | ||
| Cargo.toml | ||
| test-examples.sh | ||
|
|
||
| # Exclude artifacts directory (only used during CI) | ||
| artifacts/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| { | ||
| "name": "@hyperlight/js-host-api-linux-x64-gnu", | ||
| "version": "0.17.0", | ||
| "os": [ | ||
| "linux" | ||
| ], | ||
| "cpu": [ | ||
| "x64" | ||
| ], | ||
| "main": "js-host-api.linux-x64-gnu.node", | ||
| "files": [ | ||
| "js-host-api.linux-x64-gnu.node" | ||
| ], | ||
| "description": "Node.js API bindings for Hyperlight JS - Linux x64 gnu", | ||
| "license": "Apache-2.0", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/hyperlight-dev/hyperlight-js.git" | ||
| }, | ||
| "homepage": "https://github.com/hyperlight-dev/hyperlight-js#readme", | ||
| "bugs": { | ||
| "url": "https://github.com/hyperlight-dev/hyperlight-js/issues" | ||
| }, | ||
| "engines": { | ||
| "node": ">= 18" | ||
| }, | ||
| "libc": [ | ||
| "glibc" | ||
| ] | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.