chore(release): v2.0.3 #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| if: ${{ secrets.HOMEBREW_TAP_TOKEN != '' }} | ||
| permissions: | ||
| contents: read | ||
| steps: | ||
| - name: Resolve version | ||
| run: | | ||
| TAG="${GITHUB_REF_NAME}" | ||
| VERSION="${TAG#v}" | ||
| echo "VERSION=$VERSION" >> "$GITHUB_ENV" | ||
| - name: Download npm tarball | ||
| 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 | ||
| with: | ||
| repository: kfastov/homebrew-tap | ||
| token: ${{ secrets.HOMEBREW_TAP_TOKEN }} | ||
| path: homebrew-tap | ||
| - name: Update formula | ||
| 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'\\1%s\\2' % url, text, flags=re.M) | ||
| text = re.sub(r'^(\\s*sha256\\s+\").*(\")', r'\\1%s\\2' % sha, text, flags=re.M) | ||
| path.write_text(text) | ||
| PY | ||
| - name: Commit and push | ||
| 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 | ||