Skip to content

Release v1.0.2: GitHub repository and npm publication #2

Release v1.0.2: GitHub repository and npm publication

Release v1.0.2: GitHub repository and npm publication #2

Workflow file for this run

name: Release
on:
push:
tags:
- 'v*'
permissions:
contents: write
packages: write
jobs:
release:
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm ci
- name: Build package
run: npm run build
- name: Run tests
run: npm test
- name: Generate changelog
id: changelog
run: |
# Get the tag name
TAG_NAME=${GITHUB_REF#refs/tags/}
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_OUTPUT
# Get previous tag for changelog generation
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD~1 2>/dev/null || echo "")
if [ -z "$PREVIOUS_TAG" ]; then
# First release - include all commits
CHANGELOG=$(git log --pretty=format:"- %s" --no-merges)
else
# Generate changelog between tags
CHANGELOG=$(git log ${PREVIOUS_TAG}..HEAD --pretty=format:"- %s" --no-merges)
fi
# Save changelog to file and output
echo "$CHANGELOG" > RELEASE_CHANGELOG.md
echo "PREVIOUS_TAG=$PREVIOUS_TAG" >> $GITHUB_OUTPUT
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
name: Release ${{ steps.changelog.outputs.TAG_NAME }}
body_path: RELEASE_CHANGELOG.md
draft: false
prerelease: ${{ contains(steps.changelog.outputs.TAG_NAME, '-') }}
generate_release_notes: true
files: |
dist/*
package.json
README.md
LICENSE
CHANGELOG.md
- name: Publish to npm
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Update package-lock.json
if: ${{ !contains(steps.changelog.outputs.TAG_NAME, '-') }}
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
npm version patch --no-git-tag-version
git add package.json package-lock.json
git commit -m "chore: update version after release [skip ci]" || exit 0
git push origin HEAD:main || exit 0