Skip to content

Generate Release Notes #12

Generate Release Notes

Generate Release Notes #12

name: Generate Release Notes
on:
release:
types: [published, prereleased, released, created]
workflow_dispatch:
permissions:
contents: write
jobs:
generate-release-notes:
name: Generate AI-powered release notes
runs-on: ubuntu-latest
timeout-minutes: 10
env:
PIP_DISABLE_PIP_VERSION_CHECK: '1'
PIP_NO_PYTHON_VERSION_WARNING: '1'
PIP_PROGRESS_BAR: 'off'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install openai
- name: Determine tag
id: tag
shell: bash
run: |
set -euo pipefail
if [[ "${{ github.event_name }}" == "release" ]]; then
TAG_NAME="${{ github.event.release.tag_name }}"
else
# workflow_dispatch - use most recent tag by creation date
TAG_NAME="$(git tag --sort=-creatordate | head -n 1 || true)"
fi
if [[ -z "${TAG_NAME}" ]]; then
echo "No tag found/provided. Exiting."
exit 1
fi
echo "tag_name=${TAG_NAME}" >> "$GITHUB_OUTPUT"
echo "Will generate notes for tag: ${TAG_NAME}"
- name: Generate release notes (OpenAI)
id: generate
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
set -euo pipefail
python .github/scripts/generate_release_notes.py "${{ steps.tag.outputs.tag_name }}" --output /tmp/release_notes.md
echo "notes_path=/tmp/release_notes.md" >> "$GITHUB_OUTPUT"
- name: Update release with generated notes (gh)
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
TAG="${{ steps.tag.outputs.tag_name }}"
NOTES_FILE="${{ steps.generate.outputs.notes_path }}"
# If run from 'release' event, the release exists. If run manually, ensure there is a release.
# We simply edit the release for the tag (must exist). You can also create if missing.
gh release edit "${TAG}" --repo "${{ github.repository }}" --notes-file "${NOTES_FILE}"
- name: Upload release notes as artifact
uses: actions/upload-artifact@v4
with:
name: release-notes-${{ steps.tag.outputs.tag_name }}
path: /tmp/release_notes.md
retention-days: 30