client #12
Workflow file for this 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
| name: Publish Node Package | |
| on: | |
| push: | |
| tags: | |
| - "node/v*" | |
| permissions: | |
| contents: read | |
| id-token: write | |
| jobs: | |
| extract-version: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.extract.outputs.version }} | |
| steps: | |
| - name: Extract version from tag | |
| id: extract | |
| run: | | |
| TAG="${GITHUB_REF#refs/tags/node/v}" | |
| echo "version=$TAG" >> $GITHUB_OUTPUT | |
| publish-platform-packages: | |
| needs: extract-version | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - platform: darwin-arm64 | |
| npm_pkg: cli-darwin-arm64 | |
| - platform: darwin-x64 | |
| npm_pkg: cli-darwin-x64 | |
| - platform: linux-x64 | |
| npm_pkg: cli-linux-x64 | |
| - platform: linux-arm64 | |
| npm_pkg: cli-linux-arm64 | |
| - platform: windows-x64 | |
| npm_pkg: cli-win32-x64 | |
| runs-on: ubuntu-latest | |
| env: | |
| VERSION: ${{ needs.extract-version.outputs.version }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| registry-url: "https://registry.npmjs.org" | |
| - name: Download CLI binary from latest Rust release | |
| run: | | |
| ASSET="haiai-cli-${VERSION}-${{ matrix.platform }}" | |
| if [ "${{ matrix.platform }}" = "windows-x64" ]; then | |
| EXT="zip" | |
| else | |
| EXT="tar.gz" | |
| fi | |
| URL="https://github.com/HumanAssisted/haiai/releases/download/rust/v${VERSION}/${ASSET}.${EXT}" | |
| for i in 1 2 3 4 5 6; do | |
| if curl -fLO "$URL"; then | |
| echo "Downloaded ${ASSET}.${EXT}" | |
| exit 0 | |
| fi | |
| echo "Attempt $i failed, Rust release may still be building. Waiting 60s..." | |
| sleep 60 | |
| done | |
| echo "::error::Failed to download $URL after 6 attempts" | |
| exit 1 | |
| - name: Extract binary into platform package | |
| run: | | |
| PKG_DIR="node/npm/@haiai/${{ matrix.npm_pkg }}" | |
| mkdir -p "${PKG_DIR}/bin" | |
| if [ "${{ matrix.platform }}" = "windows-x64" ]; then | |
| unzip -o "haiai-cli-${VERSION}-${{ matrix.platform }}.zip" -d /tmp/bin | |
| cp /tmp/bin/haiai-cli.exe "${PKG_DIR}/bin/haiai.exe" 2>/dev/null || cp /tmp/bin/haiai.exe "${PKG_DIR}/bin/haiai.exe" | |
| else | |
| tar xzf "haiai-cli-${VERSION}-${{ matrix.platform }}.tar.gz" -C /tmp/bin 2>/dev/null || mkdir -p /tmp/bin && tar xzf "haiai-cli-${VERSION}-${{ matrix.platform }}.tar.gz" -C /tmp/bin | |
| cp /tmp/bin/haiai-cli "${PKG_DIR}/bin/haiai" 2>/dev/null || cp /tmp/bin/haiai "${PKG_DIR}/bin/haiai" | |
| fi | |
| chmod +x "${PKG_DIR}/bin/"* | |
| - name: Update platform package version | |
| run: | | |
| PKG_JSON="node/npm/@haiai/${{ matrix.npm_pkg }}/package.json" | |
| node -e " | |
| const fs = require('fs'); | |
| const pkg = JSON.parse(fs.readFileSync('${PKG_JSON}', 'utf-8')); | |
| pkg.version = '${VERSION}'; | |
| fs.writeFileSync('${PKG_JSON}', JSON.stringify(pkg, null, 2) + '\n'); | |
| " | |
| - name: Publish platform package | |
| working-directory: node/npm/@haiai/${{ matrix.npm_pkg }} | |
| run: npm publish --provenance --access public || echo "Already published (safe to ignore)" | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| publish: | |
| needs: [extract-version, publish-platform-packages] | |
| runs-on: ubuntu-latest | |
| env: | |
| VERSION: ${{ needs.extract-version.outputs.version }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| registry-url: "https://registry.npmjs.org" | |
| - name: Sync version from git tag | |
| run: | | |
| cd node | |
| node -e " | |
| const fs = require('fs'); | |
| const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8')); | |
| pkg.version = '${VERSION}'; | |
| for (const dep of Object.keys(pkg.optionalDependencies || {})) { | |
| pkg.optionalDependencies[dep] = '${VERSION}'; | |
| } | |
| fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n'); | |
| " | |
| - name: Install dependencies | |
| run: | | |
| cd node | |
| npm install --package-lock-only | |
| npm ci | |
| - name: Build | |
| run: | | |
| cd node | |
| npm run build | |
| - name: Smoke package | |
| run: | | |
| cd node | |
| node ./scripts/smoke-package.cjs | |
| - name: Publish to npm | |
| run: | | |
| cd node | |
| npm publish --provenance --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |