diff --git a/.github/workflows/update-homebrew.yaml b/.github/workflows/update-homebrew.yaml new file mode 100644 index 0000000000..e50179c15b --- /dev/null +++ b/.github/workflows/update-homebrew.yaml @@ -0,0 +1,88 @@ +name: update-homebrew + +on: + release: + types: [published] + +jobs: + update-formula: + runs-on: ubuntu-latest + steps: + - name: Extract version from tag + id: version + run: | + VERSION="${GITHUB_REF#refs/tags/v}" + echo "version=${VERSION}" >> $GITHUB_OUTPUT + echo "Version: ${VERSION}" + + - name: Checkout homebrew-tap repository + uses: actions/checkout@v6 + with: + repository: siderolabs/homebrew-tap + token: ${{ secrets.HOMEBREW_TAP_TOKEN }} + path: homebrew-tap + + - name: Update Homebrew formula + env: + VERSION: ${{ steps.version.outputs.version }} + run: | + cd homebrew-tap + + FORMULA="Formula/talosctl.rb" + CURRENT_VERSION=$(grep -Po 'version "\K(\d+\.\d+\.\d+)' "${FORMULA}") + echo "Current version: ${CURRENT_VERSION}" + echo "New version: ${VERSION}" + + grep -Po '(url "\K[^"]+)|(sha256 "\K[^"]+)' "${FORMULA}" | while IFS= read -r url && read -r old_hash; do + new_url="${url//\#\{version\}/${VERSION}}" + + echo "===> Downloading ${new_url}..." + wget -q -O /tmp/talosctl-binary "${new_url}" + + echo "=====> Calculating SHA256 checksum..." + new_hash=$(sha256sum /tmp/talosctl-binary | awk '{print $1}') + echo "=====> Old hash: ${old_hash}" + echo "=====> New hash: ${new_hash}" + + echo "=====> Updating hash in formula..." + sed -i "s/${old_hash}/${new_hash}/" "${FORMULA}" + + rm /tmp/talosctl-binary + done + + echo "===> Updating version in formula: ${CURRENT_VERSION} -> ${VERSION}" + sed -i "s/${CURRENT_VERSION}/${VERSION}/g" "${FORMULA}" + + echo "===> Updated formula:" + cat "${FORMULA}" + + - name: Commit and push changes + env: + VERSION: ${{ steps.version.outputs.version }} + run: | + cd homebrew-tap + + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + git checkout -b "update-talosctl-v${VERSION}" + git add Formula/talosctl.rb + git commit -m "chore: update talosctl to v${VERSION}" + git push origin "update-talosctl-v${VERSION}" + + - name: Create Pull Request + env: + VERSION: ${{ steps.version.outputs.version }} + GH_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }} + run: | + cd homebrew-tap + + gh pr create \ + --title "chore: update talosctl to v${VERSION}" \ + --body "Automated update of talosctl formula to version v${VERSION} + + This PR was automatically generated by the update-homebrew workflow. + + Release: https://github.com/${{ github.repository }}/releases/tag/v${VERSION}" \ + --head "update-talosctl-v${VERSION}" \ + --base main