Skip to content

Commit

Permalink
Rewrite Bash Script found in a step of 'Update changelog.md on Releas…
Browse files Browse the repository at this point in the history
…e' GitHub Workflow
  • Loading branch information
og-mrk committed Jul 19, 2024
1 parent 7112c78 commit 0948451
Showing 1 changed file with 80 additions and 12 deletions.
92 changes: 80 additions & 12 deletions .github/workflows/createchangelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,89 @@ jobs:

- name: Get all releases and update changelog.md file
run: |
# Fetch all releases including pre-releases using GitHub CLI
gh release list --exclude-drafts --exclude-pre-releases --limit 1000000 > releases.txt
# Extract numeric versions and create changelog.md content
echo "" > docs/changelog.md
# Initialize some values
changelog_path="docs/changelog.md"
gh release list --exclude-drafts --json tagName,name,isLatest,isPrerelease --limit 1000000 > releases.txt
declare -rA number_of_releases=$(cat releases.txt | grep -Po '"tagName"' | wc --lines)
# Clear the contents of 'docs/changelog.md' file
echo "" > $changelog_path
# Make array for git tag names
tag_arr=()
cat releases.txt | grep -Po '"tagName":.*?[^\\]"' | awk -F ':' '{print $2}' | sed s/\"//g > tags_list.txt
while read -r line; do
tag_arr+=("$line")
done < tags_list.txt
# Make array for releases names
name_arr=()
cat releases.txt | grep -Po '"name":.*?[^\\]"' | awk -F ':' '{print $2}' | sed s/\"//g > releases_names_list.txt
while read -r line; do
name_arr+=("$line")
done < releases_names_list.txt
# Make array for isPrerelease
isprerelease_arr=()
cat releases.txt | grep -Po '"isPrerelease":.*?[^\\]"' | awk -F ':' '{print $2}' | sed s/\"//g | sed s/,//g > isprerelease_list.txt
while read -r line; do
isprerelease_arr+=("$line")
done < isprerelease_list.txt
# Make array for isLatest
islatest_arr=()
cat releases.txt | grep -Po '"isLatest":.*?[^\\]"' | awk -F ':' '{print $2}' | sed s/\"//g | sed s/,//g > islatest_list.txt
while read -r line; do
tag=$(echo "$line" | awk '{print $1}')
name=$(echo "$line" | awk -F'\t' '{print $2}')
islatest_arr+=("$line")
done < islatest_list.txt
# Debug Output
echo "Tag Array: " ${tag_arr[@]}
echo "Array Length: " ${#tag_arr[@]}
echo ""
echo "Release Name Array: " ${name_arr[@]}
echo "Array Length: " ${#name_arr[@]}
echo ""
echo "IsPrerelease Array: " ${isprerelease_arr[@]}
echo "Array Length: " ${#isprerelease_arr[@]}
echo ""
echo "IsLatest Array: " ${islatest_arr[@]}
echo "Array Length: " ${#islatest_arr[@]}
echo ""
# Exit when this impossible condition is met (just to be safe)
if [[ ! (${#tag_arr[@]}==${#name_arr[@]} && ${#tag_arr[@]}==${#isprerelease_arr[@]} && ${#tag_arr[@]}==${#islatest_arr[@]} ) ]] ; then
echo "Impossible Condition has been met, the Name Array Length Does Not match Tag Array Length, exiting..."
exit 1
fi
# Main loop that does the heavy lifting (Content Generation)
for (( i=0; i<${number_of_releases}; i++ ));
do
# The Variables to use on each iteration
tag=${tag_arr[$i]}
name=${name_arr[$i]}
isprerelease=${isprerelease_arr[$i]}
islatest=${islatest_arr[$i]}
version_numeric=$(echo "$tag" | grep -o -E '[0-9.]+')
body=$(gh release view "$tag" --json body --jq .body)
echo "## $version_numeric" >> docs/changelog.md
echo "Release name: $name" >> docs/changelog.md
echo "Release body: $body" >> docs/changelog.md
echo "" >> docs/changelog.md
done < releases.txt
# The generation of changelog file contents
echo "# Changelog" >> $changelog_path
echo "" >> $changelog_path
echo "WinUtil change log received from GitHub Releases, it's autogenerated using GitHub Actions." >> $changelog_path
echo "" >> $changelog_path
echo "> [!WARNING]" >> $changelog_path
echo "> This file **SHOULD NOT** be edited directly, any PRs that tries changing it directly will either be requested on not changing it, or it'll get rejected." >> $changelog_path
echo "" >> $changelog_path
echo "# $version_numeric" >> $changelog_path
echo "Release name: $name" >> $changelog_path
echo "Release body: $body" >> $changelog_path
echo "" >> $changelog_path
done
env:
GH_TOKEN: ${{ github.token }}

Expand Down

0 comments on commit 0948451

Please sign in to comment.