Skip to content

fix(release): Simplify shell script format #16

fix(release): Simplify shell script format

fix(release): Simplify shell script format #16

Workflow file for this run

name: Create Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g., 1.4.0)'
required: true
type: string
use_existing_changelog:
description: 'Use existing CHANGELOG_{VERSION}.md file instead of generating one'
required: false
type: boolean
default: false
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
name: Create GitHub Release
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract version
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
VERSION="${{ github.event.inputs.version }}"
else
# Extract version from tag (e.g., v1.4.0 -> 1.4.0)
VERSION="${GITHUB_REF#refs/tags/v}"
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Check for existing changelog
id: changelog_check
run: |
VERSION="${{ steps.version.outputs.version }}"
CHANGELOG_FILE="CHANGELOG_${VERSION}.md"
if [ "${{ github.event.inputs.use_existing_changelog }}" = "true" ] && [ -f "$CHANGELOG_FILE" ]; then
echo "changelog_exists=true" >> $GITHUB_OUTPUT
echo "Using existing changelog: $CHANGELOG_FILE"
elif [ -f "$CHANGELOG_FILE" ]; then
echo "changelog_exists=false" >> $GITHUB_OUTPUT
echo "Changelog file exists but use_existing_changelog is false"
else
echo "changelog_exists=false" >> $GITHUB_OUTPUT
echo "No changelog file found, will generate with git-cliff"
- name: Install git-cliff
if: steps.changelog_check.outputs.changelog_exists == 'false'
run: |
# Download and install git-cliff
wget -qO- https://github.com/orhun/git-cliff/releases/latest/download/git-cliff-linux-amd64.tar.gz
tar -xzf git-cliff-linux-amd64.tar.gz
sudo mv git-cliff /usr/local/bin/
chmod +x /usr/local/bin/git-cliff
git-cliff --version
- name: Generate changelog with git-cliff
if: steps.changelog_check.outputs.changelog_exists == 'false'
run: |
VERSION="${{ steps.version.outputs.version }}"
git-cliff --config cliff.toml --tag "v$VERSION" --verbose > CHANGELOG.md
- name: Format generated changelog
if: steps.changelog_check.outputs.changelog_exists == 'false'
run: |
VERSION="${{ steps.version.outputs.version }}"
echo "# Changelog - Version $VERSION" > CHANGELOG_temp.md
echo "" >> CHANGELOG_temp.md
echo "*This changelog was automatically generated using git-cliff*" >> CHANGELOG_temp.md
echo "" >> CHANGELOG_temp.md
cat CHANGELOG.md >> CHANGELOG_temp.md
mv CHANGELOG_temp.md CHANGELOG.md
cp CHANGELOG.md "CHANGELOG_${VERSION}.md"
- name: Create release notes
id: release_notes
run: |
VERSION="${{ steps.version.outputs.version }}"
if [ "${{ steps.changelog_check.outputs.changelog_exists }}" = "true" ]; then
CHANGELOG_FILE="CHANGELOG_${VERSION}.md"
echo "### Release $VERSION" > release_notes.md
echo "" >> release_notes.md
echo "*Using existing \`$CHANGELOG_FILE\`*" >> release_notes.md
echo "" >> release_notes.md
cat "$CHANGELOG_FILE" >> release_notes.md
else
echo "### Release $VERSION" > release_notes.md
echo "" >> release_notes.md
echo "*Automatically generated using git-cliff*" >> release_notes.md
echo "" >> release_notes.md
tail -n +2 CHANGELOG.md >> release_notes.md
fi
echo "notes_file=release_notes.md" >> $GITHUB_OUTPUT
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION="${{ steps.version.outputs.version }}"
NOTES_FILE="${{ steps.release_notes.outputs.notes_file }}"
gh release create "v$VERSION" --title "v$VERSION" --notes-file "$NOTES_FILE" --repo "$GITHUB_REPOSITORY"
- name: Commit new changelog if generated
if: steps.changelog_check.outputs.changelog_exists == 'false'
uses: EndBug/add-and-commit@v9
with:
message: 'chore: Generate changelog for v${{ steps.version.outputs.version }} [skip ci]'
add: '.'
path: 'CHANGELOG_${{ steps.version.outputs.version }}.md'
- name: Upload changelog artifact
uses: actions/upload-artifact@v4
with:
name: changelog-${{ steps.version.outputs.version }}
path: |
CHANGELOG_${{ steps.version.outputs.version }}.md
CHANGELOG.md
release_notes.md