fix: allow same version in npm release step #8
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*" | |
| jobs: | |
| # ───────────────────────────────────────────── | |
| # 1. Build Go binaries (all targets, one runner) | |
| # ───────────────────────────────────────────── | |
| binaries: | |
| name: Build binaries | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| include: | |
| - goos: darwin | |
| goarch: arm64 | |
| target: pcr-macos-arm64 | |
| - goos: darwin | |
| goarch: amd64 | |
| target: pcr-macos-x64 | |
| - goos: linux | |
| goarch: amd64 | |
| target: pcr-linux-x64 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-go@v5 | |
| with: | |
| go-version: "1.22" | |
| cache: true | |
| - name: Build | |
| run: | | |
| CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} \ | |
| go build \ | |
| -ldflags="-s -w -X main.Version=${GITHUB_REF_NAME#v}" \ | |
| -o ${{ matrix.target }} \ | |
| . | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.target }} | |
| path: ${{ matrix.target }} | |
| # ───────────────────────────────────────────── | |
| # 2. Create GitHub Release with binaries | |
| # ───────────────────────────────────────────── | |
| release: | |
| name: Create GitHub Release | |
| needs: binaries | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts/ | |
| - name: Compute checksums | |
| run: | | |
| cd artifacts | |
| for dir in */; do | |
| binary="${dir%/}" | |
| sha256sum "$dir/$binary" | awk '{print $1}' > "$dir/$binary.sha256" | |
| done | |
| - name: Create release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: | | |
| artifacts/pcr-macos-arm64/pcr-macos-arm64 | |
| artifacts/pcr-macos-arm64/pcr-macos-arm64.sha256 | |
| artifacts/pcr-macos-x64/pcr-macos-x64 | |
| artifacts/pcr-macos-x64/pcr-macos-x64.sha256 | |
| artifacts/pcr-linux-x64/pcr-linux-x64 | |
| artifacts/pcr-linux-x64/pcr-linux-x64.sha256 | |
| generate_release_notes: true | |
| # ───────────────────────────────────────────── | |
| # 3. Publish npm wrapper (after release — needs binaries uploaded) | |
| # ───────────────────────────────────────────── | |
| npm: | |
| name: Publish to npm | |
| needs: release | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| id-token: write | |
| defaults: | |
| run: | |
| working-directory: npm | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| registry-url: "https://registry.npmjs.org" | |
| - name: Set version from tag | |
| run: | | |
| VERSION="${GITHUB_REF_NAME#v}" | |
| npm version "$VERSION" --no-git-tag-version --allow-same-version | |
| - name: Publish | |
| run: npm publish --provenance --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| # ───────────────────────────────────────────── | |
| # 4. Update Homebrew tap | |
| # ───────────────────────────────────────────── | |
| homebrew: | |
| name: Update Homebrew tap | |
| needs: release | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Trigger Homebrew tap update | |
| uses: peter-evans/repository-dispatch@v3 | |
| with: | |
| token: ${{ secrets.HOMEBREW_TAP_TOKEN }} | |
| repository: pcr-developers/homebrew-pcr | |
| event-type: new-release | |
| client-payload: | | |
| { | |
| "version": "${{ github.ref_name }}", | |
| "tag": "${{ github.ref_name }}" | |
| } |