name: Release
on:
release:
types: [published]
jobs:
publish-npm:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
registry-url: https://registry.npmjs.org
- run: npm ci
- run: npm test
- name: Verify tag matches package version
run: node -e "const fs=require('fs');const pkg=JSON.parse(fs.readFileSync('package.json','utf8'));const tag=(process.env.GITHUB_REF_NAME||'').replace(/^v/,'');if(!tag){throw new Error('Missing release tag');}if(pkg.version!==tag){throw new Error(`Tag ${tag} does not match package.json ${pkg.version}`);}"
- run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
update-brew:
needs: publish-npm
runs-on: ubuntu-latest
permissions:
contents: read
env:
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
steps:
- name: Skip if no Homebrew token
if: env.HOMEBREW_TAP_TOKEN == ''
run: echo "HOMEBREW_TAP_TOKEN not set; skipping brew update."
- name: Resolve version
if: env.HOMEBREW_TAP_TOKEN != ''
run: |
TAG="${GITHUB_REF_NAME}"
VERSION="${TAG#v}"
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
- name: Download npm tarball
if: env.HOMEBREW_TAP_TOKEN != ''
run: |
TARBALL_URL="https://registry.npmjs.org/@kfastov/tgcli/-/tgcli-${VERSION}.tgz"
curl -fsSL "$TARBALL_URL" -o tgcli.tgz
echo "TARBALL_URL=$TARBALL_URL" >> "$GITHUB_ENV"
echo "SHA256=$(sha256sum tgcli.tgz | awk '{print $1}')" >> "$GITHUB_ENV"
- uses: actions/checkout@v4
if: env.HOMEBREW_TAP_TOKEN != ''
with:
repository: kfastov/homebrew-tap
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
path: homebrew-tap
- name: Update formula
if: env.HOMEBREW_TAP_TOKEN != ''
env:
FORMULA_PATH: homebrew-tap/Formula/tgcli.rb
run: |
python - <<'PY'
import os
import pathlib
import re
path = pathlib.Path(os.environ["FORMULA_PATH"])
text = path.read_text()
url = os.environ["TARBALL_URL"]
sha = os.environ["SHA256"]
text = re.sub(r'^(\s*url\s+\").*(\")', r'\g<1>%s\g<2>' % url, text, flags=re.M)
text = re.sub(r'^(\s*sha256\s+\").*(\")', r'\g<1>%s\g<2>' % sha, text, flags=re.M)
path.write_text(text)
PY
- name: Commit and push
if: env.HOMEBREW_TAP_TOKEN != ''
run: |
cd homebrew-tap
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Formula/tgcli.rb
git commit -m "chore(brew): bump tgcli to ${VERSION}" || exit 0
git push