From 4be81bcdafed85f75fc60ad9fe0dbf3a4afca0bc Mon Sep 17 00:00:00 2001 From: Anuj Kumar Date: Wed, 17 Jun 2026 17:51:01 +0530 Subject: [PATCH] Tagging workflow included MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## DevBoard - https://dev.azure.com/TDEI-UW/TDEI/_workitems/edit/3739 ## Changes Added a new GitHub Actions workflow (`.github/workflows/tag.yml`) that automatically updates environment tags when pull requests are merged. **Workflow Details:** - **Trigger:** Pull request closure events on `develop`, `staging`, and `production` branches (only executes when PR is merged) - **Tag Mapping:** Maps base branch to environment tag: - `develop` → `dev` - `staging` → `stage` - `production` → `prod` - **Execution:** Force-updates the git tag locally and pushes it to the remote repository with the `--force` flag - **Permissions:** Requires `contents: write` to push tags The workflow enables automated environment tagging aligned with branch-based deployments, ensuring consistent tag versions across environments. --- .github/workflows/tag.yml | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/workflows/tag.yml diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml new file mode 100644 index 0000000..229dea4 --- /dev/null +++ b/.github/workflows/tag.yml @@ -0,0 +1,42 @@ +# Whenever there is a pull request merged into the branches, create tag +name: Update Environment Tag +on: + pull_request: + types: [closed] + branches: + - develop + - staging + - production +jobs: + update-tag: + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 1 + - name: Get the current branch name + id: get_branch + run: | + TARGET_BRANCH="${{ github.event.pull_request.base.ref }}" + + if [ "$TARGET_BRANCH" = "develop" ]; then + echo "ENV_TAG=dev" >> $GITHUB_ENV + elif [ "$TARGET_BRANCH" = "staging" ]; then + echo "ENV_TAG=stage" >> $GITHUB_ENV + elif [ "$TARGET_BRANCH" = "production" ]; then + echo "ENV_TAG=prod" >> $GITHUB_ENV + else + echo "ENV_TAG=" >> $GITHUB_ENV + fi + - name: Force update tag + if: ${{ env.ENV_TAG != '' }} + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + echo "Targeting tag: ${{ env.ENV_TAG }}" + git tag -f $ENV_TAG + git push origin $ENV_TAG --force