-
Notifications
You must be signed in to change notification settings - Fork 0
ci(release): bump homebrew-tap formula on leadtype publish #33
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -69,3 +69,114 @@ jobs: | |
| run: | | ||
| echo "Published: ${{ steps.changesets.outputs.published }}" | ||
| echo "Published packages: ${{ steps.changesets.outputs.publishedPackages }}" | ||
|
|
||
| outputs: | ||
| published: ${{ steps.changesets.outputs.published }} | ||
| publishedPackages: ${{ steps.changesets.outputs.publishedPackages }} | ||
|
|
||
| # Opens a PR against inthhq/homebrew-tap whenever a new leadtype version is | ||
| # published to npm. Requires repository secret TAP_GITHUB_TOKEN: a | ||
| # fine-grained personal access token scoped to inthhq/homebrew-tap with | ||
| # Contents: write and Pull requests: write. | ||
| bump-homebrew-tap: | ||
| name: Bump Homebrew tap | ||
| needs: release | ||
| if: | | ||
| needs.release.outputs.published == 'true' && | ||
| github.repository == 'inthhq/leadtype' | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| steps: | ||
| - name: Extract published leadtype version | ||
| id: version | ||
| env: | ||
| PUBLISHED: ${{ needs.release.outputs.publishedPackages }} | ||
| run: | | ||
| set -euo pipefail | ||
| VERSION="$(node -e ' | ||
| const pkgs = JSON.parse(process.env.PUBLISHED || "[]"); | ||
| const hit = pkgs.find(p => p.name === "leadtype"); | ||
| if (!hit) { process.exit(0); } | ||
| process.stdout.write(hit.version); | ||
| ')" | ||
| if [ -z "$VERSION" ]; then | ||
| echo "leadtype not in publishedPackages; nothing to bump." | ||
| echo "skip=true" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| fi | ||
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Wait for npm tarball to be served and compute sha256 | ||
| id: sha | ||
| if: steps.version.outputs.skip != 'true' | ||
| env: | ||
| VERSION: ${{ steps.version.outputs.version }} | ||
| run: | | ||
| set -euo pipefail | ||
| URL="https://registry.npmjs.org/leadtype/-/leadtype-${VERSION}.tgz" | ||
| for i in 1 2 3 4 5 6 7 8 9 10; do | ||
| if curl -fSL --connect-timeout 10 --max-time 60 "$URL" -o leadtype.tgz; then | ||
| break | ||
| fi | ||
| echo "Attempt $i: tarball not ready yet, sleeping..." | ||
| sleep $((i * 6)) | ||
| done | ||
| test -s leadtype.tgz | ||
| SHA="$(shasum -a 256 leadtype.tgz | awk '{print $1}')" | ||
| echo "sha256=$SHA" >> "$GITHUB_OUTPUT" | ||
| echo "url=$URL" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Check out homebrew-tap | ||
| if: steps.version.outputs.skip != 'true' | ||
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
| with: | ||
| repository: inthhq/homebrew-tap | ||
| token: ${{ secrets.TAP_GITHUB_TOKEN }} | ||
| path: homebrew-tap | ||
|
|
||
| - name: Update formula | ||
| if: steps.version.outputs.skip != 'true' | ||
| env: | ||
| VERSION: ${{ steps.version.outputs.version }} | ||
| URL: ${{ steps.sha.outputs.url }} | ||
| SHA: ${{ steps.sha.outputs.sha256 }} | ||
| run: | | ||
| set -euo pipefail | ||
| cd homebrew-tap | ||
| node -e ' | ||
| const fs = require("node:fs"); | ||
| const path = "Formula/leadtype.rb"; | ||
| const src = fs.readFileSync(path, "utf8"); | ||
| const next = src | ||
| .replace(/^(\s*url\s+).*$/m, `$1"${process.env.URL}"`) | ||
| .replace(/^(\s*sha256\s+).*$/m, `$1"${process.env.SHA}"`); | ||
| if (next === src) { | ||
| console.error("Formula did not change; refusing to commit."); | ||
| process.exit(1); | ||
| } | ||
| fs.writeFileSync(path, next); | ||
|
Comment on lines
+147
to
+158
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. Assert that both formula fields were replaced. This script only checks whether the file changed at all. If Suggested fix node -e '
const fs = require("node:fs");
const path = "Formula/leadtype.rb";
const src = fs.readFileSync(path, "utf8");
+ let replacedUrl = false;
+ let replacedSha = false;
const next = src
- .replace(/^(\s*url\s+).*$/m, `$1"${process.env.URL}"`)
- .replace(/^(\s*sha256\s+).*$/m, `$1"${process.env.SHA}"`);
- if (next === src) {
- console.error("Formula did not change; refusing to commit.");
+ .replace(/^(\s*url\s+).*$/m, (_, prefix) => {
+ replacedUrl = true;
+ return `${prefix}"${process.env.URL}"`;
+ })
+ .replace(/^(\s*sha256\s+).*$/m, (_, prefix) => {
+ replacedSha = true;
+ return `${prefix}"${process.env.SHA}"`;
+ });
+ if (!replacedUrl || !replacedSha) {
+ console.error("Expected url and sha256 fields were not both found.");
+ process.exit(1);
+ }
+ if (next === src) {
+ console.error("Formula did not change; refusing to commit.");
process.exit(1);
}
fs.writeFileSync(path, next);
'🤖 Prompt for AI Agents |
||
| ' | ||
| git diff -- Formula/leadtype.rb | ||
|
|
||
| - name: Create pull request | ||
| if: steps.version.outputs.skip != 'true' | ||
| uses: peter-evans/create-pull-request@22a9089034f40e5a961c8808d113e2c98fb63676 # v7.0.11 | ||
| with: | ||
| path: homebrew-tap | ||
| token: ${{ secrets.TAP_GITHUB_TOKEN }} | ||
| branch: bump-leadtype-${{ steps.version.outputs.version }} | ||
| base: main | ||
| commit-message: "leadtype ${{ steps.version.outputs.version }}" | ||
| title: "leadtype ${{ steps.version.outputs.version }}" | ||
| body: | | ||
| Bump `leadtype` to `${{ steps.version.outputs.version }}`. | ||
|
|
||
| - tarball: ${{ steps.sha.outputs.url }} | ||
| - sha256: `${{ steps.sha.outputs.sha256 }}` | ||
|
|
||
| Auto-generated by [inthhq/leadtype](https://github.com/inthhq/leadtype) release pipeline. Tap CI will run `brew audit --strict --online` and `brew test leadtype` against this change before it can be merged. | ||
| delete-branch: true | ||
| labels: | | ||
| automated | ||
| release | ||
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.
Fail explicitly on incomplete downloads, not just empty files.
test -s leadtype.tgzonly proves the file is non-empty. A failedcurlcan still leave a partial tarball behind, so this block may compute a SHA-256 for truncated content and open a broken tap PR. Track whether any retry actually succeeded and clear the file before each attempt.Suggested fix
URL="https://registry.npmjs.org/leadtype/-/leadtype-${VERSION}.tgz" + downloaded=false for i in 1 2 3 4 5 6 7 8 9 10; do + rm -f leadtype.tgz if curl -fSL --connect-timeout 10 --max-time 60 "$URL" -o leadtype.tgz; then + downloaded=true break fi echo "Attempt $i: tarball not ready yet, sleeping..." sleep $((i * 6)) done - test -s leadtype.tgz + $downloaded || { echo "Tarball was never downloaded successfully"; exit 1; } SHA="$(shasum -a 256 leadtype.tgz | awk '{print $1}')"🤖 Prompt for AI Agents