Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions .github/workflows/bump-homebrew.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Bump Homebrew formula

# Keeps tambo-labs/homebrew-tap's charming.rb pointed at the latest
# published npm tarball. Triggers off this repo's own GitHub Release
# (created by release.yml), so it only ever points at a version that
# already published successfully.
#
# Uses HOMEBREW_TAP_TOKEN, a fine-grained PAT scoped to just
# tambo-labs/homebrew-tap with Contents: read/write — not the
# CLI_SYNC_APP_ID app used elsewhere in this repo, since that app was
# never actually installed (see sync-openapi.yml, which has been
# disabled and has never run).

on:
release:
types: [published]
workflow_dispatch:
inputs:
version:
description: Version to bump the formula to (no leading v, e.g. 0.1.2)
required: true

permissions:
contents: read

jobs:
bump:
runs-on: ubuntu-latest
steps:
- name: Resolve version
id: version
run: |
version="${{ inputs.version }}"
if [ -z "$version" ]; then
version="${GITHUB_REF_NAME#v}"
fi
echo "version=$version" >> "$GITHUB_OUTPUT"

- name: Download tarball and compute sha256
id: tarball
run: |
version="${{ steps.version.outputs.version }}"
url="https://registry.npmjs.org/usecharming/-/usecharming-${version}.tgz"
curl -sL -o package.tgz "$url"
sha256=$(shasum -a 256 package.tgz | cut -d' ' -f1)
echo "url=$url" >> "$GITHUB_OUTPUT"
echo "sha256=$sha256" >> "$GITHUB_OUTPUT"

- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: tambo-labs/homebrew-tap
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
path: homebrew-tap

- name: Update formula
working-directory: homebrew-tap
run: |
version="${{ steps.version.outputs.version }}"
url="${{ steps.tarball.outputs.url }}"
sha256="${{ steps.tarball.outputs.sha256 }}"
sed -i "s#^ url \".*\"# url \"${url}\"#" Formula/charming.rb
sed -i "s#^ sha256 \".*\"# sha256 \"${sha256}\"#" Formula/charming.rb
if git diff --quiet; then
echo "changed=false" >> "$GITHUB_ENV"
else
echo "changed=true" >> "$GITHUB_ENV"
fi

- if: env.changed == 'true'
name: Commit and push
working-directory: homebrew-tap
run: |
version="${{ steps.version.outputs.version }}"
git config user.name "charming-cli-release[bot]"
git config user.email "charming-cli-release[bot]@users.noreply.github.com"
git switch -C "bump/charming-${version}"
git add Formula/charming.rb
git commit -m "charming ${version}"
git push --force origin "bump/charming-${version}"
env:
GH_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}

- if: env.changed == 'true'
name: Open PR
working-directory: homebrew-tap
run: |
version="${{ steps.version.outputs.version }}"
count=$(gh pr list --repo tambo-labs/homebrew-tap --head "bump/charming-${version}" --state open --json number --jq length)
if [ "$count" -eq 0 ]; then
gh pr create --repo tambo-labs/homebrew-tap \
--base main \
--head "bump/charming-${version}" \
--title "charming ${version}" \
--body "Bumps the charming formula to ${version}, matching the npm release."
fi
env:
GH_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}