Skip to content

Commit eef9cc9

Browse files
authored
Tagging workflow included (#57)
Adding another workflow as part of https://dev.azure.com/TDEI-UW/TDEI/_workitems/edit/3739 This workflow automatically updates the tags based on merges to the respective branches <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## 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. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents ddf47b2 + 9165bfa commit eef9cc9

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

.github/workflows/tag.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Whenever there is a pull request merged into the branches, create tag
2+
name: Update Environment Tag
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
- develop
8+
- staging
9+
- production
10+
jobs:
11+
update-tag:
12+
if: github.event.pull_request.merged == true
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 1
21+
- name: Get the current branch name
22+
id: get_branch
23+
run: |
24+
TARGET_BRANCH="${{ github.event.pull_request.base.ref }}"
25+
26+
if [ "$TARGET_BRANCH" = "develop" ]; then
27+
echo "ENV_TAG=dev" >> $GITHUB_ENV
28+
elif [ "$TARGET_BRANCH" = "staging" ]; then
29+
echo "ENV_TAG=stage" >> $GITHUB_ENV
30+
elif [ "$TARGET_BRANCH" = "production" ]; then
31+
echo "ENV_TAG=prod" >> $GITHUB_ENV
32+
else
33+
echo "ENV_TAG=" >> $GITHUB_ENV
34+
fi
35+
- name: Force update tag
36+
if: ${{ env.ENV_TAG != '' }}
37+
run: |
38+
git config user.name "github-actions[bot]"
39+
git config user.email "github-actions[bot]@users.noreply.github.com"
40+
echo "Targeting tag: ${{ env.ENV_TAG }}"
41+
git tag -f $ENV_TAG
42+
git push origin $ENV_TAG --force

0 commit comments

Comments
 (0)