Skip to content

Commit

Permalink
Workflow update/fix createchangelog not running (#26)
Browse files Browse the repository at this point in the history
* Make workflows re-usable

* Rename File Extensions for some workflow files

* Change job ordering

* Try something else to force specific job ordering

* Another Try something else to force specific job ordering

* Add comments & rename some jobs

* Make 'github-pages' workflow file get latest commits from action's current branch

Current branch means the running git branch that the GitHub Action was
ran at.

* Add reference to 'Checkout Repo' step

* Fix Admonition in Changelog Workflow

* Remove un-used 'release.yaml' workflow

* Add 'release' event to 'github-pages' workflow

* Fix Admonition in Changelog Workflow

* Make 'actions/checkout' fetch latest of anything, git submodules, tags, and commits

* Fix yaml syntax error

* Handle special case in 'createchangelog.yaml' workflow

* Update workflows

* Fix issue with 'createchangelog' workflow always switching to Git Detached Head Mode

* Reorder 'env' field in 'createchangelog' workflow

* Fix 'close-discussion' workflow not working

* Add debug info to 'close-discussion' workflow

* Bring back control to the 'Extract Discussion Number & Close If any Where Found' step in 'close-discussion' workflow
  • Loading branch information
og-mrk authored Jul 29, 2024
1 parent 313c5f5 commit 5eb4e1f
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 184 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ jobs:
run: echo "PR was merged"

- name: Extract Discussion Number & Close If any Where Found
# Make the running bash script behave like it would when ran locally
# by default GitHub actions has 'set -e', which'll make the whole step fail
# upon small things, like grep not finding any matches.. which sometimes
# we do want this behavior, so we set shell to be 'bash {0}' to bring back control.
# reference: https://stackoverflow.com/questions/73066461/github-actions-why-an-intermediate-command-failure-in-shell-script-would-cause
shell: bash {0}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: github.event.pull_request.merged == true
Expand All @@ -27,12 +33,16 @@ jobs:
done < discussion_ids_list.txt
number_of_ids=${#discussion_ids_arr[@]}
for (( i=0; i<${number_of_ids}; i++ ));
do
echo "Number of IDs: ${number_of_ids}"
echo "IDs Array: ${discussion_ids_arr[@]}"
echo "IDs List:"
cat discussion_ids_list.txt
for (( i=0; i<${number_of_ids}; i++ )); do
discussion_id=${discussion_ids_arr[$i]}
echo "$discussion_id"
curl -X PATCH -H "Authorization: token $GITHUB_TOKEN" \
-d '{"state": "closed"}' \
'https://api.github.com/repos/${{ github.repository }}/discussions/$discussion_id'
"https://api.github.com/repos/${{ github.repository }}/discussions/$discussion_id"
done
shell: bash
136 changes: 136 additions & 0 deletions .github/workflows/createchangelog.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
name: Update changelog.md on Release

on:
workflow_dispatch: # Manual trigger added
workflow_call: # Make this Working a re-usable one (can be called form another workflow)

jobs:
update-changelog-file:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4
# Make sure to get latest commits, like the one committed by the previous job in jobs list.
# reference: https://github.com/orgs/community/discussions/110853
with:
fetch-tags: 'true'
submodules: 'recursive'
ref: ${{ github.ref }}

- name: Get correct branch to use for committing changes
id: get_correct_branch
run: |
# NOTE/TODO:
# Because there's a chance where this'll get triggered by a Release Creation, Edit, Deletion..
# the value of 'github.ref' will be 'refs/tags/TAG-NAME', and this tag can not be handled easily by
# the 'actions/checkout' action.. we need to handle this case by always changing to main branch.
declare -rA number_of_refname_instances=$(git branch -a | grep -Po '${{ github.ref_name }}' | wc --lines)
if [[ $number_of_refname_instances = 0 ]] ; then
echo "branch_name=main" >> $GITHUB_OUTPUT
else
echo "branch_name=${{ github.ref_name }}" >> $GITHUB_OUTPUT
fi
- name: Get all releases and update changelog.md file
run: |
# 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 changelog file
echo "" > $changelog_path
# Write some Initial Content to changelog file
echo "# Changelog" >> $changelog_path
echo "" >> $changelog_path
echo "WinUtil changelog is based on GitHub Releases, and autogenerated using GitHub Actions." >> $changelog_path
echo "" >> $changelog_path
echo "!!! warning \"Important\"" >> $changelog_path
echo "" >> $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 said PR **will get rejected**." >> $changelog_path
echo "" >> $changelog_path
# Make array for git tag names
tag_arr=()
cat releases.txt | grep -Po '"tagName":\s*.*?[^\\]"' | 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":\s*.*?[^\\]"' | 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":\s*(false|true)' | awk -F ':' '{print $2}' | 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":\s*(false|true)' | awk -F ':' '{print $2}' | sed s/\"//g > islatest_list.txt
while read -r line; do
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]}
body=$(gh release view "$tag" --json body --jq .body)
# The generation of changelog file contents
echo "# $name" >> $changelog_path
echo "" >> $changelog_path
echo "$body" >> $changelog_path
echo "" >> $changelog_path
done
env:
GH_TOKEN: ${{ github.token }}

- name: Commit and Push Changes
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git switch ${{ steps.get_correct_branch.outputs.branch_name }}
git pull
git add docs/changelog.md
git commit -m "Update changelog.md with all releases"
echo "Event name: ${{ github.event_name }}"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
113 changes: 0 additions & 113 deletions .github/workflows/createchangelog.yml

This file was deleted.

41 changes: 41 additions & 0 deletions .github/workflows/github-pages.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: GitHub Pages Deploy
on:
release:
types: [edited, deleted] # Make sure changelog is up-to-date by updating it, and building GitHub Pages.
workflow_dispatch: # Manual trigger added
workflow_call: # Make this Working a re-usable one (can be called form another workflow)

permissions:
contents: write

jobs:
update-changelog:
uses: ./.github/workflows/createchangelog.yaml

bulid-deploy-gh-pages:
# Make sure 'update-changelog' run first, then run this job afterward
needs: update-changelog
runs-on: ubuntu-latest

steps:
- name: Checkout Repo
uses: actions/checkout@v4
# Make sure to get latest commits, like the one committed by the previous job in jobs list.
# reference: https://github.com/orgs/community/discussions/110853
with:
fetch-tags: 'true'
submodules: 'recursive'
ref: ${{ github.ref }}

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.x

- name: Install Additional Python Dependencies
run: |
pip install mkdocs-material
pip install pillow cairosvg
- name: Build using MkDocs & Deploy to GitHub Pages
run: mkdocs gh-deploy --force
22 changes: 0 additions & 22 deletions .github/workflows/github-pages.yml

This file was deleted.

13 changes: 12 additions & 1 deletion .github/workflows/pre-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ on:
workflow_dispatch: # Manual trigger added

jobs:
build-runspace:
release:
runs-on: windows-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
# Make sure to get latest commits, like the one committed by the previous job in jobs list.
# reference: https://github.com/orgs/community/discussions/110853
with:
fetch-tags: 'true'
submodules: 'recursive'
ref: ${{ github.ref }}

- name: Extract Version from winutil.ps1
id: extract_version
Expand Down Expand Up @@ -46,3 +52,8 @@ jobs:
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

deploy-github-pages:
# Make sure 'release' job runs first, then run this job afterward
needs: release
uses: ./.github/workflows/github-pages.yaml
Loading

0 comments on commit 5eb4e1f

Please sign in to comment.