-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add 'Release PR Changelog' GitHub action
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
name: Release PR Changelog | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
types: [opened, synchronize, reopened] | ||
|
||
jobs: | ||
changelog-comment: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 # Important pour s'assurer que tous les commits sont récupérés | ||
|
||
- name: Generate changelog | ||
id: generate_changelog | ||
run: | | ||
# Script pour générer le changelog à partir des commits | ||
features="" | ||
bug_fixes="" | ||
git log origin/master.. --oneline --no-merges | while read -r line ; do | ||
commit_message=$(echo "$line" | cut -d ' ' -f 2-) | ||
commit_type=$(echo "$commit_message" | cut -d '(' -f 1 | cut -d ':' -f 1) | ||
commit_scope=$(echo "$commit_message" | grep -o '(\K[^)]+' | cut -d ':' -f 1) | ||
case $commit_type in | ||
"feat") | ||
feature_desc=$(echo "$commit_message" | cut -d ':' -f 2-) | ||
feature_link=$(echo "$commit_message" | grep -o '#[0-9]\+' | sed 's/#//') | ||
features="$features* **[$commit_scope]** $feature_desc [#$feature_link]\n" | ||
;; | ||
"fix") | ||
fix_desc=$(echo "$commit_message" | cut -d ':' -f 2-) | ||
fix_link=$(echo "$commit_message" | grep -o '#[0-9]\+' | sed 's/#//') | ||
bug_fixes="$bug_fixes* **[$commit_scope]** $fix_desc [#$fix_link]\n" | ||
;; | ||
*) | ||
# Ignore other commit types | ||
;; | ||
esac | ||
done | ||
echo "::set-output name=features::${features}" | ||
echo "::set-output name=bug_fixes::${bug_fixes}" | ||
- name: Format and Comment on PR | ||
id: comment_on_pr | ||
run: | | ||
changelog="$(echo "${FEATURES}" | sed '/^$/d')\n\n$(echo "${BUG_FIXES}" | sed '/^$/d')" | ||
echo "::set-output name=changelog::$changelog" | ||
env: | ||
FEATURES: ${{ steps.generate_changelog.outputs.features }} | ||
BUG_FIXES: ${{ steps.generate_changelog.outputs.bug_fixes }} | ||
|
||
- name: Comment on PR | ||
uses: marvinpinto/github-comment@v1 | ||
with: | ||
comment: | | ||
## Changelog | ||
${{ steps.comment_on_pr.outputs.changelog }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |