Repository navigation
113 lines (96 loc) · 3.47 KB
/
Copy pathrelease-summary.yml
File metadata and controls
113 lines (96 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
name: release-summary
on:
workflow_run:
workflows: ["release-on-merge"]
types: [completed]
workflow_dispatch:
inputs:
tag_name:
description: "Release tag to summarize (optional, defaults to latest release)"
required: false
type: string
permissions:
contents: write
concurrency:
group: release-summary-${{ github.event.workflow_run.id || github.run_id }}
cancel-in-progress: false
jobs:
update-release-summary:
if: >
github.event_name == 'workflow_dispatch' ||
(
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_branch == 'main'
)
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Ensure Python is available
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Fetch tags
run: git fetch --tags --force
- name: Resolve release tag
id: resolve_tag
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
TAG="${{ inputs.tag_name }}"
if [[ -z "${TAG}" && "${{ github.event_name }}" == "workflow_run" ]]; then
SHA="${{ github.event.workflow_run.head_sha }}"
TAG="$(git tag --points-at "${SHA}" | sort -V | tail -n 1 || true)"
fi
if [[ -z "${TAG}" ]]; then
TAG="$(gh release list --limit 1 --json tagName -q '.[0].tagName')"
fi
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "Resolved release tag: ${TAG}"
- name: Build release context
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
python3 .github/scripts/collect_release_context.py \
"${{ github.repository }}" \
--repo-path . \
--latest-tag "${{ steps.resolve_tag.outputs.tag }}" \
--output /tmp/release-context.json
- name: Generate bilingual summary
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_MODEL: ${{ vars.OPENAI_MODEL }}
run: |
python3 .github/scripts/generate_bilingual_release_summary.py \
--input /tmp/release-context.json \
--output /tmp/release-summary.md
- name: Merge summary into release body
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
TAG="${{ steps.resolve_tag.outputs.tag }}"
OLD_BODY="$(gh release view "$TAG" --json body -q .body)"
export OLD_BODY
python3 - <<'PY'
from pathlib import Path
import os
start = "<!-- kospellcheck-release-summary-base:start -->"
end = "<!-- kospellcheck-release-summary-base:end -->"
old = os.environ.get("OLD_BODY", "")
summary = Path("/tmp/release-summary.md").read_text(encoding="utf-8").strip()
block = f"{start}\n\n{summary}\n\n{end}"
s = old.find(start)
e = old.find(end)
if s != -1 and e != -1 and e >= s:
e += len(end)
merged = (old[:s].rstrip() + "\n\n" + block).strip() + "\n"
else:
merged = (old.rstrip() + "\n\n---\n\n" + block).strip() + "\n"
Path('/tmp/new-release-body.md').write_text(merged, encoding='utf-8')
PY
gh release edit "$TAG" --notes-file /tmp/new-release-body.md