Skip to content

Cut Release

Cut Release #6

Workflow file for this run

name: Cut Release
on:
workflow_dispatch:
inputs:
dry_run:
description: 'Dry run — generate changelog preview and upload as artifact, skip creating a PR'
type: boolean
default: true
permissions:
contents: write
pull-requests: write
jobs:
create-release-pr:
name: Create Release PR
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0 # git-cliff needs full history to walk tags
- name: Read version
id: version
run: echo "version=$(cat version.txt | tr -d '[:space:]')" >> $GITHUB_OUTPUT
- name: Validate no existing tag
run: |
VERSION="${{ steps.version.outputs.version }}"
git fetch --tags
if git rev-parse --verify "refs/tags/${VERSION}" >/dev/null 2>&1; then
echo "Error: tag '${VERSION}' already exists. Update version.txt before running this workflow."
exit 1
fi
- name: Install git-cliff
run: |
CLIFF_VERSION="2.12.0"
curl -sSfL \
"https://github.com/orhun/git-cliff/releases/download/v${CLIFF_VERSION}/git-cliff-${CLIFF_VERSION}-x86_64-unknown-linux-musl.tar.gz" \
-o /tmp/git-cliff.tar.gz
tar -xzf /tmp/git-cliff.tar.gz -C /tmp
sudo mv $(find /tmp -name 'git-cliff' -type f -maxdepth 3) /usr/local/bin/git-cliff
- name: Generate changelog
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
VERSION="${{ steps.version.outputs.version }}"
# Generate only the new release section and prepend to CHANGELOG.md (preserves manual edits)
git cliff --tag "$VERSION" --unreleased --prepend CHANGELOG.md
# Same content, minus the header, saved separately for the PR body
git cliff --tag "$VERSION" --unreleased --strip header > /tmp/changelog-entry.md
- name: Upload changelog preview (dry run)
if: inputs.dry_run
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: changelog-preview
path: |
CHANGELOG.md
/tmp/changelog-entry.md
- name: Create release branch and open PR
if: ${{ !inputs.dry_run }}
env:
GH_TOKEN: ${{ github.token }}
run: |
VERSION="${{ steps.version.outputs.version }}"
BRANCH="release/${VERSION}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b "$BRANCH"
git add CHANGELOG.md
git commit -m "feat: Release version ${VERSION}"
git push origin "$BRANCH"
# Build the PR body: header + generated changelog entry
cat > /tmp/pr-body.md << PREOF
## Release ${VERSION}
This PR was automatically generated by the release workflow.
Review and edit \`CHANGELOG.md\` as needed before merging.
**Merging this PR will push tag \`${VERSION}\`, triggering the publish and docs workflows.**
---
PREOF
cat /tmp/changelog-entry.md >> /tmp/pr-body.md
gh pr create \
--title "chore: release ${VERSION}" \
--body-file /tmp/pr-body.md \
--base main \
--head "$BRANCH"