ci: fix user and added revert #2
Workflow file for this run
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
########################################################### | |
# Author: xZetsubou aka Bander # | |
# # | |
# Generate draft release of commits since latest version. # | |
########################################################### | |
name: Generate Draft Release | |
on: | |
push: | |
workflow_dispatch: | |
branches: | |
- master # Adjust this to the branch you want to track | |
- add_auto_draft_Release | |
permissions: | |
contents: write | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
release_commits: | | |
{"section": "breaking_changes", "prefix": "break", "header": "💥 Breaking Changes"} | |
{"section": "fixes", "prefix": "fix", "header": "🐛 Fixes" } | |
{"section": "feats", "prefix": "feat", "header": "✨ Feats" } | |
{"section": "improvements", "prefix": "perf", "header": "⚡ Improvements" } | |
{"section": "refactors", "prefix": "refactor", "header": "♻️ Refactors" } | |
{"section": "chores", "prefix": "chore", "header": "🧹 Chores" } | |
{"section": "docs", "prefix": "doc", "header": "📚 Docs" } | |
{"section": "revert", "prefix": "revert", "header": "🌀 Revert" } | |
{"section": "cis", "prefix": "ci", "header": "🛠️ CI" } | |
{"section": "tests", "prefix": "test", "header": "✅ Tests" } | |
{"section": "more", "prefix": "", "header": "➕ More" } | |
jobs: | |
generate-release-draft: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # Fetch all tags and history | |
- name: Get latest release tag | |
id: latest-release | |
run: | | |
latest_tag=$(curl --silent --fail \ | |
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
"https://api.github.com/repos/${{ github.repository }}/releases/latest" \ | |
| jq -r .tag_name) | |
echo "Latest release tag: $latest_tag" | |
echo "latest_tag=$latest_tag" >> $GITHUB_ENV | |
- name: Get commits from latest release to HEAD | |
run: | | |
git fetch --tags | |
git log ${{ env.latest_tag }}..HEAD --pretty=format:'%s by: @%ae in [`%h`](https://github.com/${{github.repository}}/commit/%H)' --reverse > commits.md | |
echo "" >> commits.md | |
while IFS= read -r line; do | |
commit_hash=$(echo $line | awk '{print $1}') | |
email=$(echo $line | awk -F"by: @" '{print (NF>1)? $NF : ""}'| awk '{print $1}') | |
if [[ "$email" =~ ([0-9]+)\+([a-zA-Z0-9_-]+)@ ]]; then | |
username="${BASH_REMATCH[2]}" | |
sed -i "s#$email#$username#g" "commits.md" | |
fi | |
done < commits.md | |
- name: Parse commit messages and categorize | |
id: parse_commits | |
run: | | |
declare -A commits_map; | |
while IFS= read -r line; do | |
first_lower=$(echo "$line" | awk '{print $1}' | tr '[:upper:]' '[:lower:]') | |
scope=$(echo "$line" | cut -d' ' -f1) | |
commit_desc=$(echo "$line" | cut -d' ' -f2-) | |
parsed_commit="- **$scope** $commit_desc\n" | |
added=false | |
while read -r item; do | |
section=$(echo "$item" | jq -r '.section') | |
prefix=$(echo "$item" | jq -r '.prefix') | |
echo "Looking for this prefix: $prefix and this lower $first_lower with section $section" | |
if [[ "$first_lower" == $prefix*: ]]; then | |
commits_map[$section]+=$parsed_commit && added=true && break | |
fi | |
done < <(echo '${{env.release_commits}}') | |
[[ $added == false ]] && commits_map["more"]+=$parsed_commit | |
done < commits.md | |
for key in "${!commits_map[@]}"; do | |
echo "$key=${commits_map[$key]}" >> $GITHUB_OUTPUT | |
done | |
- name: Create Release Notes | |
id: release-notes | |
run: | | |
notes="#### 🚨 **Note**: This draft has been released in $(date +'%Y.%m.%d - %H:%M:%S')\n\n" | |
while read -r item; do | |
section=$(echo "$item" | jq -r '.section') && [[ ! "$section" =~ [^[:space:]] ]] && continue | |
header=$(echo "$item" | jq -r '.header') | |
[[ ! "$section" =~ [^[:space:]] ]] && continue | |
section_commits=$(echo '${{ toJson(steps.parse_commits.outputs) }}' | jq -r ".$section") | |
if [ -n "$section_commits" ] && [ "$section_commits" != null ]; then | |
echo "ADDDDDDDDDDDED THIS" | |
echo "Section is $section HEADER IS: $header and Commits $section_commits" | |
notes+="### $header \n $section_commits \n" | |
fi | |
done < <(echo '${{env.release_commits}}') | |
echo "-------------------------------------------------" | |
echo -e $notes | |
echo "-------------------------------------------------" | |
echo -e $notes > commits.md | |
- name: Remove old Draft | |
id: remove_drafts | |
continue-on-error: true | |
run: | |
gh release delete "Draft Latest version" | |
- name: Create Release Draft | |
uses: softprops/action-gh-release@v1 | |
with: | |
name: "Draft Latest version" | |
tag_name: "Draft Latest version" | |
body_path: commits.md | |
draft: true |