From 48376c9b0a42700aab1d704336c5c318bc56bab1 Mon Sep 17 00:00:00 2001 From: konstantinos Date: Mon, 19 Aug 2024 00:38:43 +0300 Subject: [PATCH 1/5] ci: fix gitops _tag_prod Workflow --- .github/workflows/_tag-prod.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/_tag-prod.yml b/.github/workflows/_tag-prod.yml index bdacb4b..439486e 100644 --- a/.github/workflows/_tag-prod.yml +++ b/.github/workflows/_tag-prod.yml @@ -32,7 +32,6 @@ jobs: # Automatically create tag on main branch derived from RC Tag on release branch tag_prod: needs: put_test_branch_to_main - runs-on: ubuntu-latest # if merged code in main/master AND HEAD branch "was" 'release' AND # PR has label 'auto-deploy' if: always() && github.event.pull_request.merged == true && From 08bad70021c0d1ccca53468b96df301c647f2238 Mon Sep 17 00:00:00 2001 From: konstantinos Date: Mon, 19 Aug 2024 16:26:55 +0300 Subject: [PATCH 2/5] feat(gitops): delete Git Ops events related tags, on-demand with Reusable Workflow --- .github/workflows/go-delete-tags.yml | 79 ++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 .github/workflows/go-delete-tags.yml diff --git a/.github/workflows/go-delete-tags.yml b/.github/workflows/go-delete-tags.yml new file mode 100644 index 0000000..7b4a2da --- /dev/null +++ b/.github/workflows/go-delete-tags.yml @@ -0,0 +1,79 @@ +#################################### +## Delete Tags of Git Ops Events ## +## Reusable Workflow ## +#################################### + +# Delete Git Tags, acting as push events that trigger Git Ops Workflows + +name: Delete Git Ops Tags +on: + workflow_call: + secrets: + GH_PAT_CONTENT_RW: + description: 'GitHub Personal Access Token with permission to Delete Tags; read/write permissions to Content' + required: true +jobs: + delete_tags: + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + with: + # ref: ${{ github.head_ref }} + token: ${{ secrets.GH_PAT_CONTENT_RW }} + + # DELETE 'release-me' tag, if found + # if the tag exists on remote, then empty log message corresponds to successfull deletion + - name: Delete the 'release-me' Tag, if found + shell: bash + run: | + set -o pipefail + git push origin -d release-me 2>&1 | tee tag-delete.log + + if [ -s tag-delete.log ]; then # file exists with >0 bytes content + + # if 2nd line of log message matches '[deleted] release-me', we are OK + if [[ $(sed -n '2p' tag-delete.log) == *"[deleted] release-me"* ]]; then + echo '- **Deleted Tag** `release-me` :)' >> $GITHUB_STEP_SUMMARY + + # if 1st line of log file is + # error: unable to delete 'release-me': remote ref does not exist, we are OK + elif [[ $(head -n 1 tag-delete.log) == *"error: unable to delete 'release-me': remote ref does not exist"* ]]; then + + echo '- **Tag** `release-me` **NOT Found on remote** :)' >> $GITHUB_STEP_SUMMARY + + else + # we fail to anticipate log message, so we crash with ERROR + echo '- [ERROR] Could not `Delete` or `Verify non-existing` **Tag** `release-me` on **remote** !' >> $GITHUB_STEP_SUMMARY + echo "Error message:" >> $GITHUB_STEP_SUMMARY + + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + echo "$(cat tag-delete.log)" >> $GITHUB_STEP_SUMMARY + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + + echo "**Exiting Job with ERROR !**" >> $GITHUB_STEP_SUMMARY + exit 1 + fi + else + # no Log message captured, we exit with CRITICAL + echo '- [CRITICAL] Could not capture Tag Deletion Log Message!' >> $GITHUB_STEP_SUMMARY + echo "**Exiting Job with CRITICAL !**" >> $GITHUB_STEP_SUMMARY + exit 1 + fi + + # DELETE any 'auto-prod-*' tag(s) found + - name: Delete any auto-prod-* tag found + env: + auto_prod_prefix: 'auto-prod-' + run: | + # not possible to clobber existing tags, since local checkout only tracks default (ie main) branch + # so we can safely fetch all tags + git fetch --tags + + # Now we have guaranteed all local tags HAVE a remote counterpart (referencing the same commits) + # iterate and delete each tag, if any deletion fails, we crash to indicate failure + for git_tag in $(git tag -l "${auto_prod_prefix}*"); do + git push origin --delete "${git_tag}" + echo '- **Deleted Tag** ${git_tag}' >> $GITHUB_STEP_SUMMARY + done From ee16a71eabd853587ad60d6aec89c5bd9185c01d Mon Sep 17 00:00:00 2001 From: konstantinos Date: Mon, 19 Aug 2024 16:27:56 +0300 Subject: [PATCH 3/5] chore(docs): fix Automatic mkdocs Side-Navigation-update and API Gen script --- scripts/gen-docs-refs.sh | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/scripts/gen-docs-refs.sh b/scripts/gen-docs-refs.sh index 68ee810..11b411f 100644 --- a/scripts/gen-docs-refs.sh +++ b/scripts/gen-docs-refs.sh @@ -25,9 +25,9 @@ chmod +x ./scripts/gen-workflow-ref.py for workflow_yaml in ./.github/workflows/*.yml ./.github/workflows/*.yaml; do filename=$(basename $workflow_yaml) # exclude if name starts with 'underscore' (_) character - # if [[ $filename == _* ]]; then - # continue - # fi + if [[ $filename == _* ]]; then + continue + fi # keep only Reusable Workflows that are user-facing (public API) # use yq to keep only if there is top-level 'on' key mapping to any object with the 'workflow_call' inner key @@ -104,18 +104,24 @@ for workflow_yaml in ./.github/workflows/*.yml ./.github/workflows/*.yaml; do # 'Github Release' # ... # dynamic_keys=$(yq eval ".nav[2].References | .[] | keys | .[] | sub(\"-\",\"\") | sub(\"^\",\"'\") | sub(\"\$\",\"'\")" mkdocs.yml) - dirty_dynamic_keys=$(yq eval ".nav[2].References | .[] | keys | .[] | sub(\"-\",\"\") | sub(\"^\",\"'\") | sub(\"\$\",\"'\")" mkdocs.yml) - dynamic_keys=$(yq eval '.nav[2].References | .[] | keys | .[] | sub("^-","")' mkdocs.yml) + # dirty_dynamic_keys=$(yq eval ".nav[2].References | .[] | keys | .[] | sub(\"-\",\"\") | sub(\"^\",\"'\") | sub(\"\$\",\"'\")" mkdocs.yml) + + # DRY value, in case Side Navigation Design changes + API_REFS_KEY="API References" + + dynamic_keys=$(yq eval ".nav[2].[\"${API_REFS_KEY}\"] | .[] | keys | .[] | sub(\"^-\",\"\")" mkdocs.yml) + # using the keys we can query for the existing URLs to determine if the URL is already present file_url_is_present="false" IFS=$'\n' # set internal field separator to newline - # for key in $dynamic_keys; do + + # iterate over keys, get URI values and compare with generated URI for key in $dynamic_keys; do # ie api/ref_docker.md - uri_in_mkdocs_to_compare=$(yq eval ".nav[2].References | to_entries | .[].value | select(. | has(\"$key\")) | .[\"$key\"]" mkdocs.yml) + uri_in_mkdocs_to_compare=$(yq eval ".nav[2].[\"${API_REFS_KEY}\"] | to_entries | .[].value | select(. | has(\"$key\")) | .[\"$key\"]" mkdocs.yml) # it is possible that we get a multiline string with the same values per "row", simply keep the first uri_in_mkdocs_to_compare=$(echo "$uri_in_mkdocs_to_compare" | head -n 1) @@ -149,7 +155,7 @@ for workflow_yaml in ./.github/workflows/*.yml ./.github/workflows/*.yaml; do continue fi echo "[INFO] Adding ${markdown_file_url} to Site Navigation !" - yq eval ".nav[2].References += [{\"$filename\": \"$markdown_file_url\"}]" -i mkdocs.yml + yq eval ".nav[2].[\"${API_REFS_KEY}\"] += [{\"$filename\": \"$markdown_file_url\"}]" -i mkdocs.yml done shopt -u nullglob From 10af3c4f44cd3cc82614fa6890e17845cb458cb8 Mon Sep 17 00:00:00 2001 From: konstantinos Date: Mon, 19 Aug 2024 16:32:35 +0300 Subject: [PATCH 4/5] docs: add API Reference Pages for 'Tag Prod' and 'Clean-up Tags' Reusable Workflows --- docs/api/ref_go-delete-tags.md | 36 ++++++++++++++++++++++++++++ docs/api/ref_go-tag-main.md | 44 ++++++++++++++++++++++++++++++++++ mkdocs.yml | 2 ++ 3 files changed, 82 insertions(+) create mode 100644 docs/api/ref_go-delete-tags.md create mode 100644 docs/api/ref_go-tag-main.md diff --git a/docs/api/ref_go-delete-tags.md b/docs/api/ref_go-delete-tags.md new file mode 100644 index 0000000..084dc21 --- /dev/null +++ b/docs/api/ref_go-delete-tags.md @@ -0,0 +1,36 @@ +# Workflow go-delete-tags.yml + +### Trigger Events + +If any of the below events occur, the `go-delete-tags.yml` workflow will be triggered. + +- workflow_call + +Since there is a `workflow_call` _trigger_event_, this workflow can be triggered (called) by another (caller) workflow. +> Thus, it is a `Reusable Workflow`. + + +## Reusable Workflow + +Event Trigger: `workflow_call` + +### Inputs + +#### Required Inputs + +None + +#### Optional Inputs + +None + +### Secrets + +- `GH_PAT_CONTENT_RW` + - type: _string_ + - Required: True + - Description: GitHub Personal Access Token with permission to Delete Tags; read/write permissions to Content + +### Outputs + +None diff --git a/docs/api/ref_go-tag-main.md b/docs/api/ref_go-tag-main.md new file mode 100644 index 0000000..caba49f --- /dev/null +++ b/docs/api/ref_go-tag-main.md @@ -0,0 +1,44 @@ +# Workflow go-tag-main.yml + +### Trigger Events + +If any of the below events occur, the `go-tag-main.yml` workflow will be triggered. + +- workflow_call + +Since there is a `workflow_call` _trigger_event_, this workflow can be triggered (called) by another (caller) workflow. +> Thus, it is a `Reusable Workflow`. + + +## Reusable Workflow + +Event Trigger: `workflow_call` + +### Inputs + +#### Required Inputs + +- `gh_email` + - type: _string_ + - Description: GitHub Email +- `gh_username` + - type: _string_ + - Description: GitHub Username + +#### Optional Inputs + +- `main_branch` + - type: _string_ + - Description: Name of the Main Branch. Example: main, master + - Default: `${{ github.event.pull_request.base.ref || vars.GIT_MAIN_BRANCH || 'main' }}` + +### Secrets + +- `GH_PAT_ACTION_RW` + - type: _string_ + - Required: True + - Description: GitHub Personal Access Token with read/write permissions to Actions + +### Outputs + +None diff --git a/mkdocs.yml b/mkdocs.yml index 65b2585..50e8a4d 100755 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -130,6 +130,8 @@ nav: - "Git Ops - PR to Release": api/ref_go-pr-to-release.md - "Git Ops - PR to Main": api/ref_go-pr-to-main.md - "Git Ops - Auto Merge to Main": "api/ref_go-auto-merge-main.md" + - "Git Ops - Tag Main": api/ref_go-tag-main.md + - "Git Ops - Clean-up Tags": api/ref_go-delete-tags.md - Topics: - "Single Status Workflow'": "topics/workflow_single_status_idea.md" - "Git Ops": From 749238006aca3128d5d713565908c42d173749b2 Mon Sep 17 00:00:00 2001 From: konstantinos Date: Mon, 19 Aug 2024 18:59:12 +0300 Subject: [PATCH 5/5] chore(changelog): add v1.12.0 Changelog Release Entry --- CHANGELOG.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04a409d..cd822bc 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,26 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/). +## 1.12.0 (2024-09-19) + +### Changes + +Add new Reusable Workflow for doing **Clean-up**, during the final phase of `release-me` **Git Ops Process**. + +#### Feature +- delete Git Ops events related tags, on-demand with Reusable Workflow + +#### Docs +- add API Reference Pages for 'Tag Prod' and 'Clean-up Tags' Reusable Workflows +- fix auto-prod-* event trigger shell command + +#### CI +| * 48376c9 ci: fix gitops _tag_prod Workflow + +#### Other +- fix Automatic mkdocs Side-Navigation-update and API Gen script + + ## 1.11.1 (2024-09-19) ### Changes