Version and Release #61
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: Version and Release | |
on: | |
workflow_run: | |
workflows: ['Storybook to Chromatic'] | |
types: | |
- completed | |
branches: | |
- main | |
jobs: | |
version-and-release: | |
if: | | |
github.event.workflow_run.conclusion == 'success' && | |
github.event.workflow_run.head_branch == 'main' && ( | |
contains(github.event.workflow_run.head_commit.message, 'feat:') || | |
contains(github.event.workflow_run.head_commit.message, 'fix:') || | |
contains(github.event.workflow_run.head_commit.message, 'RELEASE') | |
) | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
token: ${{ secrets.GITHUB_TOKEN }} | |
ref: main | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20.18.0 | |
registry-url: 'https://registry.npmjs.org' | |
- name: Initialize changelog | |
run: | | |
if [ ! -f CHANGELOG.md ]; then | |
echo "# Changelog\n\nAll notable changes to this project will be documented in this file." > CHANGELOG.md | |
git add CHANGELOG.md | |
git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
git config --local user.name "github-actions[bot]" | |
git commit -m "chore: initialize changelog [skip ci]" | |
git push | |
fi | |
- name: Install dependencies | |
run: | | |
yarn install | |
npm install -g conventional-changelog-cli | |
- name: Configure Git | |
run: | | |
git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
git config --local user.name "github-actions[bot]" | |
- name: Bump version | |
id: version | |
run: | | |
npm --no-git-tag-version version patch | |
VERSION=$(node -p "require('./package.json').version") | |
echo "version=$VERSION" >> $GITHUB_OUTPUT | |
git add package.json | |
git commit -m "chore: bump version to ${VERSION} [skip ci]" | |
git push | |
- name: Generate changelog | |
id: changelog | |
run: | | |
# First time generation if changelog is empty | |
if [ ! -s CHANGELOG.md ]; then | |
conventional-changelog -p angular -i CHANGELOG.md -s -r 0 | |
else | |
# Generate changelog for the latest version | |
conventional-changelog -p angular -i CHANGELOG.md -s -r 1 > TEMP_CHANGELOG.md | |
fi | |
# Format changelog for GitHub Actions output | |
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT | |
if [ -f TEMP_CHANGELOG.md ]; then | |
cat TEMP_CHANGELOG.md >> $GITHUB_OUTPUT | |
else | |
echo "Initial release" >> $GITHUB_OUTPUT | |
fi | |
echo "EOF" >> $GITHUB_OUTPUT | |
# Commit changelog updates | |
git add CHANGELOG.md | |
git commit -m "docs: update changelog [skip ci]" || echo "No changelog changes to commit" | |
git push | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: v${{ steps.version.outputs.version }} | |
release_name: Release v${{ steps.version.outputs.version }} | |
body: | | |
Release for version ${{ steps.version.outputs.version }} | |
## What's Changed | |
${{ steps.changelog.outputs.CHANGELOG }} | |
For full changelog, see [CHANGELOG.md](CHANGELOG.md) | |
draft: false | |
prerelease: false | |
- name: Publish to NPM | |
run: npm publish --access public | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |