|
1 | | -name: "default workflow" |
| 1 | +name: "frontend default workflow" |
2 | 2 |
|
3 | 3 | permissions: |
4 | 4 | contents: write |
|
14 | 14 | merge_group: |
15 | 15 | branches: [main, develop] |
16 | 16 | 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: |
18 | 19 | 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 }} |
20 | 40 | outputs: |
21 | 41 | frontend_s3_bucket: ${{ steps.out.outputs.frontend_s3_bucket }} |
22 | 42 | cloudfront_distribution_id: ${{ steps.out.outputs.cloudfront_distribution_id }} |
23 | 43 | aws_region: ${{ steps.out.outputs.aws_region }} |
24 | 44 | steps: |
25 | 45 | - id: out |
26 | 46 | 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 }}" |
28 | 49 | echo "frontend_s3_bucket=${{ vars.FRONTEND_S3_BUCKET }}" >> "$GITHUB_OUTPUT" |
| 50 | + echo "cloudfront_distribution_id=${{ vars.CLOUDFRONT_DISTRIBUTION_ID }}" |
29 | 51 | echo "cloudfront_distribution_id=${{ vars.CLOUDFRONT_DISTRIBUTION_ID }}" >> "$GITHUB_OUTPUT" |
30 | 52 |
|
31 | 53 | frontend-workflow: |
32 | 54 | 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] |
35 | 57 | secrets: |
36 | 58 | GH_ORG_PRIVATE_KEY: ${{ secrets.GH_ORG_PRIVATE_KEY }} |
37 | 59 | GH_ORG_GITLEAKS_PRIVATE_KEY: ${{ secrets.GH_ORG_GITLEAKS_PRIVATE_KEY }} |
|
40 | 62 | AWS_OIDC_ROLE_ARN: ${{ secrets.AWS_OIDC_ROLE_ARN }} |
41 | 63 | AWS_DEPLOYMENT_ROLE_ARN: ${{ secrets.AWS_DEPLOYMENT_ROLE_ARN }} |
42 | 64 | with: |
| 65 | + environment: ${{ needs.set-env.outputs.environment }} |
43 | 66 | app-id: ${{ vars.GH_ORG_APP_ID }} |
44 | 67 | gitleaks-app-id: ${{ vars.GH_ORG_GITLEAKS_APP_ID }} |
45 | 68 | 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 }} |
0 commit comments