You've already forked devops-pipeline-template
Add release notes generation workflow for Gitea
This commit is contained in:
@@ -0,0 +1,128 @@
|
|||||||
|
name: Release Notes Template
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
inputs:
|
||||||
|
previous_release:
|
||||||
|
description: 'Previous release tag'
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
current_release:
|
||||||
|
description: 'Current release tag'
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
gitea_url:
|
||||||
|
description: 'Gitea URL'
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
default: 'https://gitea.technarts.com'
|
||||||
|
repo_owner:
|
||||||
|
description: 'Repository owner'
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
repo_name:
|
||||||
|
description: 'Repository name'
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
update_release:
|
||||||
|
description: 'Update release description'
|
||||||
|
required: false
|
||||||
|
type: boolean
|
||||||
|
default: false
|
||||||
|
release_id:
|
||||||
|
description: 'Release ID to update'
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
default: ''
|
||||||
|
secrets:
|
||||||
|
gitea_token:
|
||||||
|
description: 'Gitea API token'
|
||||||
|
required: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
generate-and-update:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Generate and update release notes
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.gitea_token }}
|
||||||
|
GITEA_URL: ${{ inputs.gitea_url }}
|
||||||
|
REPO_OWNER: ${{ inputs.repo_owner }}
|
||||||
|
REPO_NAME: ${{ inputs.repo_name }}
|
||||||
|
PREVIOUS_RELEASE: ${{ inputs.previous_release }}
|
||||||
|
CURRENT_RELEASE: ${{ inputs.current_release }}
|
||||||
|
UPDATE_RELEASE: ${{ inputs.update_release }}
|
||||||
|
RELEASE_ID: ${{ inputs.release_id }}
|
||||||
|
run: |
|
||||||
|
echo "Generating release notes: $PREVIOUS_RELEASE -> $CURRENT_RELEASE"
|
||||||
|
echo "Repository: $REPO_OWNER/$REPO_NAME"
|
||||||
|
|
||||||
|
# Get releases
|
||||||
|
RELEASES=$(curl -s -H "Authorization: token $GITEA_TOKEN" \
|
||||||
|
"$GITEA_URL/api/v1/repos/$REPO_OWNER/$REPO_NAME/releases")
|
||||||
|
|
||||||
|
# Get release dates
|
||||||
|
PREVIOUS_DATE=$(echo "$RELEASES" | jq -r --arg tag "$PREVIOUS_RELEASE" \
|
||||||
|
'.[] | select(.tag_name == $tag) | .created_at')
|
||||||
|
|
||||||
|
CURRENT_DATE=$(echo "$RELEASES" | jq -r --arg tag "$CURRENT_RELEASE" \
|
||||||
|
'.[] | select(.tag_name == $tag) | .created_at')
|
||||||
|
|
||||||
|
if [ -z "$PREVIOUS_DATE" ] || [ "$PREVIOUS_DATE" = "null" ]; then
|
||||||
|
echo "ERROR: Release not found: $PREVIOUS_RELEASE"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$CURRENT_DATE" ] || [ "$CURRENT_DATE" = "null" ]; then
|
||||||
|
echo "ERROR: Release not found: $CURRENT_RELEASE"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Date range: $PREVIOUS_DATE to $CURRENT_DATE"
|
||||||
|
|
||||||
|
# Get merged PRs
|
||||||
|
PRS=$(curl -s -H "Authorization: token $GITEA_TOKEN" \
|
||||||
|
"$GITEA_URL/api/v1/repos/$REPO_OWNER/$REPO_NAME/pulls?state=closed&limit=200")
|
||||||
|
|
||||||
|
# Build release notes
|
||||||
|
NOTES_HEADER="# Release Notes: $CURRENT_RELEASE"$'\n\n'"## Changes"$'\n\n'
|
||||||
|
|
||||||
|
# Filter and format PRs
|
||||||
|
PR_LIST=$(echo "$PRS" | jq -r --arg prev_date "$PREVIOUS_DATE" --arg curr_date "$CURRENT_DATE" '
|
||||||
|
[.[] | select(.merged == true and .merged_at > $prev_date and .merged_at <= $curr_date)] |
|
||||||
|
sort_by(.merged_at) |
|
||||||
|
reverse |
|
||||||
|
.[] |
|
||||||
|
"* **\(.title)** ([#\(.number)](\(.html_url)))\n Author: @\(.user.username)\n Merged: \(.merged_at | split("T")[0])\n"
|
||||||
|
')
|
||||||
|
|
||||||
|
# Count PRs
|
||||||
|
PR_COUNT=$(echo "$PRS" | jq --arg prev_date "$PREVIOUS_DATE" --arg curr_date "$CURRENT_DATE" \
|
||||||
|
'[.[] | select(.merged == true and .merged_at > $prev_date and .merged_at <= $curr_date)] | length')
|
||||||
|
|
||||||
|
NOTES_FOOTER=$'\n\n'"---"$'\n\n'"**Total changes:** $PR_COUNT pull requests merged"
|
||||||
|
|
||||||
|
FULL_NOTES="${NOTES_HEADER}${PR_LIST}${NOTES_FOOTER}"
|
||||||
|
|
||||||
|
echo "Release notes generated: $PR_COUNT PRs found"
|
||||||
|
echo "======================================"
|
||||||
|
echo "$FULL_NOTES"
|
||||||
|
echo "======================================"
|
||||||
|
|
||||||
|
# Update release if requested
|
||||||
|
if [ "$UPDATE_RELEASE" = "true" ] && [ -n "$RELEASE_ID" ]; then
|
||||||
|
echo "Updating release description..."
|
||||||
|
|
||||||
|
NOTES_JSON=$(echo "$FULL_NOTES" | jq -Rs .)
|
||||||
|
|
||||||
|
curl -X PATCH \
|
||||||
|
-H "Authorization: token $GITEA_TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
"$GITEA_URL/api/v1/repos/$REPO_OWNER/$REPO_NAME/releases/$RELEASE_ID" \
|
||||||
|
-d "{\"body\":$NOTES_JSON}"
|
||||||
|
|
||||||
|
echo "Release description updated successfully!"
|
||||||
|
else
|
||||||
|
echo "Skipping release update"
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user