feat: multi-platform release builds with homebrew tap automation #5
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*" | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: Existing tag to publish via release | |
| required: true | |
| permissions: | |
| contents: write | |
| jobs: | |
| tests: | |
| name: Run tests | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: dtolnay/rust-toolchain@stable | |
| - name: Cargo test | |
| run: cargo test --locked | |
| build-macos: | |
| name: Build macOS (${{ matrix.arch }}) | |
| runs-on: macos-14 | |
| needs: tests | |
| strategy: | |
| matrix: | |
| arch: [amd64, arm64] | |
| include: | |
| - arch: amd64 | |
| target: x86_64-apple-darwin | |
| - arch: arm64 | |
| target: aarch64-apple-darwin | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Build | |
| run: | | |
| cargo build --release --locked --target ${{ matrix.target }} | |
| - name: Package | |
| run: | | |
| BINARY="plausible-darwin-${{ matrix.arch }}" | |
| cp target/${{ matrix.target }}/release/plausible "dist/${BINARY}" 2>/dev/null || { | |
| mkdir -p dist | |
| cp target/${{ matrix.target }}/release/plausible "dist/${BINARY}" | |
| } | |
| chmod +x "dist/${BINARY}" | |
| tar -C dist -czf "dist/${BINARY}.tar.gz" "${BINARY}" | |
| rm "dist/${BINARY}" | |
| (cd dist && shasum -a 256 "${BINARY}.tar.gz" > "${BINARY}.tar.gz.sha256") | |
| - name: Smoke test (arm64 only) | |
| if: matrix.arch == 'arm64' | |
| run: | | |
| tar -xzf dist/plausible-darwin-arm64.tar.gz -C dist | |
| ./dist/plausible-darwin-arm64 --help >/dev/null | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: macos-${{ matrix.arch }} | |
| path: dist/* | |
| build-linux: | |
| name: Build Linux (${{ matrix.arch }}) | |
| runs-on: ubuntu-latest | |
| needs: tests | |
| strategy: | |
| matrix: | |
| arch: [amd64, arm64] | |
| include: | |
| - arch: amd64 | |
| target: x86_64-unknown-linux-gnu | |
| use_cross: false | |
| - arch: arm64 | |
| target: aarch64-unknown-linux-gnu | |
| use_cross: true | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Install cross | |
| if: matrix.use_cross | |
| run: cargo install cross --git https://github.com/cross-rs/cross | |
| - name: Build (native) | |
| if: "!matrix.use_cross" | |
| run: cargo build --release --locked --target ${{ matrix.target }} | |
| - name: Build (cross) | |
| if: matrix.use_cross | |
| run: cross build --release --locked --target ${{ matrix.target }} | |
| - name: Package | |
| run: | | |
| mkdir -p dist | |
| BINARY="plausible-linux-${{ matrix.arch }}" | |
| cp target/${{ matrix.target }}/release/plausible "dist/${BINARY}" | |
| chmod +x "dist/${BINARY}" | |
| tar -C dist -czf "dist/${BINARY}.tar.gz" "${BINARY}" | |
| rm "dist/${BINARY}" | |
| (cd dist && sha256sum "${BINARY}.tar.gz" > "${BINARY}.tar.gz.sha256") | |
| - name: Smoke test (amd64 only) | |
| if: matrix.arch == 'amd64' | |
| run: | | |
| tar -xzf dist/plausible-linux-amd64.tar.gz -C dist | |
| ./dist/plausible-linux-amd64 --help >/dev/null | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: linux-${{ matrix.arch }} | |
| path: dist/* | |
| release: | |
| name: Create GitHub Release | |
| runs-on: ubuntu-latest | |
| needs: | |
| - build-macos | |
| - build-linux | |
| steps: | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| - name: Prepare release files | |
| run: | | |
| mkdir -p release-files | |
| find artifacts -type f -name '*.tar.gz' -exec mv {} release-files/ \; | |
| find artifacts -type f -name '*.sha256' -exec cat {} \; > release-files/checksums.txt | |
| - name: Resolve tag | |
| id: tag | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| echo "value=${{ inputs.tag }}" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "value=${{ github.ref_name }}" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Create GitHub Release | |
| if: steps.tag.outputs.value != '' | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: | | |
| release-files/*.tar.gz | |
| release-files/*.sha256 | |
| release-files/checksums.txt | |
| tag_name: ${{ steps.tag.outputs.value }} | |
| update-homebrew: | |
| name: Update Homebrew formula | |
| runs-on: ubuntu-latest | |
| needs: release | |
| steps: | |
| - name: Resolve tag | |
| id: tag | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| echo "value=${{ inputs.tag }}" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "value=${{ github.ref_name }}" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Checkout tap repository | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: vicentereig/homebrew-tap | |
| token: ${{ secrets.HOMEBREW_TAP_TOKEN }} | |
| path: homebrew-tap | |
| - name: Update formula | |
| run: | | |
| TAG="${{ steps.tag.outputs.value }}" | |
| VERSION="${TAG#v}" | |
| BASE_URL="https://github.com/vicentereig/plausible-cli/releases/download/${TAG}" | |
| FORMULA="homebrew-tap/Formula/plausible.rb" | |
| # Download SHA256 values from release | |
| DARWIN_AMD64=$(curl -sL "${BASE_URL}/plausible-darwin-amd64.tar.gz.sha256" | awk '{print $1}') | |
| DARWIN_ARM64=$(curl -sL "${BASE_URL}/plausible-darwin-arm64.tar.gz.sha256" | awk '{print $1}') | |
| LINUX_AMD64=$(curl -sL "${BASE_URL}/plausible-linux-amd64.tar.gz.sha256" | awk '{print $1}') | |
| LINUX_ARM64=$(curl -sL "${BASE_URL}/plausible-linux-arm64.tar.gz.sha256" | awk '{print $1}') | |
| # Update version | |
| sed -i "s/version \".*\"/version \"${VERSION}\"/" "$FORMULA" | |
| # Update SHA256 values | |
| sed -i "/darwin-amd64/,/sha256/{s/sha256 \"[^\"]*\"/sha256 \"${DARWIN_AMD64}\"/}" "$FORMULA" | |
| sed -i "/darwin-arm64/,/sha256/{s/sha256 \"[^\"]*\"/sha256 \"${DARWIN_ARM64}\"/}" "$FORMULA" | |
| sed -i "/linux-amd64/,/sha256/{s/sha256 \"[^\"]*\"/sha256 \"${LINUX_AMD64}\"/}" "$FORMULA" | |
| sed -i "/linux-arm64/,/sha256/{s/sha256 \"[^\"]*\"/sha256 \"${LINUX_ARM64}\"/}" "$FORMULA" | |
| - name: Commit and push | |
| working-directory: homebrew-tap | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add Formula/plausible.rb | |
| git diff --staged --quiet || git commit -m "Update plausible to ${{ steps.tag.outputs.value }}" | |
| git push |