|
| 1 | +name: update-homebrew |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + |
| 7 | +jobs: |
| 8 | + update-formula: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + steps: |
| 11 | + - name: Extract version from tag |
| 12 | + id: version |
| 13 | + run: | |
| 14 | + VERSION="${GITHUB_REF#refs/tags/v}" |
| 15 | + echo "version=${VERSION}" >> $GITHUB_OUTPUT |
| 16 | + echo "Version: ${VERSION}" |
| 17 | +
|
| 18 | + - name: Check if release is latest |
| 19 | + id: check-latest |
| 20 | + env: |
| 21 | + GH_TOKEN: ${{ github.token }} |
| 22 | + run: | |
| 23 | + LATEST_TAG=$(gh release view --repo ${{ github.repository }} --json tagName -q '.tagName') |
| 24 | + CURRENT_TAG="${GITHUB_REF#refs/tags/}" |
| 25 | +
|
| 26 | + echo "Latest release tag: ${LATEST_TAG}" |
| 27 | + echo "Current release tag: ${CURRENT_TAG}" |
| 28 | +
|
| 29 | + if [ "${CURRENT_TAG}" != "${LATEST_TAG}" ]; then |
| 30 | + echo "This release (${CURRENT_TAG}) is not the latest (${LATEST_TAG}). Skipping update." |
| 31 | + echo "is_latest=false" >> $GITHUB_OUTPUT |
| 32 | + else |
| 33 | + echo "This release is the latest. Proceeding with update." |
| 34 | + echo "is_latest=true" >> $GITHUB_OUTPUT |
| 35 | + fi |
| 36 | +
|
| 37 | + - name: Checkout homebrew-tap repository |
| 38 | + if: steps.check-latest.outputs.is_latest == 'true' |
| 39 | + uses: actions/checkout@v6 |
| 40 | + with: |
| 41 | + repository: siderolabs/homebrew-tap |
| 42 | + token: ${{ secrets.HOMEBREW_TAP_TOKEN }} |
| 43 | + path: homebrew-tap |
| 44 | + |
| 45 | + - name: Update Homebrew formula |
| 46 | + if: steps.check-latest.outputs.is_latest == 'true' |
| 47 | + env: |
| 48 | + VERSION: ${{ steps.version.outputs.version }} |
| 49 | + run: | |
| 50 | + cd homebrew-tap |
| 51 | +
|
| 52 | + FORMULA="Formula/talosctl.rb" |
| 53 | + CURRENT_VERSION=$(grep -Po 'version "\K(\d+\.\d+\.\d+)' "${FORMULA}") |
| 54 | + echo "Current version: ${CURRENT_VERSION}" |
| 55 | + echo "New version: ${VERSION}" |
| 56 | +
|
| 57 | + grep -Po '(url "\K[^"]+)|(sha256 "\K[^"]+)' "${FORMULA}" | while IFS= read -r url && read -r old_hash; do |
| 58 | + new_url="${url//\#\{version\}/${VERSION}}" |
| 59 | +
|
| 60 | + echo "===> Downloading ${new_url}..." |
| 61 | + wget -q -O /tmp/talosctl-binary "${new_url}" |
| 62 | +
|
| 63 | + echo "=====> Calculating SHA256 checksum..." |
| 64 | + new_hash=$(sha256sum /tmp/talosctl-binary | awk '{print $1}') |
| 65 | + echo "=====> Old hash: ${old_hash}" |
| 66 | + echo "=====> New hash: ${new_hash}" |
| 67 | +
|
| 68 | + echo "=====> Updating hash in formula..." |
| 69 | + sed -i "s/${old_hash}/${new_hash}/" "${FORMULA}" |
| 70 | +
|
| 71 | + rm /tmp/talosctl-binary |
| 72 | + done |
| 73 | +
|
| 74 | + echo "===> Updating version in formula: ${CURRENT_VERSION} -> ${VERSION}" |
| 75 | + sed -i "s/${CURRENT_VERSION}/${VERSION}/g" "${FORMULA}" |
| 76 | +
|
| 77 | + echo "===> Updated formula:" |
| 78 | + cat "${FORMULA}" |
| 79 | +
|
| 80 | + - name: Commit and push changes |
| 81 | + if: steps.check-latest.outputs.is_latest == 'true' |
| 82 | + env: |
| 83 | + VERSION: ${{ steps.version.outputs.version }} |
| 84 | + run: | |
| 85 | + cd homebrew-tap |
| 86 | +
|
| 87 | + git config user.name "github-actions[bot]" |
| 88 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 89 | +
|
| 90 | + git checkout -b "update-talosctl-v${VERSION}" |
| 91 | + git add Formula/talosctl.rb |
| 92 | + git commit -m "chore: update talosctl to v${VERSION}" |
| 93 | + git push origin "update-talosctl-v${VERSION}" |
| 94 | +
|
| 95 | + - name: Create Pull Request |
| 96 | + if: steps.check-latest.outputs.is_latest == 'true' |
| 97 | + env: |
| 98 | + VERSION: ${{ steps.version.outputs.version }} |
| 99 | + GH_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }} |
| 100 | + run: | |
| 101 | + cd homebrew-tap |
| 102 | +
|
| 103 | + gh pr create \ |
| 104 | + --title "chore: update talosctl to v${VERSION}" \ |
| 105 | + --body "Automated update of talosctl formula to version v${VERSION} |
| 106 | +
|
| 107 | + This PR was automatically generated by the update-homebrew workflow. |
| 108 | +
|
| 109 | + Release: https://github.com/${{ github.repository }}/releases/tag/v${VERSION}" \ |
| 110 | + --head "update-talosctl-v${VERSION}" \ |
| 111 | + --base main |
0 commit comments