|
| 1 | +name: Update Homebrew Tap |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + |
| 7 | +jobs: |
| 8 | + update-tap: |
| 9 | + name: Update homebrew-cortex-auth formula |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Compute SHA256 for macOS tarballs |
| 13 | + id: sha |
| 14 | + env: |
| 15 | + VERSION: ${{ github.ref_name }} |
| 16 | + GH_REPO: ${{ github.repository }} |
| 17 | + run: | |
| 18 | + BASE="https://github.com/${GH_REPO}/releases/download/${VERSION}" |
| 19 | +
|
| 20 | + AARCH64_FILE="cortex-auth-${VERSION}-aarch64-apple-darwin.tar.gz" |
| 21 | + X86_64_FILE="cortex-auth-${VERSION}-x86_64-apple-darwin.tar.gz" |
| 22 | +
|
| 23 | + curl -fLO "${BASE}/${AARCH64_FILE}" |
| 24 | + curl -fLO "${BASE}/${X86_64_FILE}" |
| 25 | +
|
| 26 | + echo "aarch64=$(sha256sum ${AARCH64_FILE} | awk '{print $1}')" >> "$GITHUB_OUTPUT" |
| 27 | + echo "x86_64=$(sha256sum ${X86_64_FILE} | awk '{print $1}')" >> "$GITHUB_OUTPUT" |
| 28 | + echo "version=${VERSION#v}" >> "$GITHUB_OUTPUT" |
| 29 | +
|
| 30 | + - name: Checkout homebrew tap |
| 31 | + uses: actions/checkout@v4 |
| 32 | + with: |
| 33 | + repository: davideuler/homebrew-cortex-auth |
| 34 | + token: ${{ secrets.HOMEBREW_TAP_TOKEN }} |
| 35 | + path: tap |
| 36 | + |
| 37 | + - name: Update formula |
| 38 | + env: |
| 39 | + VERSION: ${{ steps.sha.outputs.version }} |
| 40 | + SHA_AARCH64: ${{ steps.sha.outputs.aarch64 }} |
| 41 | + SHA_X86_64: ${{ steps.sha.outputs.x86_64 }} |
| 42 | + run: | |
| 43 | + FORMULA="tap/Formula/cortex-auth.rb" |
| 44 | +
|
| 45 | + sed -i "s|version \".*\"|version \"${VERSION}\"|" "$FORMULA" |
| 46 | + sed -i "s|sha256 \"PLACEHOLDER_AARCH64_APPLE_DARWIN_SHA256\"|sha256 \"${SHA_AARCH64}\"|" "$FORMULA" |
| 47 | + sed -i "s|sha256 \"PLACEHOLDER_X86_64_APPLE_DARWIN_SHA256\"|sha256 \"${SHA_X86_64}\"|" "$FORMULA" |
| 48 | +
|
| 49 | + # For subsequent releases, replace the previous SHA values too |
| 50 | + python3 - <<'EOF' |
| 51 | + import re, os |
| 52 | +
|
| 53 | + formula = open("tap/Formula/cortex-auth.rb").read() |
| 54 | +
|
| 55 | + ver = os.environ["VERSION"] |
| 56 | + sha_arm = os.environ["SHA_AARCH64"] |
| 57 | + sha_x86 = os.environ["SHA_X86_64"] |
| 58 | +
|
| 59 | + # Update version |
| 60 | + formula = re.sub(r'version "[^"]+"', f'version "{ver}"', formula) |
| 61 | +
|
| 62 | + # Update sha256 values — first occurrence is arm, second is x86_64 |
| 63 | + sha_pattern = re.compile(r'(sha256 ")[^"]+(")') |
| 64 | + occurrences = list(sha_pattern.finditer(formula)) |
| 65 | + if len(occurrences) >= 2: |
| 66 | + # Replace from end to avoid offset shifts |
| 67 | + formula = formula[:occurrences[1].start()] + f'sha256 "{sha_x86}"' + formula[occurrences[1].end():] |
| 68 | + formula = formula[:occurrences[0].start()] + f'sha256 "{sha_arm}"' + formula[occurrences[0].end():] |
| 69 | +
|
| 70 | + open("tap/Formula/cortex-auth.rb", "w").write(formula) |
| 71 | + print(formula) |
| 72 | + EOF |
| 73 | +
|
| 74 | + - name: Commit and push |
| 75 | + working-directory: tap |
| 76 | + env: |
| 77 | + VERSION: ${{ steps.sha.outputs.version }} |
| 78 | + run: | |
| 79 | + git config user.name "github-actions[bot]" |
| 80 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 81 | + git add Formula/cortex-auth.rb |
| 82 | + git diff --cached --quiet || git commit -m "cortex-auth ${VERSION}" |
| 83 | + git push |
0 commit comments