Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
skamril committed Mar 5, 2024
1 parent b40269b commit a3387d2
Showing 1 changed file with 30 additions and 51 deletions.
81 changes: 30 additions & 51 deletions .github/workflows/release-changelog.yml
Original file line number Diff line number Diff line change
@@ -1,64 +1,43 @@
name: Release PR Changelog
name: Release changelog

on:
pull_request:
branches:
- master
types: [opened, synchronize, reopened]
types: [ opened, synchronize, reopened ]

jobs:
changelog-comment:
release-changelog:
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)
steps:
- name: Checkout repository
uses: actions/checkout@v2

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
- name: Install dependencies
run: npm install -g conventional-changelog-cli

echo "::set-output name=features::${features}"
echo "::set-output name=bug_fixes::${bug_fixes}"
- name: Generate Changelog
id: changelog
run: echo "::set-output name=changelog::$(conventional-changelog -s)"

- 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: Get PR Number
run: echo "::set-output name=pr_number::${{ github.event.pull_request.number }}"

- name: Comment on PR
run: |
curl -X POST -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.number }}/comments \
-d "{\"body\": \"## Changelog\n${{ steps.comment_on_pr.outputs.changelog }}\"}"
- name: Update PR comment
uses: actions/github-script@v4
with:
script: |
const fs = require('fs');
const prNumber = process.env.PR_NUMBER;
const changelog = fs.readFileSync('changelog.txt', 'utf8'); // assuming changelog output is stored in a file
const octokit = github.getOctokit(process.env.GITHUB_TOKEN);
octokit.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: `Changelog has been updated. You can review it [here](https://github.com/${{ github.repository }}/blob/master/CHANGELOG.md).\n\nChangelog:\n${changelog}`
});
env:
PR_NUMBER: ${{ steps.pr_number.outputs.pr_number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit a3387d2

Please sign in to comment.