Skip to content

Commit

Permalink
[NEW] Automated Workflows v1.7.2 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 17, 2024
2 parents 75ed530 + 5f86a59 commit 5f78f38
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 58 deletions.
74 changes: 38 additions & 36 deletions .github/workflows/_auto-prod.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
#############################
## Merge Release into Main ##
#############################
#####################################
## Auto Merge PR to Main - GitOps ##
#####################################

# Triggered on tag 'auto-prod' push
# Part of 'release-me' Git Ops Process: User Br -> release -> main

# export tt='auto-prod'
# Triggers on pushed auto-prod-* tags

# EG
# export tt='auto-prod-1.3.0'
# OR
# export tt='auto-prod-1.2.1-dev'
# git tag -d "$tt"; git push --delete origin "$tt"; git tag "$tt" && git push origin "$tt"

#### Does the following:
# 1. Triggers 'Release' Stress Tests
# 2. if Tests and Code Review OK
# 3. Merge PR 'Release' --> 'Main'
# 1. Derives a Git Tag to make an RC Tag
# 2. Tags commit on release branch with RC Tag
####


on:
push:
tags:
- auto-prod-*
# jobs:
# # please add 'main' Rule Required Checks, before running this job
# auto_merge_pr_to_main:
# uses: boromir674/automated-workflows/.github/workflows/go-auto-merge-main.yml@test
# with:
# main_branch: ${{ vars.GIT_MAIN_BRANCH || 'main' }}
# release_branch: ${{ vars.GIT_RELEASE_BRANCH || 'release' }}
# commit_message: 'Automated Workflows'
# secrets:
# pat_token: ${{ secrets.GA_WORKFLOWS_CI_PR_RW_AND_ACTIONS_RW }}

jobs:
merge_release_into_main:
Expand All @@ -25,7 +40,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_BR: 'release'
MAIN_BR: ${{ vars.GIT_MAIN_BRANCH || 'main' }}
COMMIT_MSG_ON_RELEASE_BR: 'Release Candidate - CI Pipeline'
COMMIT_MSG_ON_RELEASE_BR: 'Automated Workflows'
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -47,19 +62,6 @@ jobs:
name: "Exit if '${{ github.ref }}' NOT on '${{ env.RELEASE_BR }}' branch"
run: echo "Tag '${{ github.ref }}' on '${{ env.RELEASE_BR }}' = ${{ steps.tag_on_release.outputs.retval }}" && exit 1

# Parse SOURCE Sem Ver
# - run: echo SEMVER=$(grep -E -o '^version\s*=\s*\".*\"' pyproject.toml | cut -d'"' -f2) >> $GITHUB_OUTPUT
# id: sem_ver

# Find latest tag on MAIN_BR and derive Sem Ver
- name: "Search tags on MAIN_BR, filter out those not matching v* and find latest"
run: |
LATEST_PROD_GIT_TAG=$(git tag -l "v*" | sort -V | tail -n 1)
echo "[INFO]: Latest Prod Git Tag: $LATEST_PROD_GIT_TAG"
LATEST_PROD_SEM_VER=${LATEST_PROD_GIT_TAG:1}"
echo "**Discovered Sem Ver, previously published: $LATEST_PROD_SEM_VER**" >> $GITHUB_STEP_SUMMARY
# READ NEW SEM VER from pushed git tag, ie '1.2.0' from 'auto-prod-1.2.0'
- name: Read New Sem Ver from Tag
id: sem_ver
Expand All @@ -79,29 +81,27 @@ jobs:
echo "PROD_OR_DEV=PROD" >> $GITHUB_OUTPUT
fi
# Derive Git Tag that will trigger 'Release Candidate - CI Pipeline'
- name: 'Create Git Tag, by appending -rc to PROD Sem Ver'
# ie 1.0.1-> v1.0.1-rc
- name: 'Derive RC Git Tag from PROD Release: prepend v and append -rc to Sem Ver'
if: ${{ steps.prod_or_dev.outputs.PROD_OR_DEV == 'PROD' }}
run: 'echo RC_TAG="v${{ steps.sem_ver.outputs.SEMVER }}-rc" >> $GITHUB_ENV'

- name: 'Create Git Tag, using DEV Sem Ver'
# ie 1.0.1-dev-> v1.0.1-rc
- name: 'Derive RC Git Tag from DEV Release: prepend v, use <M.m.p> part from Sem Ver and append -rc'
if: ${{ steps.prod_or_dev.outputs.PROD_OR_DEV == 'DEV' }}
run: 'echo RC_TAG="v${{ steps.sem_ver.outputs.SEMVER }}" >> $GITHUB_ENV'
# run: 'echo RC_TAG="v${{ steps.sem_ver.outputs.SEMVER }}" >> $GITHUB_ENV'
run: 'echo RC_TAG="v$(echo ${{ steps.sem_ver.outputs.SEMVER }} | grep -oP "^\d+\.\d+\.\d+")-rc" >> $GITHUB_ENV'

