ci: fix release #7
This file contains 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 | |
permissions: | |
id-token: write | |
contents: write | |
on: | |
push: | |
branches: | |
- master | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Install pnpm | |
uses: pnpm/action-setup@v4 | |
with: | |
version: 'latest' | |
- name: Setup Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ matrix.node-version }} | |
cache: 'pnpm' | |
- name: Install dependencies | |
run: pnpm i | |
- name: Lint | |
run: pnpm lint | |
- name: Benchmark | |
run: pnpm vitest bench --run | tee bench_results.txt | |
continue-on-error: true | |
- name: Get current version | |
id: get_version | |
run: echo "PACKAGE_VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV | |
- name: Check for version changes | |
id: version_check | |
run: | | |
git fetch --tags | |
PREV_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0") | |
echo "Previous version: $PREV_VERSION" | |
echo "Current version: $PACKAGE_VERSION" | |
if [ "$PACKAGE_VERSION" != "$PREV_VERSION" ]; then | |
echo "version_changed=true" >> $GITHUB_ENV | |
else | |
echo "version_changed=false" >> $GITHUB_ENV | |
fi | |
- name: Setup npmrc | |
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc | |
- name: Publish to npm | |
if: env.version_changed == 'true' | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
run: pnpm publish --no-git-checks | |
- name: Create GitHub release and tag | |
if: env.version_changed == 'true' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
git tag v$PACKAGE_VERSION | |
git push origin v$PACKAGE_VERSION | |
BENCH_RESULTS="$(cat bench_results.txt)" | |
RELEASE_NOTES="### Benchmark Results: | |
\`\`\` | |
$BENCH_RESULTS | |
\`\`\`" | |
echo "$RELEASE_NOTES" > release_notes.md | |
gh release create v$PACKAGE_VERSION --title "v$PACKAGE_VERSION" --notes-file release_notes.md |