Publish to npm and Create GitHub Release #27
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: Publish to npm and Create GitHub Release | |
on: | |
push: | |
tags: | |
- 'v*' # Trigger on tags matching v* | |
workflow_dispatch: | |
jobs: | |
publish-to-npm: | |
name: Publish to npm | |
runs-on: ubuntu-latest | |
permissions: | |
id-token: write | |
steps: | |
- name: Checkout source | |
uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: 20 # Corrected node version | |
registry-url: 'https://registry.npmjs.org' | |
cache: npm | |
# Optional step to clear npm cache | |
- name: Clear npm Cache (Optional) | |
run: npm cache clean --force | |
- name: Install dependencies and build | |
run: npm ci | |
- name: Publish package | |
run: npm publish --access public | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # Replace with your secret variable name | |
create-github-release: | |
name: Create GitHub Release | |
runs-on: ubuntu-latest | |
needs: publish-to-npm # This job depends on the successful completion of publish-to-npm | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Determine if release notes exist | |
id: release_notes | |
run: | | |
if [[ $(git status --porcelain -- "*.md" | grep CHANGELOG.md) ]]; then | |
# Release notes found (CHANGELOG.md has changes) | |
echo "NOTES=true" >> $GITHUB_ENV | |
else | |
# No release notes | |
echo "NOTES=false" >> $GITHUB_ENV | |
fi | |
- name: Create Release (if there are release notes) | |
if: steps.release_notes.outputs.notes == 'true' | |
run: gh release create ${{ github.ref }} --generate-notes | |
env: | |
RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }} # Replace with your secret variable name | |