Brew formula update #40
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
| # Copyright AGNTCY Contributors (https://github.com/agntcy) | |
| # SPDX-License-Identifier: Apache-2.0 | |
| name: Brew formula update | |
| # This workflow automatize the brew formula file update process with replacing the version number to the latest, | |
| # recalculate all hash for the binaries and create a new PR with the changes. | |
| on: | |
| release: | |
| types: [released] | |
| workflow_call: | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| formula-update: | |
| name: Update Formula | |
| runs-on: ubuntu-latest | |
| env: | |
| # Required for `gh` CLI authentication | |
| GH_TOKEN: ${{ secrets.AGNTCY_BUILD_BOT_GH_TOKEN }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 | |
| with: | |
| fetch-depth: 0 | |
| - name: Download latest binary releases | |
| id: release-infos | |
| run: | | |
| LATEST_VERSION=$(gh release list --limit 1 --json tagName --jq '.[] | .tagName') | |
| echo "LATEST_VERSION=$LATEST_VERSION" >> $GITHUB_OUTPUT | |
| gh release download $LATEST_VERSION | |
| echo "DIRCTL_HASH_DARWIN_ARM=$(sha256sum ./dirctl-darwin-arm64 | cut -d ' ' -f 1)" >> $GITHUB_OUTPUT | |
| echo "DIRCTL_HASH_DARWIN_AMD=$(sha256sum ./dirctl-darwin-amd64 | cut -d ' ' -f 1)" >> $GITHUB_OUTPUT | |
| echo "DIRCTL_HASH_LINUX_ARM=$(sha256sum ./dirctl-linux-arm64 | cut -d ' ' -f 1)" >> $GITHUB_OUTPUT | |
| echo "DIRCTL_HASH_LINUX_AMD=$(sha256sum ./dirctl-linux-amd64 | cut -d ' ' -f 1)" >> $GITHUB_OUTPUT | |
| - name: Update Brew formula | |
| id: brew-formula | |
| run: | | |
| # Note: the following account information will not work on GHES | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git remote set-url origin https://github.com/agntcy/dir.git | |
| git push origin --delete chore/brew-formula-update || true | |
| git checkout -B chore/brew-formula-update origin/main | |
| # Replace version | |
| sed -i "s/version \"v*.*.*\"/version \""${{ steps.release-infos.outputs.LATEST_VERSION }}"\"/" HomebrewFormula/dirctl.rb | |
| # Replace hashes | |
| sed -i "/url \".*\/dirctl-darwin-arm64\"/ {N;s/sha256 \".*\"/sha256 \"${{ steps.release-infos.outputs.DIRCTL_HASH_DARWIN_ARM }}\"/}" ./HomebrewFormula/dirctl.rb | |
| sed -i "/url \".*\/dirctl-darwin-amd64\"/ {N;s/sha256 \".*\"/sha256 \"${{ steps.release-infos.outputs.DIRCTL_HASH_DARWIN_AMD }}\"/}" ./HomebrewFormula/dirctl.rb | |
| sed -i "/url \".*\/dirctl-linux-arm64\"/ {N;s/sha256 \".*\"/sha256 \"${{ steps.release-infos.outputs.DIRCTL_HASH_LINUX_ARM }}\"/}" ./HomebrewFormula/dirctl.rb | |
| sed -i "/url \".*\/dirctl-linux-amd64\"/ {N;s/sha256 \".*\"/sha256 \"${{ steps.release-infos.outputs.DIRCTL_HASH_LINUX_AMD }}\"/}" ./HomebrewFormula/dirctl.rb | |
| DIFF_FOUND=0 | |
| if ! git diff --exit-code; then | |
| DIFF_FOUND=1 | |
| fi | |
| echo "DIFF_FOUND=$DIFF_FOUND" >> $GITHUB_OUTPUT | |
| if [ $DIFF_FOUND -eq 1 ]; then | |
| git commit ./HomebrewFormula/dirctl.rb -m "chore: update brew formula version" --signoff | |
| git push --set-upstream origin chore/brew-formula-update | |
| fi | |
| - name: Test new formula | |
| id: test-brew-formula | |
| if: ${{ steps.brew-formula.outputs.DIFF_FOUND == 1 }} | |
| run: | | |
| apt update && apt install curl git -y | |
| NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" | |
| eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" | |
| # Make local formula for testing from the repo homebrew formula file | |
| brew tap-new --no-git agntcy/dir-test | |
| FORMULA_DIR="$(brew --repository)/Library/Taps/agntcy/homebrew-dir-test/Formula/" | |
| cp ./HomebrewFormula/dirctl.rb "$FORMULA_DIR" | |
| brew install agntcy/dir-test/dirctl --verbose | |
| dirctl --help | |
| - name: Create PR | |
| if: ${{ steps.brew-formula.outputs.DIFF_FOUND == 1 && steps.test-brew-formula.outcome == 'success' }} | |
| run: | | |
| gh pr create --title "chore(dirctl): update brew formula to ${{ steps.release-infos.outputs.LATEST_VERSION }}" --body "This PR is created by brew-formula-update workflow." |