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:
parent
3a61387215
commit
4e2bfbee02
2 changed files with 48 additions and 25 deletions
|
|
@ -6,7 +6,7 @@ name: Release
|
||||||
- "**"
|
- "**"
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: write
|
||||||
releases: write
|
releases: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
@ -19,38 +19,59 @@ jobs:
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Build changelog
|
- name: Extract changelog and update CHANGELOG.md
|
||||||
id: changelog
|
id: changelog
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
current_tag="${GITHUB_REF_NAME}"
|
current_tag="${GITHUB_REF_NAME}"
|
||||||
previous_stable_tag=""
|
today=$(date +%Y-%m-%d)
|
||||||
|
|
||||||
if previous_stable_tag="$(
|
# Extract content of [Unreleased] section (non-empty lines)
|
||||||
git describe --tags --abbrev=0 \
|
release_notes=$(awk '/^## \[Unreleased\]/{found=1; next} found && /^## \[/{exit} found{print}' CHANGELOG.md | sed '/^[[:space:]]*$/d')
|
||||||
--exclude '*-rc*' \
|
|
||||||
--exclude '*-beta*' \
|
if [ -z "${release_notes}" ]; then
|
||||||
--exclude '*-alpha*' \
|
release_notes="Voir les commits pour le détail des changements."
|
||||||
"${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
|
|
||||||
fi
|
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
|
- name: Create or update release
|
||||||
env:
|
env:
|
||||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
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'
|
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}' \
|
payload="$(printf '{"tag_name":"%s","name":"%s","body":"%s","draft":false,"prerelease":%s}' \
|
||||||
"${current_tag}" \
|
"${current_tag}" \
|
||||||
"${current_tag}" \
|
"${current_tag}" \
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
## [v1.11.0] — 2026-05-12
|
## [v1.11.0] — 2026-05-12
|
||||||
|
|
||||||
### Nouvelles fonctionnalités
|
### Nouvelles fonctionnalités
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue