diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e9253ae53..1b0b7511e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 "opensource@mittwald.de" + 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: diff --git a/scripts/release/homebrew.rb b/scripts/release/homebrew.rb new file mode 100644 index 000000000..a6bc6a7ff --- /dev/null +++ b/scripts/release/homebrew.rb @@ -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 \ No newline at end of file