name: github_release
on:
push:
tags:
- '*'
workflow_dispatch:
permissions:
contents: write
jobs:
github-release:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: checkout
uses: actions/checkout@v6
- name: skip release creation in act
if: ${{ env.ACT == 'true' }}
run: |
printf 'Skipping GitHub release creation in act for ref %s\n' "${GITHUB_REF_NAME:-workflow-dispatch}"
- name: generate release notes
id: notes
if: ${{ env.ACT != 'true' }}
env:
GH_TOKEN: ${{ github.token }}
REPOSITORY: ${{ github.repository }}
TAG_NAME: ${{ github.ref_name }}
TARGET_SHA: ${{ github.sha }}
run: |
notes_file="$RUNNER_TEMP/release-notes.md"
gh api \
--method POST \
"repos/$REPOSITORY/releases/generate-notes" \
-f tag_name="$TAG_NAME" \
-f target_commitish="$TARGET_SHA" \
--jq '.body' > "$notes_file"
printf 'notes-file=%s\n' "$notes_file" >> "$GITHUB_OUTPUT"
- name: create or update github release
if: ${{ env.ACT != 'true' }}
env:
GH_TOKEN: ${{ github.token }}
TAG_NAME: ${{ github.ref_name }}
NOTES_FILE: ${{ steps.notes.outputs.notes-file }}
run: |
if gh release view "$TAG_NAME" >/dev/null 2>&1; then
gh release edit "$TAG_NAME" --title "$TAG_NAME" --notes-file "$NOTES_FILE"
else
gh release create "$TAG_NAME" --verify-tag --title "$TAG_NAME" --notes-file "$NOTES_FILE"
fi