name: Release
on:
workflow_call:
inputs:
version:
required: true
type: string
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
release:
name: Create Release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create git tag
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git tag "v${{ inputs.version }}"
git push origin "v${{ inputs.version }}"
- name: Generate release notes
id: notes
run: |
# get the previous tag to know where to start reading commits
PREV_TAG=$(git tag --sort=-version:refname | sed -n '2p')
if [ -z "$PREV_TAG" ]; then
COMMITS=$(git log --pretty=format:"%s" HEAD)
else
COMMITS=$(git log --pretty=format:"%s" ${PREV_TAG}..HEAD)
fi
FEATURES=""
FIXES=""
REFACTORS=""
CORE=""
TESTS=""
DOCS=""
BUILD=""
while IFS= read -r commit; do
PREFIX=$(echo "$commit" | grep -oP '^[a-z]+(?=:)' || echo "")
VERB=$(echo "$commit" | grep -oP '(?<=:\s)[a-z]+' || echo "")
MESSAGE=$(echo "$commit" | grep -oP '(?<=:\s).+' || echo "")
# prefix wins routing
case "$PREFIX" in
test) TESTS="$TESTS\n- $MESSAGE" ;;
docs) DOCS="$DOCS\n- $MESSAGE" ;;
build) BUILD="$BUILD\n- $MESSAGE" ;;
core) CORE="$CORE\n- $MESSAGE" ;;
release) ;; # silently drop release commits
*)
case "$VERB" in
add) FEATURES="$FEATURES\n- $MESSAGE" ;;
fix) FIXES="$FIXES\n- $MESSAGE" ;;
refactor) REFACTORS="$REFACTORS\n- $MESSAGE" ;;
esac
;;
esac
done <<< "$COMMITS"
# build the release body, sections only appear if they have content
BODY=""
[ -n "$FEATURES" ] && BODY="$BODY\n## ๐ Features\n$FEATURES\n"
[ -n "$FIXES" ] && BODY="$BODY\n## ๐ Fixes\n$FIXES\n"
[ -n "$REFACTORS" ] && BODY="$BODY\n## โป๏ธ Refactors\n$REFACTORS\n"
[ -n "$CORE" ] && BODY="$BODY\n## โ๏ธ Core\n$CORE\n"
[ -n "$TESTS" ] && BODY="$BODY\n## ๐งช Tests\n$TESTS\n"
[ -n "$DOCS" ] && BODY="$BODY\n## ๐ Docs\n$DOCS\n"
[ -n "$BUILD" ] && BODY="$BODY\n## ๐ง Build\n$BUILD\n"
# write to file to avoid quoting issues
printf "$BODY" > release_notes.md
- name: Create GitHub release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ inputs.version }}
name: v${{ inputs.version }}
body_path: release_notes.md
prerelease: ${{ startsWith(inputs.version, '0.0.') }}