Skip to content

create-release

create-release #23

name: create-release
on:
workflow_dispatch: {}
permissions: {}
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
env:
CI: true
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0
fetch-tags: true
- name: Setup Node
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
with:
node-version: 'lts/*'
- name: Install mise
uses: jdx/mise-action@5228313ee0372e111a38da051671ca30fc5a96db # v3
with:
experimental: true
- name: Install dependencies
run: mise run install
- name: Set git identity
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Create version and tag
id: version
run: |
# Run commit-and-tag-version to bump version, update changelog, and create tag
npx commit-and-tag-version
# Get the new version tag
NEW_TAG=$(git describe --tags --abbrev=0)
echo "new_tag=$NEW_TAG" >> $GITHUB_OUTPUT
# Extract changelog for this version
# This extracts content between the first two version headers
CHANGELOG_CONTENT=$(awk '/^## \[/{if(++count==2) exit; if(count==1) next} count==1' CHANGELOG.md)
# Save changelog to file for multiline handling
echo "$CHANGELOG_CONTENT" > /tmp/release_notes.md
echo "Prepared release $NEW_TAG"
- name: Create release branch and PR
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Create and push release branch (local tag not pushed)
BRANCH_NAME="release/${{ steps.version.outputs.new_tag }}"
# Delete existing branch if it exists
git push origin --delete "$BRANCH_NAME" 2>/dev/null || true
git branch -D "$BRANCH_NAME" 2>/dev/null || true
git checkout -b "$BRANCH_NAME"
git push origin "$BRANCH_NAME"
# Create pull request with tag info in body
echo "## Release ${{ steps.version.outputs.new_tag }}" > /tmp/pr_body.md
echo "" >> /tmp/pr_body.md
echo "This PR will create tag \`${{ steps.version.outputs.new_tag }}\` when merged." >> /tmp/pr_body.md
echo "" >> /tmp/pr_body.md
cat /tmp/release_notes.md >> /tmp/pr_body.md
# Close existing PR if it exists, then create new one
gh pr close "release/${{ steps.version.outputs.new_tag }}" 2>/dev/null || true
gh pr create \
--title "Release ${{ steps.version.outputs.new_tag }}" \
--body-file /tmp/pr_body.md \
--base main \
--head "$BRANCH_NAME"