feat(npm): use platform-specific packages instead of postinstall down… #7
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: Release | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| permissions: | |
| contents: write | |
| env: | |
| CARGO_TERM_COLOR: always | |
| jobs: | |
| build: | |
| name: Build ${{ matrix.name }} | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - target: x86_64-apple-darwin | |
| os: macos-latest | |
| name: darwin-x86_64 | |
| - target: aarch64-apple-darwin | |
| os: macos-latest | |
| name: darwin-aarch64 | |
| - target: x86_64-unknown-linux-gnu | |
| os: ubuntu-latest | |
| name: linux-x86_64 | |
| - target: aarch64-unknown-linux-gnu | |
| os: ubuntu-latest | |
| name: linux-aarch64 | |
| - target: x86_64-pc-windows-msvc | |
| os: windows-latest | |
| name: windows-x86_64 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Install cross-compilation tools (Linux ARM64) | |
| if: matrix.target == 'aarch64-unknown-linux-gnu' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y gcc-aarch64-linux-gnu | |
| echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV | |
| - name: Cache cargo | |
| uses: Swatinem/rust-cache@v2 | |
| with: | |
| key: ${{ matrix.target }} | |
| - name: Build | |
| run: cargo build --release --target ${{ matrix.target }} | |
| - name: Package (Unix) | |
| if: runner.os != 'Windows' | |
| run: | | |
| cd target/${{ matrix.target }}/release | |
| tar czf ../../../agentmap-${{ matrix.name }}.tar.gz agentmap | |
| cd ../../.. | |
| shasum -a 256 agentmap-${{ matrix.name }}.tar.gz > agentmap-${{ matrix.name }}.tar.gz.sha256 | |
| - name: Package (Windows) | |
| if: runner.os == 'Windows' | |
| run: | | |
| cd target/${{ matrix.target }}/release | |
| 7z a ../../../agentmap-${{ matrix.name }}.zip agentmap.exe | |
| cd ../../.. | |
| Get-FileHash agentmap-${{ matrix.name }}.zip -Algorithm SHA256 | Format-List > agentmap-${{ matrix.name }}.zip.sha256 | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: agentmap-${{ matrix.name }} | |
| path: | | |
| agentmap-*.tar.gz | |
| agentmap-*.zip | |
| agentmap-*.sha256 | |
| release: | |
| name: Create Release | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| merge-multiple: true | |
| - name: List artifacts | |
| run: ls -la artifacts/ | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: artifacts/* | |
| generate_release_notes: true | |
| draft: false | |
| prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc') }} | |
| publish-crates: | |
| name: Publish to crates.io | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Publish to crates.io | |
| env: | |
| CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
| run: cargo publish --no-verify --allow-dirty | |
| trigger-homebrew-tap: | |
| name: Trigger Homebrew Tap Update | |
| needs: release | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Trigger homebrew-tap update | |
| run: | | |
| curl -X POST \ | |
| -H "Authorization: token ${{ secrets.TAP_TOKEN }}" \ | |
| -H "Accept: application/vnd.github.v3+json" \ | |
| https://api.github.com/repos/nguyenphutrong/homebrew-tap/dispatches \ | |
| -d '{"event_type":"agentmap-release","client_payload":{"version":"${{ github.ref_name }}"}}' | |
| publish-npm: | |
| name: Publish to npm | |
| needs: release | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| include: | |
| - artifact: darwin-aarch64 | |
| npm-package: darwin-arm64 | |
| - artifact: darwin-x86_64 | |
| npm-package: darwin-x64 | |
| - artifact: linux-x86_64 | |
| npm-package: linux-x64 | |
| - artifact: linux-aarch64 | |
| npm-package: linux-arm64 | |
| - artifact: windows-x86_64 | |
| npm-package: win32-x64 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: agentmap-${{ matrix.artifact }} | |
| path: artifacts | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| registry-url: "https://registry.npmjs.org" | |
| - name: Prepare platform package | |
| run: | | |
| VERSION=${GITHUB_REF_NAME#v} | |
| PKG_DIR=npm/${{ matrix.npm-package }} | |
| cd $PKG_DIR | |
| npm version $VERSION --no-git-tag-version --allow-same-version | |
| if [[ "${{ matrix.npm-package }}" == "win32-x64" ]]; then | |
| cd ../../artifacts | |
| unzip agentmap-${{ matrix.artifact }}.zip -d ../npm/${{ matrix.npm-package }}/bin/ | |
| else | |
| tar -xzf ../../artifacts/agentmap-${{ matrix.artifact }}.tar.gz -C bin/ | |
| chmod +x bin/agentmap | |
| fi | |
| - name: Publish platform package | |
| run: | | |
| cd npm/${{ matrix.npm-package }} | |
| npm publish --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| publish-npm-cli: | |
| name: Publish agentmap-cli to npm | |
| needs: publish-npm | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| registry-url: "https://registry.npmjs.org" | |
| - name: Update package version | |
| run: | | |
| VERSION=${GITHUB_REF_NAME#v} | |
| cd npm/cli | |
| npm version $VERSION --no-git-tag-version --allow-same-version | |
| node -e " | |
| const pkg = require('./package.json'); | |
| const version = '$VERSION'; | |
| pkg.optionalDependencies = { | |
| '@agentmap/darwin-arm64': version, | |
| '@agentmap/darwin-x64': version, | |
| '@agentmap/linux-arm64': version, | |
| '@agentmap/linux-x64': version, | |
| '@agentmap/win32-x64': version | |
| }; | |
| require('fs').writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n'); | |
| " | |
| - name: Publish to npm | |
| run: | | |
| cd npm/cli | |
| npm publish --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |