Skip to content

update-formula

update-formula #17

Workflow file for this run

name: Bump Homebrew formula
on:
repository_dispatch:
types: [update-formula]
workflow_dispatch:
inputs:
formula_new_version:
description: "New version of the formula"
required: true
type: string
formula_name:
description: "Name of the formula"
required: true
type: string
formula_url:
description: "URL of the formula"
required: true
type: string
formula_homebrew_tap:
description: "Homebrew tap"
required: true
type: string
env:
FORMULA_NEW_VERSION: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.formula_new_version || inputs.formula_new_version }}
FORMULA_NAME: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.formula_name || inputs.formula_name }}
FORMULA_URL: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.formula_url || inputs.formula_url }}
FORMULA_HOMEBREW_TAP: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.formula_homebrew_tap || inputs.formula_homebrew_tap }}
jobs:
bump-homebrew-formula:
name: Bump Homebrew formula
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout source repository
uses: actions/checkout@v4
- name: Update Homebrew formula
uses: mislav/bump-homebrew-formula-action@v3
env:
COMMITTER_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
formula-name: ${{ env.FORMULA_NAME }}
formula-path: Formula/${{ env.FORMULA_NAME }}.rb
download-url: ${{ env.FORMULA_URL }}
homebrew-tap: ${{ github.repository }}
tag-name: v${{ env.FORMULA_NEW_VERSION }}
base-branch: master
create-pullrequest: true
commit-message: Updated formula to version ${{ env.FORMULA_NEW_VERSION }}
- name: Give pre-commit a little time to start running to prevent error
run: sleep 10
- name: Try to enable auto-merge of pull request and delete branch
env:
GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
run: | # Ignore errors if pull request can't be merged. Then we just have to do it manually.
sleep 2
PULL_REQUEST_NUMBER=$(gh pr list --json number --jq ".[0].number" || echo "")
if [ -n "$PULL_REQUEST_NUMBER" ]; then
gh pr merge "$PULL_REQUEST_NUMBER" --auto --merge --delete-branch || true
fi
update-version-badge:
name: Update version badge in README.md
needs: bump-homebrew-formula
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout source repository
uses: actions/checkout@v4
- name: Update version badge in README.md
run: |
sed -i "s/label=version\&message=[0-9].*\&/label=version\&message=${{ env.FORMULA_NEW_VERSION }}\&/" README.md
- name: Show changes in Git
run: git diff --patch --stat
- name: Commit changes and create pull request
uses: peter-evans/create-pull-request@v7
with:
commit-message: "Updated version badge to ${{ env.FORMULA_NEW_VERSION }}"
title: "Update version badge to ${{ env.FORMULA_NEW_VERSION }}"
body: "This pull request updates the version badge in README.md to version ${{ env.FORMULA_NEW_VERSION }}."
branch: update-version-badge-${{ env.FORMULA_NEW_VERSION }}
labels: enhancement
base: master
delete-branch: true
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
- name: Give pre-commit a little time to start running to prevent error
run: sleep 10
- name: Try to enable auto-merge of pull request and delete branch
env:
GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
run: | # Ignore errors if pull request can't be merged. Then we just have to do it manually.
sleep 2
PULL_REQUEST_NUMBER=$(gh pr list --json number --jq ".[0].number" || echo "")
if [ -n "$PULL_REQUEST_NUMBER" ]; then
gh pr merge "$PULL_REQUEST_NUMBER" --auto --merge --delete-branch || true
fi