ci: release macOS in a separate workflow #1
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 CLI (macOS) | |
| # macOS lives in its own workflow so its slower runners never block the | |
| # linux/windows release. Triggered by the same v* tags (and manual dispatch); | |
| # runs in parallel with "Release CLI". | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| workflow_dispatch: | |
| inputs: | |
| release_version: | |
| description: Release version without the leading v | |
| required: true | |
| type: string | |
| jobs: | |
| build-macos: | |
| name: Build ${{ matrix.target.rust_target }} | |
| runs-on: ${{ matrix.target.runner }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| target: | |
| - runner: macos-14 | |
| rust_target: aarch64-apple-darwin | |
| - runner: macos-13 | |
| rust_target: x86_64-apple-darwin | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target.rust_target }} | |
| - name: Build release binary | |
| run: cargo build --release --target ${{ matrix.target.rust_target }} | |
| - name: Stage artifact | |
| shell: bash | |
| run: | | |
| mkdir -p artifacts/${{ matrix.target.rust_target }} | |
| cp target/${{ matrix.target.rust_target }}/release/jucode artifacts/${{ matrix.target.rust_target }}/jucode | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.target.rust_target }} | |
| path: artifacts/${{ matrix.target.rust_target }}/jucode | |
| release-macos: | |
| name: Publish macOS release assets | |
| needs: build-macos | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| registry-url: https://registry.npmjs.org/ | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| merge-multiple: false | |
| - name: Resolve release metadata | |
| id: release_meta | |
| shell: bash | |
| run: | | |
| if [ "${GITHUB_EVENT_NAME}" = "workflow_dispatch" ]; then | |
| echo "version=${{ inputs.release_version }}" >> "$GITHUB_OUTPUT" | |
| echo "tag=v${{ inputs.release_version }}" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT" | |
| echo "tag=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Normalize artifact layout | |
| shell: bash | |
| run: | | |
| mkdir -p artifacts-normalized | |
| for dir in artifacts/*; do | |
| target="$(basename "$dir")" | |
| mkdir -p "artifacts-normalized/$target" | |
| cp "$dir"/* "artifacts-normalized/$target/" | |
| done | |
| - name: Sync npm versions | |
| env: | |
| RELEASE_VERSION: ${{ steps.release_meta.outputs.version }} | |
| run: npm run release:sync-version | |
| - name: Stage npm binaries | |
| run: npm run release:stage-binaries -- --source-root artifacts-normalized --target aarch64-apple-darwin --target x86_64-apple-darwin | |
| - name: Pack npm packages | |
| run: npm run release:pack -- --target aarch64-apple-darwin --target x86_64-apple-darwin | |
| - name: Name macOS binaries uniquely for the release | |
| shell: bash | |
| run: | | |
| cp artifacts-normalized/aarch64-apple-darwin/jucode jucode-aarch64-apple-darwin | |
| cp artifacts-normalized/x86_64-apple-darwin/jucode jucode-x86_64-apple-darwin | |
| - name: Upload macOS assets to GitHub release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.release_meta.outputs.tag }} | |
| files: | | |
| jucode-aarch64-apple-darwin | |
| jucode-x86_64-apple-darwin | |
| dist/npm/*darwin*.tgz | |
| - name: Publish macOS npm packages | |
| if: ${{ env.NODE_AUTH_TOKEN != '' }} | |
| run: | | |
| npm publish ./npm/cli-darwin-arm64 --access public | |
| npm publish ./npm/cli-darwin-x64 --access public |