Skip to content

Commit

Permalink
feat(dist): automatically publish to a homebrew tap
Browse files Browse the repository at this point in the history
Fixes: #297
  • Loading branch information
zkat committed Sep 30, 2023
1 parent 8d04d84 commit 023ebcc
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 9 deletions.
51 changes: 43 additions & 8 deletions .github/workflows/release.yml
Expand Up @@ -60,7 +60,7 @@ jobs:
- name: Install Rust
run: rustup update "1.72.1" --no-self-update && rustup default "1.72.1"
- name: Install cargo-dist
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.3.0/cargo-dist-installer.sh | sh"
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.3.1/cargo-dist-installer.sh | sh"
- id: plan
run: |
cargo dist plan ${{ !github.event.pull_request && format('--tag={0}', github.ref_name) || '' }} --output-format=json > dist-manifest.json
Expand Down Expand Up @@ -103,17 +103,18 @@ jobs:
- uses: swatinem/rust-cache@v2
- name: Install cargo-dist
run: ${{ matrix.install_dist }}
- name: Build artifacts
run: |
# Actually do builds and make zips and whatnot
cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
echo "cargo dist ran successfully"
- id: cargo-dist
name: Post-build
# We force bash here just because github makes it really hard to get values up
# to "real" actions without writing to env-vars, and writing to env-vars has
# inconsistent syntax between shell and powershell. cargo-dist and jq work fine
# in powershell.
# inconsistent syntax between shell and powershell.
shell: bash
run: |
# Actually do builds and make zips and whatnot
cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
echo "cargo dist ran successfully"
# Parse out what we just built and upload it to the Github Release™
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
Expand All @@ -137,7 +138,7 @@ jobs:
- name: Install Rust
run: rustup update "1.72.1" --no-self-update && rustup default "1.72.1"
- name: Install cargo-dist
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.3.0/cargo-dist-installer.sh | sh"
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.3.1/cargo-dist-installer.sh | sh"
# Get all the local artifacts for the global tasks to use (for e.g. checksums)
- name: Fetch local artifacts
uses: actions/download-artifact@v3
Expand Down Expand Up @@ -171,6 +172,40 @@ jobs:
- name: print tag
run: echo "ok we're publishing!"

publish-homebrew-formula:
needs: [plan, should-publish]
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: "orogene/homebrew-tap"
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
# So we have access to the formula
- name: Fetch local artifacts
uses: actions/download-artifact@v3
with:
name: artifacts
path: Formula/
- 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[]'); do
name=$(echo "$release" | jq .app_name --raw-output)
version=$(echo "$release" | jq .app_version --raw-output)
git add Formula/${name}.rb
git commit -m "${name} ${version}"
done
git push
# Create a Github Release with all the results once everything is done,
publish-release:
needs: [plan, should-publish]
Expand Down
6 changes: 5 additions & 1 deletion Cargo.toml
Expand Up @@ -160,7 +160,7 @@ reqwest-retry = "0.2.2"
# Config for 'cargo dist'
[workspace.metadata.dist]
# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax)
cargo-dist-version = "0.3.0"
cargo-dist-version = "0.3.1"
# The preferred Rust toolchain to use in CI (rustup toolchain syntax)
rust-toolchain-version = "1.72.1"
# CI backends to support
Expand All @@ -177,6 +177,10 @@ unix-archive = ".tar.gz"
pr-run-mode = "plan"
# Skip checking whether the specified configuration files are up to date
allow-dirty = ["msi"]
# A GitHub repo to push Homebrew formulas to
tap = "orogene/homebrew-tap"
# Publish jobs to run in CI
publish-jobs = ["homebrew"]

[build-dependencies]
embed-resource = "1.3.3"
Expand Down
2 changes: 2 additions & 0 deletions rust-toolchain.toml
@@ -0,0 +1,2 @@
[toolchain]
channel = "1.72.1"
5 changes: 5 additions & 0 deletions src/lib.rs
Expand Up @@ -43,6 +43,11 @@
//! $ cargo install orogene
//! ```
//!
//! Homebrew:
//! ```sh
//! $ brew install orogene/homebrew-tap/orogene
//! ```
//!
//! You can also find install scripts, windows MSI installers, and archive
//! downloads in [the latest
//! release](https://github.com/orogene/orogene/releases/latest).
Expand Down

0 comments on commit 023ebcc

Please sign in to comment.