Skip to content

Commit

Permalink
[NEW] Automated Workflows v1.12.0 Release
Browse files Browse the repository at this point in the history
[GITOPS] - Merging 'release' in 'main' - Releasing into Production
  • Loading branch information
boromir674 authored Aug 19, 2024
2 parents 420f00f + 7492380 commit 18b20a3
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 9 deletions.
1 change: 0 additions & 1 deletion .github/workflows/_tag-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
79 changes: 79 additions & 0 deletions .github/workflows/go-delete-tags.yml
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions docs/api/ref_go-delete-tags.md
Original file line number Diff line number Diff line change
@@ -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
44 changes: 44 additions & 0 deletions docs/api/ref_go-tag-main.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
22 changes: 14 additions & 8 deletions scripts/gen-docs-refs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit 18b20a3

Please sign in to comment.