ci(release): alimenter les notes de release depuis [Unreleased] dans CHANGELOG.md

À chaque tag stable, la CI extrait la section [Unreleased], l'utilise
comme notes de release Forgejo, renomme la section avec la version et
la date, puis commite le CHANGELOG.md mis à jour sur main.

Les tags RC utilisent le contenu [Unreleased] pour les notes mais ne
modifient pas le fichier.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
thibaud-lclr 2026-05-13 11:15:21 +02:00
parent 3a61387215
commit 4e2bfbee02
2 changed files with 48 additions and 25 deletions

View file

@ -6,7 +6,7 @@ name: Release
- "**"
permissions:
contents: read
contents: write
releases: write
jobs:
@ -19,38 +19,59 @@ jobs:
with:
fetch-depth: 0
- name: Build changelog
- name: Extract changelog and update CHANGELOG.md
id: changelog
env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
shell: bash
run: |
set -euo pipefail
current_tag="${GITHUB_REF_NAME}"
previous_stable_tag=""
today=$(date +%Y-%m-%d)
if previous_stable_tag="$(
git describe --tags --abbrev=0 \
--exclude '*-rc*' \
--exclude '*-beta*' \
--exclude '*-alpha*' \
"${current_tag}^" 2>/dev/null
)"; then
range="${previous_stable_tag}..${current_tag}"
{
printf '## Changelog\n\n'
printf 'Changes since `%s`.\n\n' "${previous_stable_tag}"
git log --reverse --pretty=format:'- %h %s' "${range}"
printf '\n'
} >CHANGELOG.md
else
{
printf '## Changelog\n\n'
printf 'Initial release.\n\n'
git log --reverse --pretty=format:'- %h %s' "${current_tag}"
printf '\n'
} >CHANGELOG.md
# Extract content of [Unreleased] section (non-empty lines)
release_notes=$(awk '/^## \[Unreleased\]/{found=1; next} found && /^## \[/{exit} found{print}' CHANGELOG.md | sed '/^[[:space:]]*$/d')
if [ -z "${release_notes}" ]; then
release_notes="Voir les commits pour le détail des changements."
fi
printf '%s\n' "${release_notes}" > release_notes.md
# For stable releases: rename [Unreleased] and insert a new empty section
case "${current_tag}" in
*-rc*|*-beta*|*-alpha*)
echo "Pre-release tag — CHANGELOG.md non modifié"
;;
*)
cat > /tmp/update_changelog.py << 'PYEOF'
import os
version = os.environ['VERSION']
today = os.environ['TODAY']
with open('CHANGELOG.md', 'r') as f:
content = f.read()
content = content.replace('## [Unreleased]', f'## [{version}] — {today}', 1)
content = content.replace('# Changelog\n', '# Changelog\n\n## [Unreleased]\n', 1)
with open('CHANGELOG.md', 'w') as f:
f.write(content)
PYEOF
VERSION="${current_tag}" TODAY="${today}" python3 /tmp/update_changelog.py
git config user.name "CI"
git config user.email "ci@forge.lclr.dev"
git remote set-url origin "https://x-token:${GITEA_TOKEN}@${GITHUB_SERVER_URL#https://}/${GITHUB_REPOSITORY}.git"
git add CHANGELOG.md
git commit -m "chore(changelog): release ${current_tag}"
git push origin HEAD:main
;;
esac
- name: Create or update release
env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
@ -73,7 +94,7 @@ jobs:
sed ':a;N;$!ba;s/\\/\\\\/g;s/"/\\"/g;s/\t/\\t/g;s/\r//g;s/\n/\\n/g'
}
body="$(json_escape < CHANGELOG.md)"
body="$(json_escape < release_notes.md)"
payload="$(printf '{"tag_name":"%s","name":"%s","body":"%s","draft":false,"prerelease":%s}' \
"${current_tag}" \
"${current_tag}" \

View file

@ -1,5 +1,7 @@
# Changelog
## [Unreleased]
## [v1.11.0] — 2026-05-12
### Nouvelles fonctionnalités