Skip to content

Commit 3d3e1ab

Browse files
committed
feat(env): adds ability to specify the env on root frontend workflow
1 parent 8796d6d commit 3d3e1ab

2 files changed

Lines changed: 43 additions & 16 deletions

File tree

.github/examples/frontend_trigger_default_workflow.yml

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "default workflow"
1+
name: "frontend default workflow"
22

33
permissions:
44
contents: write
@@ -14,24 +14,46 @@ on:
1414
merge_group:
1515
branches: [main, develop]
1616
jobs:
17-
resolve-env:
17+
# maps the branch to an environment and sets it as output for the rest of the workflow
18+
set-env:
1819
runs-on: ubuntu-latest
19-
environment: ${{ github.ref == 'refs/heads/develop' && 'develop' || 'integration' }}
20+
outputs:
21+
environment: ${{ steps.map-branch-to-env.outputs.environment }}
22+
23+
steps:
24+
- id: map-branch-to-env
25+
shell: bash
26+
run: |
27+
if [[ "${GITHUB_REF}" == "refs/heads/develop" ]]; then
28+
echo "environment=dev" >> "$GITHUB_OUTPUT"
29+
elif [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then
30+
echo "environment=int" >> "$GITHUB_OUTPUT"
31+
else
32+
echo "unable to set environment for ref ${GITHUB_REF}"
33+
fi
34+
# resolves environment specific variables like s3 bucket name or cloudfront distribution id and sets them as output for the rest of the workflow.
35+
# this would not be needed if we would use the vars in the called workflows directly without exposing them as inputs (but we want to document needed variables and their purpose in the workflow inputs and not rely on implicit usage of vars in the called workflows)
36+
resolve-env-vars:
37+
runs-on: ubuntu-latest
38+
needs: set-env
39+
environment: ${{ needs.set-env.outputs.environment }}
2040
outputs:
2141
frontend_s3_bucket: ${{ steps.out.outputs.frontend_s3_bucket }}
2242
cloudfront_distribution_id: ${{ steps.out.outputs.cloudfront_distribution_id }}
2343
aws_region: ${{ steps.out.outputs.aws_region }}
2444
steps:
2545
- id: out
2646
run: |
27-
echo "resolving environment specific variables for environment $environment setting outputs for frontend_s3_bucket to ${{ vars.FRONTEND_S3_BUCKET }}"
47+
echo "resolving environment specific variables for environment ${{ needs.set-env.outputs.environment }}"
48+
echo "frontend_s3_bucket=${{ vars.FRONTEND_S3_BUCKET }}"
2849
echo "frontend_s3_bucket=${{ vars.FRONTEND_S3_BUCKET }}" >> "$GITHUB_OUTPUT"
50+
echo "cloudfront_distribution_id=${{ vars.CLOUDFRONT_DISTRIBUTION_ID }}"
2951
echo "cloudfront_distribution_id=${{ vars.CLOUDFRONT_DISTRIBUTION_ID }}" >> "$GITHUB_OUTPUT"
3052
3153
frontend-workflow:
3254
name: '.'
33-
uses: ./.github/workflows/frontend_workflow.yml
34-
needs: resolve-env
55+
uses: blw-ofag-ufag/atlas-code-github-workflows/.github/workflows/frontend_workflow.yml@v1.4.0
56+
needs: [set-env, resolve-env-vars]
3557
secrets:
3658
GH_ORG_PRIVATE_KEY: ${{ secrets.GH_ORG_PRIVATE_KEY }}
3759
GH_ORG_GITLEAKS_PRIVATE_KEY: ${{ secrets.GH_ORG_GITLEAKS_PRIVATE_KEY }}
@@ -40,8 +62,9 @@ jobs:
4062
AWS_OIDC_ROLE_ARN: ${{ secrets.AWS_OIDC_ROLE_ARN }}
4163
AWS_DEPLOYMENT_ROLE_ARN: ${{ secrets.AWS_DEPLOYMENT_ROLE_ARN }}
4264
with:
65+
environment: ${{ needs.set-env.outputs.environment }}
4366
app-id: ${{ vars.GH_ORG_APP_ID }}
4467
gitleaks-app-id: ${{ vars.GH_ORG_GITLEAKS_APP_ID }}
4568
aws-region: ${{ vars.AWS_REGION }}
46-
frontend-s3-bucket: ${{ needs.resolve-env.outputs.frontend_s3_bucket }}
47-
cloudfront-distribution-id: ${{ needs.resolve-env.outputs.cloudfront_distribution_id }}
69+
frontend-s3-bucket: ${{ needs.resolve-env-vars.outputs.frontend_s3_bucket }}
70+
cloudfront-distribution-id: ${{ needs.resolve-env-vars.outputs.cloudfront_distribution_id }}

.github/workflows/frontend_workflow.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name: "frontend workflow"
22

33
permissions:
4-
contents: write
5-
pull-requests: write
6-
id-token: write
7-
issues: write
4+
contents: write
5+
pull-requests: write
6+
id-token: write
7+
issues: write
88

99
on:
1010
workflow_call:
@@ -29,6 +29,10 @@ on:
2929
description: "CloudFront distribution ID for cache invalidation"
3030
required: true
3131
type: string
32+
environment:
33+
description: "Deployment environment used to resolve secrets (e.g., dev, int)"
34+
required: true
35+
type: string
3236
secrets:
3337
GH_ORG_PRIVATE_KEY:
3438
description: "GitHub App private key matching the app-id inputs"
@@ -80,7 +84,7 @@ jobs:
8084
name: '.'
8185
if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop') }}
8286
uses: ./.github/workflows/semantic_release.yml
83-
needs: [unit-test-sonarqube, vulnerability-scan]
87+
needs: [ unit-test-sonarqube, vulnerability-scan ]
8488
secrets:
8589
GH_ORG_PRIVATE_KEY: ${{ secrets.GH_ORG_PRIVATE_KEY }}
8690
with:
@@ -90,13 +94,13 @@ jobs:
9094
name: '.'
9195
if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop') }}
9296
uses: ./.github/workflows/frontend_build_deploy_s3.yml
93-
needs: [semantic-release ]
97+
needs: [ semantic-release ]
9498
secrets:
9599
AWS_OIDC_ROLE_ARN: ${{ secrets.AWS_OIDC_ROLE_ARN }}
96100
AWS_DEPLOYMENT_ROLE_ARN: ${{ secrets.AWS_DEPLOYMENT_ROLE_ARN }}
97101
with:
98-
version: ${{ needs.semantic-release.outputs.version }}
99-
environment: ${{ github.ref == 'refs/heads/develop' && 'dev' || 'int' }}
102+
environment: ${{ inputs.environment }}
103+
version: 1.4.0-rc.16
100104
aws-region: ${{ inputs.aws-region }}
101105
frontend-s3-bucket: ${{ inputs.frontend-s3-bucket }}
102106
cloudfront-distribution-id: ${{ inputs.cloudfront-distribution-id }}

0 commit comments

Comments
 (0)