Update a formula #23
This file contains 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
# docs: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions | |
name: Update a formula | |
on: | |
workflow_dispatch: | |
inputs: | |
subject: | |
description: which formula to update? | |
required: true | |
type: choice | |
options: | |
- cli | |
- gomod | |
version: | |
description: which version shall be published | |
required: true | |
type: string | |
concurrency: | |
group: '${{ github.workflow }}-${{ github.event.inputs.subject }}' | |
cancel-in-progress: true | |
env: | |
UF_SUBJECT: ${{ github.event.inputs.subject }} | |
UF_VERSION: ${{ github.event.inputs.version }} | |
ARTIFACT_FORMULA: formula | |
ARTIFACT_FORMULA_FIXED: formula_fixed | |
jobs: | |
update: | |
name: "Update Formula: ${{ github.event.inputs.subject }} ${{ github.event.inputs.version }}" | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
steps: | |
- name: Checkout | |
# see https://github.com/actions/checkout | |
uses: actions/checkout@v4 | |
- name: Update Formula | |
run: > | |
.github/scripts/update-formula/"$UF_SUBJECT"/gen.sh | |
"${UF_VERSION}" | |
> Formula/cyclonedx-"$UF_SUBJECT".rb | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Artifact Formula | |
# https://github.com/actions/upload-artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ env.ARTIFACT_FORMULA }} | |
path: Formula/cyclonedx-${{ env.UF_SUBJECT }}.rb | |
if-no-files-found: error | |
retention-days: 3 | |
fix-test: | |
# https://docs.brew.sh/Adding-Software-to-Homebrew#testing-and-auditing-the-formula | |
needs: [ "update" ] | |
name: "Fix & Test Formula" | |
runs-on: macos-latest | |
timeout-minutes: 10 | |
env: | |
HOMEBREW_NO_AUTO_UPDATE: '1' | |
HOMEBREW_NO_INSTALL_FROM_API: '1' | |
TAP_TESTING: 'local/testing' | |
steps: | |
- run: brew developer on | |
- name: Fetch Formula | |
# https://github.com/actions/download-artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: ${{ env.ARTIFACT_FORMULA }} | |
- name: brew tap formula | |
run: | | |
set -eux | |
brew tap-new "$TAP_TESTING" --no-git | |
ln -s "$PWD/cyclonedx-${UF_SUBJECT}.rb" "$(brew --repo "$TAP_TESTING")"/Formula/ | |
- name: Audit & fix Formula | |
run: brew audit --fix --stric --online "${TAP_TESTING}/cyclonedx-${UF_SUBJECT}" | |
- name: Artifact fixed Formula | |
# `brew audit` might fail, but still fix. in this case, we should modify the template accordingly | |
if: ${{ ! cancelled() }} | |
# https://github.com/actions/upload-artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ env.ARTIFACT_FORMULA_FIXED }} | |
path: cyclonedx-${{ env.UF_SUBJECT }}.rb | |
if-no-files-found: error | |
retention-days: 3 | |
- name: Test Formula | |
run: | | |
set -eux | |
FORMULA="${TAP_TESTING}/cyclonedx-${UF_SUBJECT}" | |
brew install --build-from-source "$FORMULA" | |
brew deps "$FORMULA" | |
brew test --verbose "$FORMULA" | |
brew uninstall "$FORMULA" | |
pullrequest: | |
name: "Commit/PR Formula" | |
permissions: | |
contents: write # push commits | |
pull-requests: write # create pullrequests | |
needs: [ "fix-test" ] | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
steps: | |
- name: Checkout | |
# see https://github.com/actions/checkout | |
uses: actions/checkout@v4 | |
- name: Fetch fixed Formula | |
# https://github.com/actions/download-artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: ${{ env.ARTIFACT_FORMULA_FIXED }} | |
path: Formula | |
- name: Commit & Push | |
run: | | |
set -eux | |
BRANCH_NAME='${{ github.ref_name }}'_"update-formula/${UF_SUBJECT}-${UF_VERSION}" | |
git checkout -B "$BRANCH_NAME" | |
git add -A Formula | |
git config user.name "[BOT] Formula Updater" | |
git config user.email "[email protected]" | |
git commit -s -m "Update ${UF_SUBJECT}: ${UF_VERSION}" | |
git push -f --set-upstream origin "$BRANCH_NAME" | |
- name: Open PullRequest | |
run: > | |
gh pr create | |
--fill-verbose | |
--label "formula: ${UF_SUBJECT}" | |
--base '${{ github.ref_name }}' | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |