Files
winnow/.github/workflows/release.yml
T

83 lines
2.5 KiB
YAML

name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
version:
description: "Version to release (e.g. 0.1.0)"
required: true
default: "0.1.0"
permissions:
contents: write
jobs:
release:
name: Create GitHub Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Resolve tag name
id: tag
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "TAG=v${{ github.event.inputs.version }}" >> "$GITHUB_OUTPUT"
echo "VERSION=${{ github.event.inputs.version }}" >> "$GITHUB_OUTPUT"
else
TAG="${GITHUB_REF_NAME}"
echo "TAG=${TAG}" >> "$GITHUB_OUTPUT"
echo "VERSION=${TAG#v}" >> "$GITHUB_OUTPUT"
fi
- name: Create and push tag (workflow_dispatch only)
if: github.event_name == 'workflow_dispatch'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
TAG="${{ steps.tag.outputs.TAG }}"
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Tag $TAG already exists, skipping creation."
else
git tag "$TAG"
git push origin "$TAG"
fi
- name: Extract changelog for this version
id: changelog
run: |
VERSION="${{ steps.tag.outputs.VERSION }}"
# Extract the section for this version from CHANGELOG.md
NOTES=$(awk "/^## \[$VERSION\]/{found=1; next} found && /^## \[/{exit} found{print}" CHANGELOG.md)
# Use a delimiter to safely pass multiline output
{
echo "NOTES<<CHANGELOG_EOF"
echo "$NOTES"
echo "CHANGELOG_EOF"
} >> "$GITHUB_OUTPUT"
- name: Create GitHub Release
uses: actions/github-script@v7
env:
RELEASE_TAG: ${{ steps.tag.outputs.TAG }}
RELEASE_NOTES: ${{ steps.changelog.outputs.NOTES }}
with:
script: |
const tag = process.env.RELEASE_TAG;
const notes = (process.env.RELEASE_NOTES || '').trim();
await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: tag,
name: `Release ${tag}`,
body: notes || `Release ${tag}`,
draft: false,
prerelease: false,
});