- name: "Trigger Release Candidate - Stress Tests"
# potentially trigger Deployment into Staging/Test
- name: "Create and Push RC Tag ${{ env.RC_TAG }}"
run: |
echo "[STEP]: Tag Local: ${RC_TAG}"
git tag -d "$RC_TAG" || echo "Ensured Local Tag $RC_TAG does not exist"
git tag -d "$RC_TAG" || true
git tag "$RC_TAG"
echo
echo "[STEP]: Tag Remote: ${RC_TAG}"
git push --delete origin "$RC_TAG" || echo "Ensured Remote Tag $RC_TAG does not exist"
git push --delete origin "$RC_TAG" || true
git push origin "$RC_TAG"
echo
echo "Tag ${{ env.RC_TAG }} was **pushed to remote**" >> $GITHUB_STEP_SUMMARY
echo " -> Pushed tag $RC_TAG"
echo
echo "## TRIGGERED RELEASE CANDIDATE - TESTS ##"
echo
# Derive Commit subject for PR Merge, based on PROD or DEV
- name: 'Create Commit Message: [NEW] ${{ env.COMMIT_MSG_ON_RELEASE_BR }} v${{ steps.sem_ver.outputs.SEMVER }} Release'
Expand All @@ -115,6 +115,8 @@ jobs:
# LABEL PR for Auto Deploy, to trigger 'Tag Prod' Workflow after merge
- name: "Label PR for Auto Deploy"
run: gh pr edit "${{ env.RELEASE_BR }}" --add-label "auto-deploy"
env:
GH_TOKEN: ${{ secrets.GA_WORKFLOWS_CI_PR_RW_AND_ACTIONS_RW }}

