release.yml•3.09 kB
name: Release
on:
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g., 1.0.1)'
required: true
type: string
prerelease:
description: 'Mark as pre-release'
required: false
type: boolean
default: false
jobs:
prepare-release:
name: Prepare Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Update version
run: npm version ${{ github.event.inputs.version }} --no-git-tag-version
- name: Build project
run: npm run build
- name: Run tests
run: npm run test
- name: Generate changelog
run: |
echo "# Release ${{ github.event.inputs.version }}" > RELEASE_NOTES.md
echo "" >> RELEASE_NOTES.md
echo "## Changes" >> RELEASE_NOTES.md
echo "" >> RELEASE_NOTES.md
git log --pretty=format:"- %s" $(git describe --tags --abbrev=0)..HEAD >> RELEASE_NOTES.md || echo "- Initial release" >> RELEASE_NOTES.md
- name: Commit version bump
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add package.json package-lock.json
git commit -m "chore: bump version to ${{ github.event.inputs.version }}"
git push
- name: Create Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ github.event.inputs.version }}
release_name: Release v${{ github.event.inputs.version }}
body_path: RELEASE_NOTES.md
draft: false
prerelease: ${{ github.event.inputs.prerelease }}
post-release:
name: Post Release Tasks
runs-on: ubuntu-latest
needs: prepare-release
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: v${{ github.event.inputs.version }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build project
run: npm run build
- name: Publish to NPM
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create GitHub deployment
uses: actions/github-script@v7
with:
script: |
github.rest.repos.createDeployment({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'v${{ github.event.inputs.version }}',
environment: 'production',
description: 'Deploy version ${{ github.event.inputs.version }} to NPM'
});