From 79ce777489b7808027c4e88df01dd0dbe3572d72 Mon Sep 17 00:00:00 2001 From: Guillaume Chervet Date: Sun, 14 Apr 2024 15:16:32 +0200 Subject: [PATCH] doc(changelog): add auto changelog (release) --- .github/workflows/npm-publish.yml | 24 ++++++++------ bin/generate-changelog.sh | 54 +++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 9 deletions(-) create mode 100644 bin/generate-changelog.sh diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 18683d2..031a913 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -115,7 +115,7 @@ jobs: mkdir opencv_build cd opencv_build # https://docs.opencv.org/3.4/d4/da1/tutorial_js_setup.html - git clone https://github.com/opencv/opencv.git + git clone -b 4.x https://github.com/opencv/opencv.git --depth 1 cd opencv sed -i "s/white_list = makeWhiteList(\[core, imgproc, objdetect, video, dnn, features2d, photo, calib3d\])/white_list = makeWhiteList([core, imgproc, features2d, calib3d])/g" ./platforms/js/opencv_js.config.py docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk:2.0.10 emcmake python3 ./platforms/js/build_js.py build_js @@ -141,15 +141,21 @@ jobs: # git push --force --tags --follow-tags # # - - name: Commit Release ${{ steps.tag_release.outputs.new_version }} - uses: stefanzweifel/git-auto-commit-action@v4 + - name: Commit and push if: github.ref == 'refs/heads/main' && steps.which_tag.outputs.tag == 'release' - with: - commit_message: "[skip ci] Release v${{ steps.tag_release.outputs.new_version }}" - commit_user_name: GitHub - commit_user_email: github-action@bot.com - commit_author: GitHub - push_options: '--force' + run: | + git config --global user.name "GitHub" + git config --global user.email "github-action@bot.com" + git add . + git commit -m "[skip ci] Update to version ${{ steps.tag.outputs.new_version }} in package.json" + git tag ${{ steps.tag.outputs.new_version }} + git push --set-upstream origin "HEAD:main" --follow-tags -f + + chmod +x ./bin/generate-changelog.sh + ./bin/generate-changelog.sh + git add . + git commit -m "[skip ci] Generate changelog to version ${{ steps.tag.outputs.new_version }}" + git push --set-upstream origin "HEAD:main" --follow-tags -f - id: publish-slight-capture uses: JS-DevTools/npm-publish@v1 diff --git a/bin/generate-changelog.sh b/bin/generate-changelog.sh new file mode 100644 index 0000000..c921e2a --- /dev/null +++ b/bin/generate-changelog.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +num_tags=60 +excluded_author="GitHub" +project_url="https://github.com/AxaFrance/slight-capture/commit" + +# Get all tag names in reverse order +tags=(`git tag -l --sort=-creatordate | head -$num_tags`) + +# File to save the log +outfile=CHANGELOG.md + +# Write the header +echo "# Changelog" > $outfile +echo "" >> $outfile + +# Iterate over tags array +for((i=0; i<${#tags[@]}-1; i++)) +do +# current tag +current=${tags[$i]} +# previous tag +previous=${tags[$i+1]} + +# Write header for current tag +echo "## $current" >> $outfile +echo "## $current" +echo "" >> $outfile + +# Get commit hashes: between current and previous tag +hashes=(`git log --pretty=format:"%H" $previous..$current`) + +# Output commit log for each hash +for hash in ${hashes[@]} +do + # Check the author of the commit + author=$(git log -1 --pretty=format:"%an" $hash) + + # Exclude commits from the specified author + if [ "$author" != "$excluded_author" ]; then + # Get commit log in the desired format. + # You can modify the 'format' as per your need. Please refer 'PRETTY FORMATS' section of git-log man page + log=$(git log -1 --pretty=format:"[%h]($project_url/%H) - %s, %ad by *%an*" --date=short $hash) + + # Write formatted log to CHANGELOG.md file + echo "- $log" >> $outfile + echo "- $log" + fi +done + +# Space between two tags +echo "" >> $outfile +echo "" >> $outfile +done \ No newline at end of file