Reconcile formulae #64
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
| name: Reconcile Formulae | |
| run-name: Reconcile formulae${{ inputs.formula && format(' ({0})', inputs.formula) || '' }}${{ github.event_name == 'workflow_dispatch' && inputs.dry_run && ' [dry run]' || '' }} | |
| on: | |
| schedule: | |
| - cron: "17 */3 * * *" | |
| workflow_dispatch: | |
| inputs: | |
| formula: | |
| description: "Optional single formula to inspect" | |
| required: false | |
| type: string | |
| dry_run: | |
| description: "Verify and report drift without committing" | |
| required: true | |
| default: true | |
| type: boolean | |
| permissions: | |
| contents: write | |
| concurrency: | |
| group: reconcile-formulae | |
| cancel-in-progress: false | |
| jobs: | |
| reconcile: | |
| if: >- | |
| github.ref_protected == true && | |
| github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && | |
| endsWith(github.workflow_ref, format('@refs/heads/{0}', github.event.repository.default_branch)) | |
| runs-on: macos-15 | |
| steps: | |
| - name: Checkout tap repository | |
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | |
| with: | |
| persist-credentials: false | |
| ref: ${{ github.sha }} | |
| - name: Setup Git | |
| env: | |
| DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} | |
| run: | | |
| git checkout -B "$DEFAULT_BRANCH" "$GITHUB_SHA" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| - name: Reconcile formulae | |
| env: | |
| DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && inputs.dry_run && 'true' || 'false' }} | |
| FORMULA: ${{ github.event_name == 'workflow_dispatch' && inputs.formula || '' }} | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| args=() | |
| if [ -n "$FORMULA" ]; then | |
| args+=(--formula "$FORMULA") | |
| fi | |
| if [ "$DRY_RUN" = "true" ]; then | |
| args+=(--dry-run) | |
| fi | |
| python3 .github/scripts/reconcile_formulae.py "${args[@]}" | |
| - name: Validate formulae | |
| run: | | |
| python3 -m unittest discover -s tests -v | |
| for formula in Formula/*.rb; do | |
| ruby -c "$formula" | |
| done | |
| brew style Formula/*.rb | |
| - name: Commit and push | |
| env: | |
| DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} | |
| DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && inputs.dry_run && 'true' || 'false' }} | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| if [ "$DRY_RUN" = "true" ]; then | |
| git diff --exit-code | |
| echo "Dry run left the checkout unchanged" | |
| exit 0 | |
| fi | |
| git add Formula/*.rb | |
| if git diff --cached --quiet; then | |
| echo "All formulae are current; no commit needed" | |
| exit 0 | |
| fi | |
| git commit -m "chore: reconcile Homebrew formulae" | |
| gh auth setup-git | |
| for attempt in 1 2 3; do | |
| if git push origin "HEAD:refs/heads/${DEFAULT_BRANCH}"; then | |
| exit 0 | |
| fi | |
| if [ "$attempt" -eq 3 ]; then | |
| echo "git push failed after ${attempt} attempts" >&2 | |
| exit 1 | |
| fi | |
| git pull --rebase origin "$DEFAULT_BRANCH" | |
| python3 -m unittest discover -s tests -v | |
| for formula in Formula/*.rb; do | |
| ruby -c "$formula" | |
| done | |
| brew style Formula/*.rb | |
| done |