Skip to content

Merge pull request #198 from Gnathonic/develop #22

Merge pull request #198 from Gnathonic/develop

Merge pull request #198 from Gnathonic/develop #22

Workflow file for this run

name: Release
on:
push:
branches: [main]
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check for version change
id: version_check
run: |
# Get current version from package.json
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
# Get previous version from the parent commit
PREVIOUS_VERSION=$(git show HEAD^:package.json 2>/dev/null | node -p "JSON.parse(require('fs').readFileSync('/dev/stdin', 'utf8')).version" 2>/dev/null || echo "")
echo "Current version: $CURRENT_VERSION"
echo "Previous version: $PREVIOUS_VERSION"
# Check if tag already exists
if git rev-parse "v$CURRENT_VERSION" >/dev/null 2>&1; then
echo "Tag v$CURRENT_VERSION already exists"
echo "should_release=false" >> $GITHUB_OUTPUT
elif [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ] && [ -n "$PREVIOUS_VERSION" ]; then
echo "Version changed from $PREVIOUS_VERSION to $CURRENT_VERSION, will create release"
echo "should_release=true" >> $GITHUB_OUTPUT
else
echo "No version change detected"
echo "should_release=false" >> $GITHUB_OUTPUT
fi
# Create and push tag
- name: Create and push tag
if: steps.version_check.outputs.should_release == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag "v${{ steps.version_check.outputs.current_version }}"
git push origin "v${{ steps.version_check.outputs.current_version }}"
# Extract release notes from CHANGELOG.md for this version
- name: Extract release notes
if: steps.version_check.outputs.should_release == 'true'
id: release_notes
run: |
VERSION="${{ steps.version_check.outputs.current_version }}"
# Extract content between this version header and the next version header
NOTES=$(awk "/^## $VERSION/,/^## \[?[0-9]/" CHANGELOG.md | head -n -1 | tail -n +2)
# Use a delimiter for multiline output
echo "notes<<EOF" >> $GITHUB_OUTPUT
echo "$NOTES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
# Create GitHub Release
- name: Create GitHub Release
if: steps.version_check.outputs.should_release == 'true'
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.version_check.outputs.current_version }}
name: v${{ steps.version_check.outputs.current_version }}
body: ${{ steps.release_notes.outputs.notes }}
generate_release_notes: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}