Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI/CD] WIP: Re-use Workflows to Ensure GitHub Pages is built after every pre-release - Cleanup Workflow Naming Inconsistency - Remove 'release.yaml' workflow #2471

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
8fd0f0d
Make workflows re-usable
og-mrk Jul 28, 2024
0a1e4cc
Rename File Extensions for some workflow files
og-mrk Jul 28, 2024
7ee15a7
Change job ordering
og-mrk Jul 28, 2024
c6613de
Try something else to force specific job ordering
og-mrk Jul 28, 2024
b0c2165
Another Try something else to force specific job ordering
og-mrk Jul 28, 2024
05f75c9
Add comments & rename some jobs
og-mrk Jul 28, 2024
85d56fb
Make 'github-pages' workflow file get latest commits from action's cu…
og-mrk Jul 28, 2024
a8f17ce
Add reference to 'Checkout Repo' step
og-mrk Jul 28, 2024
2bda652
Fix Admonition in Changelog Workflow
og-mrk Jul 28, 2024
a6bc7ca
Remove un-used 'release.yaml' workflow
og-mrk Jul 28, 2024
d923e34
Add 'release' event to 'github-pages' workflow
og-mrk Jul 28, 2024
2d95b12
Fix Admonition in Changelog Workflow
og-mrk Jul 28, 2024
11658a6
Make 'actions/checkout' fetch latest of anything, git submodules, tag…
og-mrk Jul 28, 2024
6c5c869
Fix yaml syntax error
og-mrk Jul 28, 2024
753d9f9
Handle special case in 'createchangelog.yaml' workflow
og-mrk Jul 28, 2024
c63c9aa
Update workflows
og-mrk Jul 28, 2024
0d12b0c
Fix issue with 'createchangelog' workflow always switching to Git Det…
og-mrk Jul 29, 2024
feee518
Reorder 'env' field in 'createchangelog' workflow
og-mrk Jul 29, 2024
1343bd9
Fix 'close-discussion' workflow not working
og-mrk Jul 29, 2024
5b47a33
Add debug info to 'close-discussion' workflow
og-mrk Jul 29, 2024
416ab76
Bring back control to the 'Extract Discussion Number & Close If any W…
og-mrk Jul 29, 2024
fb4de0f
Make 'grep' treat git ref as a simple string rather than a pattern (r…
og-mrk Jul 29, 2024
431533d
Better filter the results in second step of 'createchangelog' workflow
og-mrk Jul 29, 2024
51e13fa
Another Try to make 'createchangelog' work on release edit/deletion
og-mrk Jul 29, 2024
1ed1539
Merge to 'main' branch workflow-update/fix-createchangelog-not-running
og-mrk Jul 31, 2024
03b21a7
Temporarily make 'close-discussion' as a WIP Workflow
og-mrk Jul 31, 2024
7bebae8
Make http(s) links clickable by converting any links to a format unde…
og-mrk Aug 1, 2024
bb31064
Fix YAML syntax error - 'close-discussion' Workflow
og-mrk Aug 1, 2024
a00ac0e
Fix RegEx with 'sed' commands - 'createchangelog' Workflow
og-mrk Aug 1, 2024
1982579
Fix Download Counter for each pre-release - 'pre-release' Workflow
og-mrk Aug 1, 2024
0e2647d
Another Fix for 'sed' commands RegEx - 'createchangelog' Workflow
og-mrk Aug 1, 2024
ca724c6
Make 'actions/checkout' pull from 'main' - 'createchangelog' & 'githu…
og-mrk Aug 1, 2024
1ab8d71
Re-Add 'git config' in 'createchangelog' Workflow
og-mrk Aug 1, 2024
125b437
Update 'createchangelog' Workflow
og-mrk Aug 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/close-discussion.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Close Discussion on PR Merge

on:
pull_request:
types: [closed]

jobs:
closeDiscussion:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Check if PR was merged
if: github.event.pull_request.merged == true
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
id: extract-discussion
run: |
output_str=$(cat <<DELIMITER
TODO:
Use GitHub's GraphQL to query the Discussion by ID, therefore checking if ID is for a discussion or not.
Then make a new comment to it, wait until it's created, and maybe wait additional seconds to make sure everything works great.
Then mark the newly created comment on discussion as the answer to discussion, so the discussion is "closed" so to speak.
Reference:
- https://github.com/orgs/community/discussions/43
- https://github.com/orgs/community/discussions/43#discussioncomment-399047
- https://docs.github.com/en/graphql/guides/using-the-graphql-api-for-discussions
DELIMITER)
echo "$output_str"
exit 1
#pr_body="${{ github.event.pull_request.body }}"

#discussion_ids=$(echo "$pr_body" | grep -i -Po '^\s*(-|\d+\.)?\s*(Resolve(s|d)?)\s*#\d+\s*$|^\s*(-|\d+\.)?\s*(Fix(es|ed)?)\s*#\d+\s*$|^\s*(-|\d+\.)?\s*(Close(s|d)?)\s*#\d+\s*$' | awk -F '#' '{print $2}')

#echo "IDs Array: ${discussion_ids[@]}"

#if [ -z "$discussion_ids" ]; then
# echo "No discussion IDs found."
# exit 0
#fi

#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"
#done
43 changes: 0 additions & 43 deletions .github/workflows/close-discussion.yml

This file was deleted.

124 changes: 124 additions & 0 deletions .github/workflows/createchangelog.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
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: main # Always pull from & push to 'main' branch, as without doing so, it'll cause some problems.

- 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 -r 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 change log received from GitHub Releases, it's 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) || { echo "Failed to fetch release body for $tag"; exit 1; }

# The generation of changelog file contents
echo "# $name" >> $changelog_path
echo "" >> $changelog_path
echo "$body" >> $changelog_path
echo "" >> $changelog_path
done

# Make http(s) links clickable by converting any links to a format understandable by Markdown
sed -ri 's/(https?:\/\/.*?\/(pull|compare)\/([^ \t\r\n]+))/\[\3\](\1)/g' $changelog_path
sed -ri 's/\[([0-9]+)\]\((https?:\/\/.*?\/pull\/[^ \t\r\n]+)\)/\[#\1\]\(\2\)/g' $changelog_path
sed -ri 's/@([^ \t\r\n]+)/[@\1](https:\/\/github\.com\/\1)/g' $changelog_path
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 add docs/changelog.md
git commit -m "Update changelog.md with all releases"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
117 changes: 0 additions & 117 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 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: main # Always pull from & push to 'main' branch, as without doing so, it'll cause some problems.

- 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
Loading