Skip to content

Commit 983b2cd

Browse files
Update update-changelog.yml (#20)
changed : Update update-changelog.yml
1 parent df281da commit 983b2cd

File tree

1 file changed

+42
-9
lines changed

1 file changed

+42
-9
lines changed

.github/workflows/update-changelog.yml

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
name: Update Changelog
1+
name: Update Changelog on Release
22

33
on:
4-
workflow_dispatch: # tu peux aussi ajouter "schedule" ou "push"
4+
release:
5+
types: [published]
56

67
jobs:
78
update-changelog:
@@ -11,25 +12,57 @@ jobs:
1112
pull-requests: write
1213

1314
steps:
14-
- uses: actions/checkout@v4
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0 # ⚠️ nécessaire pour récupérer tous les tags
19+
20+
- name: Get previous tag
21+
id: previoustag
22+
run: |
23+
previous_tag=$(git describe --tags --abbrev=0 "${GITHUB_SHA}^" || echo "")
24+
echo "previous_tag=$previous_tag" >> $GITHUB_OUTPUT
25+
26+
- name: Generate changelog section
27+
id: changelog
28+
run: |
29+
new_tag="${{ github.event.release.tag_name }}"
30+
prev_tag="${{ steps.previoustag.outputs.previous_tag }}"
31+
32+
echo "## $new_tag ($(date +'%Y-%m-%d'))" > new_changes.md
1533
16-
- name: Auto-commit CHANGELOG.md
34+
if [ -n "$prev_tag" ]; then
35+
echo "" >> new_changes.md
36+
git log $prev_tag..HEAD --pretty=format:"- %s (%h)" >> new_changes.md
37+
else
38+
echo "" >> new_changes.md
39+
git log --pretty=format:"- %s (%h)" >> new_changes.md
40+
fi
41+
42+
echo "" >> new_changes.md
43+
echo "---" >> new_changes.md
44+
45+
- name: Update CHANGELOG.md
46+
run: |
47+
cat new_changes.md CHANGELOG.md > tmp.md
48+
mv tmp.md CHANGELOG.md
49+
50+
- name: Commit changes
1751
uses: stefanzweifel/git-auto-commit-action@v5
1852
with:
1953
file_pattern: CHANGELOG.md
20-
commit_message: "Update CHANGELOG"
21-
branch: changelog-update # 👉 branche temporaire pour les changements
54+
commit_message: "chore: update CHANGELOG for release ${{ github.event.release.tag_name }}"
55+
branch: changelog-update
2256

2357
- name: Create Pull Request
2458
id: cpr
2559
uses: peter-evans/create-pull-request@v7
2660
with:
2761
branch: changelog-update
2862
base: main
29-
title: "Update CHANGELOG"
30-
body: "This PR updates the CHANGELOG automatically."
63+
title: "chore: update CHANGELOG for release ${{ github.event.release.tag_name }}"
64+
body: "This PR updates the CHANGELOG with commits since the previous release."
3165
labels: automated-pr
32-
draft: false
3366

3467
- name: Auto-merge Pull Request
3568
if: steps.cpr.outputs.pull-request-url != ''

0 commit comments

Comments
 (0)