Skip to content

Commit 8b73dfb

Browse files
committed
feat: use workflow run with branches for resolving issue
1 parent 72f2bd3 commit 8b73dfb

2 files changed

Lines changed: 14 additions & 16 deletions

File tree

.github/workflows/build-publish-image.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and publish image
1+
name: Build and Publish Docker Image
22

33
on:
44
push:

.github/workflows/terraform.yml

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
name: Terraform Plan and Apply
22
on:
3-
workflow_dispatch:
4-
inputs:
5-
environment:
6-
description: 'The target environment for deployment'
7-
required: true
8-
default: 'Sandbox'
9-
type: choice
10-
options:
11-
- Sandbox
12-
- Production
13-
3+
workflow_run:
4+
workflows: [ "Build and publish image" ]
5+
types:
6+
- completed
7+
branches:
8+
- 'SSOTEAM-2579'
9+
- 'dev'
10+
- 'main'
1411

1512
jobs:
1613
terraform:
17-
environment: ${{ github.event.inputs.environment }}
14+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
15+
environment: ${{ github.event.workflow_run.head_branch == 'main' && 'Production' || 'Sandbox' }}
1816
runs-on: ubuntu-latest
1917
# workaround for "context access might be invalid warning"
2018
env:
@@ -29,7 +27,7 @@ jobs:
2927
- name: Get latest tag
3028
id: tag
3129
run: |
32-
if [ "${{ github.event.inputs.environment }}" == "Production" ]; then
30+
if [ "${{ github.event.workflow_run.head_branch }}" == "main" ]; then
3331
echo "IMAGE_TAG=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
3432
else
3533
echo "IMAGE_TAG=dev" >> $GITHUB_ENV
@@ -46,7 +44,7 @@ jobs:
4644
TF_VAR_image_repo=${{ env.IMAGE_REPO }}
4745
EOF
4846
- name: Set sandbox environment variables
49-
if: github.event.inputs.environment == 'Sandbox'
47+
if: github.event.workflow_run.head_branch == 'SSOTEAM-2579'
5048
run: |
5149
cat >> $GITHUB_ENV <<EOF
5250
TF_STATE_BUCKET_NAME=otp-provider-tf-sandbox
@@ -96,7 +94,7 @@ jobs:
9694
EOF
9795
9896
- name: Set production environment variables
99-
if: github.event.inputs.environment == 'Production'
97+
if: github.event.workflow_run.head_branch == 'main'
10098
run: |
10199
cat >> $GITHUB_ENV <<EOF
102100
TF_STATE_BUCKET_NAME=otp-provider-tf-production

0 commit comments

Comments
 (0)