From 4126245a976d42a9ae7e324d68f3a6fe663e49d1 Mon Sep 17 00:00:00 2001 From: Owen Nelson Date: Mon, 27 Jan 2025 15:53:42 -0800 Subject: [PATCH] CLI: enable homebrew installer The dist docs for for the `homebrew` installer indicate there are two parts to this: 1. create a "tap" repo and a github token for dist to use to manage it 2. configure dist here (with the token as a secret) The first piece will need to be done by someone else. This diff does the 2nd piece. The config for dist targets the extant `svix/homebrew-svix` repo, which appears to be where the tap lived previously. It's not clear if we'd need to empty that repo, reboot it, or anything else. Refs: - https://opensource.axo.dev/cargo-dist/book/installers/homebrew.html - https://github.com/svix/homebrew-svix --- .github/workflows/release.yml | 48 ++++++++++++++++++++++++++++++++++- dist-workspace.toml | 6 ++++- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 08082184f..9dce9015c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -276,14 +276,60 @@ jobs: gh release edit "${{ needs.plan.outputs.tag }}" --target "$RELEASE_COMMIT" $PRERELEASE_FLAG --draft=false + publish-homebrew-formula: + needs: + - plan + - host + runs-on: "ubuntu-20.04" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PLAN: ${{ needs.plan.outputs.val }} + GITHUB_USER: "axo bot" + GITHUB_EMAIL: "admin+bot@axo.dev" + if: ${{ !fromJson(needs.plan.outputs.val).announcement_is_prerelease || fromJson(needs.plan.outputs.val).publish_prereleases }} + steps: + - uses: actions/checkout@v4 + with: + repository: "svix/homebrew-svix" + token: ${{ secrets.HOMEBREW_TAP_TOKEN }} + # So we have access to the formula + - name: Fetch homebrew formulae + uses: actions/download-artifact@v4 + with: + pattern: artifacts-* + path: Formula/ + merge-multiple: true + # This is extra complex because you can make your Formula name not match your app name + # so we need to find releases with a *.rb file, and publish with that filename. + - name: Commit formula files + run: | + git config --global user.name "${GITHUB_USER}" + git config --global user.email "${GITHUB_EMAIL}" + + for release in $(echo "$PLAN" | jq --compact-output '.releases[] | select([.artifacts[] | endswith(".rb")] | any)'); do + filename=$(echo "$release" | jq '.artifacts[] | select(endswith(".rb"))' --raw-output) + name=$(echo "$filename" | sed "s/\.rb$//") + version=$(echo "$release" | jq .app_version --raw-output) + + export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH" + brew update + # We avoid reformatting user-provided data such as the app description and homepage. + brew style --except-cops FormulaAudit/Homepage,FormulaAudit/Desc,FormulaAuditStrict --fix "Formula/${filename}" || true + + git add "Formula/${filename}" + git commit -m "${name} ${version}" + done + git push + announce: needs: - plan - host + - publish-homebrew-formula # use "always() && ..." to allow us to wait for all publish jobs while # still allowing individual publish jobs to skip themselves (for prereleases). # "host" however must run to completion, no skipping allowed! - if: ${{ always() && needs.host.result == 'success' }} + if: ${{ always() && needs.host.result == 'success' && (needs.publish-homebrew-formula.result == 'skipped' || needs.publish-homebrew-formula.result == 'success') }} runs-on: "ubuntu-20.04" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/dist-workspace.toml b/dist-workspace.toml index 5dc4118f4..48633e047 100644 --- a/dist-workspace.toml +++ b/dist-workspace.toml @@ -8,7 +8,7 @@ cargo-dist-version = "0.28.0" # CI backends to support ci = "github" # The installers to generate for each app -installers = ["shell", "powershell", "msi"] +installers = ["shell", "powershell", "homebrew", "msi"] # Target platforms to build apps for (Rust target-triple syntax) targets = ["aarch64-apple-darwin", "aarch64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-unknown-linux-musl", "x86_64-pc-windows-msvc"] # Whether dist should create a Github Release or use an existing draft @@ -19,4 +19,8 @@ install-path = "~/.svix/bin" install-updater = true # Whether CI should trigger releases with dispatches instead of tag pushes dispatch-releases = true +# A GitHub repo to push Homebrew formulas to +tap = "svix/homebrew-svix" +# Publish jobs to run in CI +publish-jobs = ["homebrew"]