### Merge PR, when CI Pass + Human Review OK ###
- name: "Merge PR 'head': ${{ env.RELEASE_BR }} --> 'base': ${{ env.MAIN_BR }}"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/_tag-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
# if tag ends with '-rc' strip it and store remaining string
if [[ $LATEST_GIT_TAG == *"-rc" ]]; then
PROD_SEM_VER=${LATEST_GIT_TAG:1:${#LATEST_GIT_TAG}-3}
PROD_SEM_VER=${LATEST_GIT_TAG:1:${#LATEST_GIT_TAG}-4}
# else if dev substring is found then store as it is
elif [[ $LATEST_GIT_TAG == *"dev"* ]]; then
PROD_SEM_VER=$LATEST_GIT_TAG
Expand Down
23 changes: 11 additions & 12 deletions .github/workflows/go-auto-merge-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
- name: Read New Sem Ver from Tag
id: sem_ver
run: |
NEW_SEMVER=$(echo "${{ github.ref }}" | cut -d'-' -f3)
NEW_SEMVER=$(echo "${{ github.ref }}" | grep -oP '(?<=auto-prod-).+')
echo "[INFO]: New Sem Ver: $NEW_SEMVER"
echo "**New Sem Ver: $NEW_SEMVER**" >> $GITHUB_STEP_SUMMARY
echo SEMVER=$NEW_SEMVER >> $GITHUB_OUTPUT
Expand All @@ -110,23 +110,22 @@ jobs:
if: ${{ steps.prod_or_dev.outputs.PROD_OR_DEV == 'PROD' }}
run: 'echo RC_TAG="v${{ steps.sem_ver.outputs.SEMVER }}-rc" >> $GITHUB_ENV'

# ie 1.0.1-dev-> v1.0.1-dev
- name: 'Derive RC Git Tag from DEV Release: prepend v and use rest of Sem Ver'
# ie 1.0.1-dev-> v1.0.1-rc
- name: 'Derive RC Git Tag from DEV Release: prepend v, use <M.m.p> part from Sem Ver and append -rc'
if: ${{ steps.prod_or_dev.outputs.PROD_OR_DEV == 'DEV' }}
run: 'echo RC_TAG="v${{ steps.sem_ver.outputs.SEMVER }}0" >> $GITHUB_ENV'
# run: 'echo RC_TAG="v${{ steps.sem_ver.outputs.SEMVER }}" >> $GITHUB_ENV'
run: 'echo RC_TAG="v$(echo ${{ steps.sem_ver.outputs.SEMVER }} | grep -oP "^\d+\.\d+\.\d+")-rc" >> $GITHUB_ENV'

- name: "Push RC Tag - potentially triggering Deployment into Staging"
# potentially trigger Deployment into Staging/Test
- name: "Create and Push RC Tag ${{ env.RC_TAG }}"
run: |
echo "[STEP]: Tag Local: ${RC_TAG}"
git tag -d "$RC_TAG" || echo "Ensured Local Tag $RC_TAG does not exist"
git tag -d "$RC_TAG" || true
git tag "$RC_TAG"
echo
echo "[STEP]: Tag Remote: ${RC_TAG}"
git push --delete origin "$RC_TAG" || echo "Ensured Remote Tag $RC_TAG does not exist"
git push --delete origin "$RC_TAG" || true
git push origin "$RC_TAG"
echo
echo "Tag ${{ env.RC_TAG }} was **pushed to remote**" >> $GITHUB_STEP_SUMMARY
echo " -> Pushed tag $RC_TAG"
echo
# Derive Commit subject for PR Merge, based on PROD or DEV

Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ All notable changes to this project will be documented in this file.

This project adheres to [Semantic Versioning](https://semver.org/).


## 1.7.2 (2024-09-17)

### Changes

#### Feature

- convert -dev tags into -rc when running Auto Prod Workflow

#### Fix
- correctly name tag on main and improve Auto Prod

#### Docs
- mention that Release Me Phase 2 creates an RC Tag on release branch


## 1.7.1 (2024-09-16)

### Changes
Expand Down
24 changes: 19 additions & 5 deletions docs/guides/gitops/run/guide_run_gitops_release_me_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,28 @@ This is a `how-to` Guide, with everything you need, to "run" the
2. Wait for PR to open against *base* `main` branch, from *head* `release` branch
3. Derive new Sem Ver
3. Sync `release` branch to local checkout
```sh
export release=release
```
```sh
git fetch
git branch --track $release "origin/${release}" || true
git checkout "${release}"
git pull origin "${release}"
```
4. Derive new Sem Ver
{% include 'diagram-sem-ver-derivation-process.md' %}
4. Update Changelog (1)
5. Update Changelog (1)
5. If you maintain the Sem Ver in your source files, **update Sem Ver in sources**
6. If you maintain the Sem Ver in your source files, **update Sem Ver in sources**
6. Fire-up a `auto-prod-<sem ver>` git tag event (ie `auto-prod-1.2.0`)
7. Fire-up a `auto-prod-<sem ver>` git tag event (ie `auto-prod-1.2.0`)
```sh
export _SEM_VER=...
Expand All @@ -76,7 +89,7 @@ This is a `how-to` Guide, with everything you need, to "run" the
git tag "$_tag" && git push origin "$_tag"
```
7. If, you have setup `Human Approval`, give the Release a **green light**, by approving a Code Review.
8. If, you have setup `Human Approval`, give the Release a **green light**, by approving a Code Review.
</div>
Expand All @@ -102,6 +115,7 @@ Your changes should now be merged into `main`.
checkout release
merge "User Br" id: "Merge" type: HIGHLIGHT
commit id: "CHANGELOG.md" tag: "v2.1.0-rc"
checkout main
merge release id: "[NEW] 2.1.0" type: HIGHLIGHT
Expand Down
29 changes: 25 additions & 4 deletions docs/topics/gitops/release-me-process.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,21 @@ A typical **Release** `User Journey` for a single-Developer/Contributor project,

## Phase 1

**On-demand trigger** by pushing the `release-me` git tag to remote.
- **On-demand trigger** by pushing the `release-me` git tag to remote.

In this phase we say

**Our `head` branch has all the code changes to be released**


```
export tt='release-me'
git tag -d "$tt"; git push --delete origin "$tt"
git tag "$tt" && git push origin "$tt"
```

1. Open `PR` 'User Br' --> 'release', and merge if *PR OK*
2. Open `PR` 'release' --> 'main'
1. Opens a `PR` 'User Br' --> 'release', and auto merges if *PR OK*
2. Opens a `PR` 'release' --> 'main'

```mermaid
Expand All @@ -62,9 +67,25 @@ git tag "$tt" && git push origin "$tt"
merge "User Br" id: "Merge" type: HIGHLIGHT
```

## Manual Phase

Typically, the Developer should take care of doing the necessary *Release chores*,
which include make changes to the source files.

- Adding a new Release Entry in source Changelog

## Phase 2

**On-demand trigger** by pushing a `auto-prod-<sem_ver>` git tag to remote.
- **On-demand trigger** by pushing a `auto-prod-<sem_ver>` git tag to remote.

!!! Tip

Typically, the Developer should take care of doing the necessary *Release chores*, which include make changes to the source files, on the `release` branch:

- **Updating Changelog**, by adding a Release Entry corresponding to the new Sem Ver
- **Updating Sem Ver in Sources**, by bumping all references of Version maintained in the Sources



Example:
```
Expand Down

0 comments on commit 5f78f38

Please sign in to comment.