|
| 1 | +name: UpdateHomebrew |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: 'v*' |
| 6 | + |
| 7 | +jobs: |
| 8 | + homebrew: |
| 9 | + name: Bump Homebrew formula |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - uses: mislav/bump-homebrew-formula-action@v3 |
| 13 | + with: |
| 14 | + homebrew-tap: 'vetlewi/homebrew-formula' |
| 15 | + formula-name: 'xia2tree' |
| 16 | + formula-path: 'xia2tree.rb' |
| 17 | + base-branch: 'main' |
| 18 | + env: |
| 19 | + # the personal access token should have "repo" & "workflow" scopes |
| 20 | + COMMITTER_TOKEN: ${{ secrets.COMMITTER_TOKEN }} |
| 21 | + deploy: |
| 22 | + needs: homebrew |
| 23 | + runs-on: macos-latest |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v4 |
| 26 | + |
| 27 | + - name: Add tap |
| 28 | + run: brew tap vetlewi/formula |
| 29 | + |
| 30 | + - name: Update homebrew |
| 31 | + run: brew update |
| 32 | + |
| 33 | + - name: Install via homebrew |
| 34 | + run: brew install --build-bottle xia2tree |
| 35 | + |
| 36 | + - name: Bottle binary |
| 37 | + run: brew bottle --root-url="https://github.com/vetlewi/XIA2tree/releases/download/${{ github.ref_name }}" --no-rebuild xia2tree |
| 38 | + |
| 39 | + - name: Upload bottle to release |
| 40 | + uses: softprops/action-gh-release@v1 |
| 41 | + with: |
| 42 | + files: ./xia2tree--*.tar.gz |
| 43 | + env: |
| 44 | + GITHUB_TOKEN: {{ secrets.COMMITTER_TOKEN }} |
| 45 | + |
| 46 | + - name: Commit updated bottle block |
| 47 | + run: | |
| 48 | + # Clone the tap repo |
| 49 | + git clone https://x-access-token:${{ secrets.COMMITTER_TOKEN }}@github.com/vetlewi/homebrew-formula.git |
| 50 | + cd homebrew-formula |
| 51 | +
|
| 52 | + # Replace the old bottle block using Ruby logic |
| 53 | + FORMULA_PATH="xia2tree.rb" |
| 54 | + NEW_BOTTLE_BLOCK=$(brew bottle ./xia2tree.rb --json | jq -r '.formula.bottle | " bottle do\n root_url \"" + .root_url + "\"\n sha256 cellar: :any_skip_relocation, " + (.tags | to_entries[] | "\(.key): \"" + .value.sha256 + "\"") + "\n end"') |
| 55 | +
|
| 56 | + # Use sed to replace old bottle block (naively here, better if you use Ruby) |
| 57 | + awk ' |
| 58 | + BEGIN { skip = 0 } |
| 59 | + /^ bottle do/, /^ end$/ { skip = 1 } |
| 60 | + skip && /^ end$/ { skip = 0; next } |
| 61 | + !skip { print } |
| 62 | + ' "$FORMULA_PATH" > tmp.rb |
| 63 | +
|
| 64 | + echo "$NEW_BOTTLE_BLOCK" >> tmp.rb |
| 65 | + mv tmp.rb "$FORMULA_PATH" |
| 66 | +
|
| 67 | + git config user.name "github-actions" |
| 68 | + git config user.email "github-actions@github.com" |
| 69 | + git add "$FORMULA_PATH" |
| 70 | + git commit -m "Update bottle block for xia2tree ${{ github.ref_name }}" |
| 71 | + git push origin main |
0 commit comments