Skip to content

Commit

Permalink
Automate homebrew releases
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-helmich committed Jul 27, 2023
1 parent 6e219d7 commit 2c19bd8
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,54 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

release-homebrew:
runs-on: ubuntu-latest
needs:
- build-linux
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Checkout Homebrew repo
uses: actions/checkout@v3
with:
repository: mittwald/homebrew-cli
path: homebrew
token: ${{ secrets.MACHINE_USER_TOKEN }}

- name: Download artifacts
uses: actions/download-artifact@v3

- name: Generate Homebrew formula
run: |
sed \
's/__VERSION_/${GITHUB_REF_NAME#v}/' \
's/__VERSIONHASH__/$(git rev-parse --short ${{ github.sha }})/' \
's/__SHA_X64/$(sha256sum pkg-tarballs/mw-*-x64.tar.xz | awk '{print $1}')/' \
's/__SHA_ARM64/$(sha256sum pkg-tarballs/mw-*-arm64.tar.xz | awk '{print $1}')/' < scripts/release/homebrew.rb > homebrew/mw.rb
- name: Generate .netrc
run: |
echo -e "machine github.com\nlogin ${MACHINE_USER_NAME}\npassword ${MACHINE_USER_TOKEN}" > ~/.netrc
env:
MACHINE_USER_NAME: ${{ secrets.MACHINE_USER_NAME }}
MACHINE_USER_TOKEN: ${{ secrets.MACHINE_USER_TOKEN }}

- name: Commit and push
run: |
cd homebrew
git config --global user.email "[email protected]"
git config --global user.name "mittwald machine"
git add mw.rb
git commit -m "Release ${GITHUB_REF_NAME}"
git push
cleanup-artifacts:
runs-on: ubuntu-latest
needs:
- release-github
- release-docker
- release-homebrew
steps:
- uses: geekyeggo/delete-artifact@v1
with:
Expand Down
25 changes: 25 additions & 0 deletions scripts/release/homebrew.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Mw < Formula
desc "The mittwald command-line tool"
homepage "https://github.com/mittwald/cli"
url "https://mittwald-cli.s3.eu-central-1.amazonaws.com/versions/__VERSION__/__VERSIONHASH__/mw-v__VERSION__-__VERSIONHASH__-darwin-x64.tar.xz"
sha256 "__SHA_X64__"
version "__VERSION__"
version_scheme 1

on_macos do
if Hardware::CPU.arm?
url "https://mittwald-cli.s3.eu-central-1.amazonaws.com/versions/__VERSION__/__VERSIONHASH__/mw-v__VERSION__-__VERSIONHASH__-darwin-arm64.tar.xz"
sha256 "__SHA_ARM64__"
end
end

def install
inreplace "bin/mw", /^CLIENT_HOME=/, "export HEROKU_OCLIF_CLIENT_HOME=#{lib/"client"}\nCLIENT_HOME="
libexec.install Dir["*"]
bin.install_symlink libexec/"bin/mw"
end

test do
system bin/"mw", "--version"
end
end

0 comments on commit 2c19bd8

Please sign in to comment.