name: Release
on:
push:
tags:
- 'v*'
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run linter
run: npm run lint --if-present
- name: Build project
run: npm run build
- name: Run tests
run: npm test
publish-npm:
needs: test
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build project
run: npm run build
- name: Determine npm tag
id: npm-tag
run: |
VERSION=${GITHUB_REF#refs/tags/v}
if [[ $VERSION == *"-beta"* ]]; then
echo "tag=beta" >> $GITHUB_OUTPUT
elif [[ $VERSION == *"-alpha"* ]]; then
echo "tag=alpha" >> $GITHUB_OUTPUT
elif [[ $VERSION == *"-rc"* ]]; then
echo "tag=rc" >> $GITHUB_OUTPUT
elif [[ $VERSION == *"-next"* ]]; then
echo "tag=next" >> $GITHUB_OUTPUT
else
echo "tag=latest" >> $GITHUB_OUTPUT
fi
- name: Publish to npm
run: npm publish --access public --tag ${{ steps.npm-tag.outputs.tag }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
create-github-release:
needs: test
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate release notes
id: changelog
run: |
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -z "$PREVIOUS_TAG" ]; then
echo "No previous tag found, including all commits"
CHANGELOG=$(git log --pretty=format:"- %s (%h)" --no-merges)
else
echo "Generating changelog from $PREVIOUS_TAG to ${{ github.ref_name }}"
CHANGELOG=$(git log --pretty=format:"- %s (%h)" --no-merges ${PREVIOUS_TAG}..${{ github.ref_name }})
fi
# Format changelog for GitHub release
echo "## What's Changed" > release_notes.md
echo "" >> release_notes.md
echo "$CHANGELOG" >> release_notes.md
echo "" >> release_notes.md
echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${PREVIOUS_TAG}...${{ github.ref_name }}" >> release_notes.md
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
body_path: release_notes.md
prerelease: ${{ contains(github.ref_name, '-beta') || contains(github.ref_name, '-alpha') || contains(github.ref_name, '-rc') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}