-
Notifications
You must be signed in to change notification settings - Fork 25
Automate Homebrew cask updates during release #130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,7 +118,38 @@ else | |
| --generate-notes | ||
| fi | ||
|
|
||
| # --- 11. Update Homebrew cask --- | ||
| echo "🍺 Updating Homebrew cask..." | ||
| ZIP_SHA=$(shasum -a 256 "$ZIP_PATH" | awk '{print $1}') | ||
| TAP_REPO="pablopunk/homebrew-brew" | ||
| TAP_CLONE_DIR="$(mktemp -d /tmp/swiftshift-homebrew.XXXXXX)" | ||
| TAP_CASK_PATH="$TAP_CLONE_DIR/Casks/swift-shift.rb" | ||
| GIT_REMOTE="https://github.com/$TAP_REPO.git" | ||
|
|
||
| if [[ -n "${GH_PAT:-}" ]]; then | ||
| GIT_REMOTE="https://x-access-token:${GH_PAT}@github.com/$TAP_REPO.git" | ||
| fi | ||
|
|
||
| git clone "$GIT_REMOTE" "$TAP_CLONE_DIR" | ||
| sed -i '' "s/version \".*\"/version \"$VERSION\"/" "$TAP_CASK_PATH" | ||
| sed -i '' "s/sha256 \".*\"/sha256 \"$ZIP_SHA\"/" "$TAP_CASK_PATH" | ||
| ruby -c "$TAP_CASK_PATH" | ||
|
Comment on lines
+134
to
+136
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fail fast when cask replacements don’t apply. If either ✅ Suggested hardening sed -i '' "s/version \".*\"/version \"$VERSION\"/" "$TAP_CASK_PATH"
sed -i '' "s/sha256 \".*\"/sha256 \"$ZIP_SHA\"/" "$TAP_CASK_PATH"
ruby -c "$TAP_CASK_PATH"
+
+if ! grep -q "version \"$VERSION\"" "$TAP_CASK_PATH"; then
+ echo "Failed to update cask version to $VERSION"
+ exit 1
+fi
+if ! grep -q "sha256 \"$ZIP_SHA\"" "$TAP_CASK_PATH"; then
+ echo "Failed to update cask sha256 to $ZIP_SHA"
+ exit 1
+fiAlso applies to: 141-147 🤖 Prompt for AI Agents |
||
|
|
||
| pushd "$TAP_CLONE_DIR" > /dev/null | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
| if ! git diff --quiet -- Casks/swift-shift.rb; then | ||
| git add Casks/swift-shift.rb | ||
| git commit -m "swift-shift: update to $VERSION" | ||
| git push | ||
| else | ||
| echo "Homebrew cask already up to date." | ||
| fi | ||
| popd > /dev/null | ||
| rm -rf "$TAP_CLONE_DIR" | ||
|
|
||
| echo "" | ||
| echo "✅ Release $VERSION complete!" | ||
| echo " PR: $PR_URL" | ||
| echo " Release: https://github.com/pablopunk/SwiftShift/releases/tag/$VERSION" | ||
| echo " Homebrew: https://github.com/$TAP_REPO/blob/main/Casks/swift-shift.rb" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid credential-in-URL cloning and guarantee cleanup on failure.
At Line 130,
GH_PATis embedded in the remote URL. That token can end up in.git/configinside the temp clone, and because cleanup only happens at Line 149, any earlier failure can leave credentials on disk in/tmp.Please switch to a non-URL credential flow and register cleanup with an
EXIThandler that also preserves the existing cleanup behavior.Also applies to: 149-149
🤖 Prompt for AI Agents