|
| 1 | +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json |
| 2 | + |
| 3 | +name: Publish npm packages |
| 4 | + |
| 5 | +on: |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + version: |
| 9 | + description: 'Version to publish (e.g., 0.17.0)' |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + dry-run: |
| 13 | + description: 'Dry run (skip actual publish)' |
| 14 | + required: false |
| 15 | + type: boolean |
| 16 | + default: false |
| 17 | + workflow_call: |
| 18 | + inputs: |
| 19 | + version: |
| 20 | + description: 'Version to publish' |
| 21 | + required: true |
| 22 | + type: string |
| 23 | + dry-run: |
| 24 | + description: 'Dry run (skip actual publish)' |
| 25 | + required: false |
| 26 | + type: boolean |
| 27 | + default: false |
| 28 | + secrets: |
| 29 | + NPM_TOKEN: |
| 30 | + required: true |
| 31 | + |
| 32 | +permissions: |
| 33 | + contents: read |
| 34 | + id-token: write |
| 35 | + |
| 36 | +env: |
| 37 | + WORKING_DIR: src/js-host-api |
| 38 | + |
| 39 | +jobs: |
| 40 | + build: |
| 41 | + strategy: |
| 42 | + fail-fast: true |
| 43 | + matrix: |
| 44 | + include: |
| 45 | + - target: x86_64-unknown-linux-gnu |
| 46 | + os: [self-hosted, Linux, X64, "1ES.Pool=hld-kvm-amd"] |
| 47 | + build_name: linux-x64-gnu |
| 48 | + - target: x86_64-pc-windows-msvc |
| 49 | + os: [self-hosted, Windows, X64, "1ES.Pool=hld-win2022-amd"] |
| 50 | + build_name: win32-x64-msvc |
| 51 | + runs-on: ${{ matrix.os }} |
| 52 | + steps: |
| 53 | + - uses: actions/checkout@v6 |
| 54 | + with: |
| 55 | + fetch-depth: 0 |
| 56 | + |
| 57 | + - name: Hyperlight setup |
| 58 | + uses: hyperlight-dev/ci-setup-workflow@v1.8.0 |
| 59 | + with: |
| 60 | + rust-toolchain: "1.89" |
| 61 | + |
| 62 | + - name: Setup Node.js |
| 63 | + uses: actions/setup-node@v6 |
| 64 | + with: |
| 65 | + node-version: '22' |
| 66 | + cache: 'npm' |
| 67 | + cache-dependency-path: 'src/js-host-api/package-lock.json' |
| 68 | + |
| 69 | + - name: Install dependencies |
| 70 | + working-directory: ${{ env.WORKING_DIR }} |
| 71 | + run: npm ci --ignore-scripts --omit=optional |
| 72 | + |
| 73 | + - name: Set package version |
| 74 | + working-directory: ${{ env.WORKING_DIR }} |
| 75 | + shell: bash |
| 76 | + run: | |
| 77 | + npm version ${{ inputs.version }} --no-git-tag-version --allow-same-version |
| 78 | +
|
| 79 | + - name: Build native module |
| 80 | + working-directory: ${{ env.WORKING_DIR }} |
| 81 | + run: npm run build |
| 82 | + |
| 83 | + - name: Upload artifact |
| 84 | + uses: actions/upload-artifact@v8 |
| 85 | + with: |
| 86 | + name: bindings-${{ matrix.build_name }} |
| 87 | + path: ${{ env.WORKING_DIR }}/*.node |
| 88 | + if-no-files-found: error |
| 89 | + |
| 90 | + publish: |
| 91 | + needs: build |
| 92 | + runs-on: [self-hosted, Linux, X64, "1ES.Pool=hld-kvm-amd"] |
| 93 | + steps: |
| 94 | + - uses: actions/checkout@v6 |
| 95 | + |
| 96 | + - name: Setup Node.js |
| 97 | + uses: actions/setup-node@v6 |
| 98 | + with: |
| 99 | + node-version: '22' |
| 100 | + registry-url: 'https://registry.npmjs.org' |
| 101 | + cache: 'npm' |
| 102 | + cache-dependency-path: 'src/js-host-api/package-lock.json' |
| 103 | + |
| 104 | + - name: Install dependencies |
| 105 | + working-directory: ${{ env.WORKING_DIR }} |
| 106 | + run: npm ci --ignore-scripts --omit=optional |
| 107 | + |
| 108 | + - name: Download Linux artifact |
| 109 | + uses: actions/download-artifact@v8 |
| 110 | + with: |
| 111 | + name: bindings-linux-x64-gnu |
| 112 | + path: ${{ env.WORKING_DIR }}/artifacts/linux-x64-gnu |
| 113 | + |
| 114 | + - name: Download Windows artifact |
| 115 | + uses: actions/download-artifact@v8 |
| 116 | + with: |
| 117 | + name: bindings-win32-x64-msvc |
| 118 | + path: ${{ env.WORKING_DIR }}/artifacts/win32-x64-msvc |
| 119 | + |
| 120 | + - name: List artifacts |
| 121 | + run: ls -la ${{ env.WORKING_DIR }}/artifacts/*/ |
| 122 | + |
| 123 | + - name: Move artifacts to npm directories |
| 124 | + working-directory: ${{ env.WORKING_DIR }} |
| 125 | + run: | |
| 126 | + # Rename artifacts to match napi-rs naming convention |
| 127 | + mv artifacts/linux-x64-gnu/*.node npm/linux-x64-gnu/js-host-api.linux-x64-gnu.node |
| 128 | + mv artifacts/win32-x64-msvc/*.node npm/win32-x64-msvc/js-host-api.win32-x64-msvc.node |
| 129 | + ls -la npm/linux-x64-gnu/ |
| 130 | + ls -la npm/win32-x64-msvc/ |
| 131 | +
|
| 132 | + - name: Set package versions |
| 133 | + working-directory: ${{ env.WORKING_DIR }} |
| 134 | + run: | |
| 135 | + # Update main package version |
| 136 | + npm version ${{ inputs.version }} --no-git-tag-version --allow-same-version |
| 137 | + |
| 138 | + # Update platform package versions |
| 139 | + cd npm/linux-x64-gnu && npm version ${{ inputs.version }} --no-git-tag-version --allow-same-version |
| 140 | + cd ../win32-x64-msvc && npm version ${{ inputs.version }} --no-git-tag-version --allow-same-version |
| 141 | +
|
| 142 | + - name: Update optionalDependencies versions |
| 143 | + working-directory: ${{ env.WORKING_DIR }} |
| 144 | + run: | |
| 145 | + # Update only @hyperlight platform package versions (not other optionalDeps) |
| 146 | + node -e " |
| 147 | + const fs = require('fs'); |
| 148 | + const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); |
| 149 | + for (const dep of Object.keys(pkg.optionalDependencies || {})) { |
| 150 | + if (dep.startsWith('@hyperlight/js-host-api-')) { |
| 151 | + pkg.optionalDependencies[dep] = '${{ inputs.version }}'; |
| 152 | + } |
| 153 | + } |
| 154 | + fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n'); |
| 155 | + " |
| 156 | + cat package.json |
| 157 | +
|
| 158 | + - name: Generate JS bindings (index.js and index.d.ts) |
| 159 | + working-directory: ${{ env.WORKING_DIR }} |
| 160 | + run: | |
| 161 | + # napi prepublish generates index.js and index.d.ts from the .node artifacts |
| 162 | + npx napi prepublish -t npm --skip-gh-release |
| 163 | + ls -la index.js index.d.ts |
| 164 | +
|
| 165 | + - name: Publish Linux package |
| 166 | + if: ${{ !inputs.dry-run }} |
| 167 | + working-directory: ${{ env.WORKING_DIR }}/npm/linux-x64-gnu |
| 168 | + run: npm publish --access public |
| 169 | + env: |
| 170 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 171 | + |
| 172 | + - name: Publish Windows package |
| 173 | + if: ${{ !inputs.dry-run }} |
| 174 | + working-directory: ${{ env.WORKING_DIR }}/npm/win32-x64-msvc |
| 175 | + run: npm publish --access public |
| 176 | + env: |
| 177 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 178 | + |
| 179 | + - name: Publish main package |
| 180 | + if: ${{ !inputs.dry-run }} |
| 181 | + working-directory: ${{ env.WORKING_DIR }} |
| 182 | + run: npm publish --access public |
| 183 | + env: |
| 184 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 185 | + |
| 186 | + - name: Dry run - show what would be published |
| 187 | + if: ${{ inputs.dry-run }} |
| 188 | + working-directory: ${{ env.WORKING_DIR }} |
| 189 | + run: | |
| 190 | + echo "=== DRY RUN - Would publish the following packages ===" |
| 191 | + echo "" |
| 192 | + echo "--- @hyperlight/js-host-api-linux-x64-gnu ---" |
| 193 | + npm pack ./npm/linux-x64-gnu --dry-run |
| 194 | + echo "" |
| 195 | + echo "--- @hyperlight/js-host-api-win32-x64-msvc ---" |
| 196 | + npm pack ./npm/win32-x64-msvc --dry-run |
| 197 | + echo "" |
| 198 | + echo "--- @hyperlight/js-host-api ---" |
| 199 | + npm pack --dry-run |
0 commit comments