Skip to content

Commit 0265541

Browse files
committed
Refactor github action
When triggering jobs with workflow_run the default git ref to fetch is the default branch[1], causing all deploys to use the dev branch. We want the workflow to checkout the branch that trigger the event. The github community suggested solution is to change workflow_run to workflow_call[2] [1] https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#workflow_run [2] https://github.com/orgs/community/discussions/72097#discussioncomment-7376117
1 parent 1ac9794 commit 0265541

File tree

5 files changed

+39
-31
lines changed

5 files changed

+39
-31
lines changed

.github/workflows/deploy-dev.yaml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
name: deploy-dev
22

33
on:
4-
workflow_run:
5-
workflows:
6-
- check
7-
types:
8-
- completed
9-
branches:
10-
- dev
4+
push:
5+
branches: ['dev']
116

127
jobs:
8+
test:
9+
uses: ./.github/workflows/test.yaml
10+
with:
11+
environment: dev
1312
aws-deploy:
1413
uses: "./.github/workflows/aws-deploy.yaml"
1514
with:
16-
role-to-assume: "arn:aws:iam::XXXXXXXX:role/sagebase-github-oidc-myapp-infra"
15+
role-to-assume: "arn:aws:iam::607346494281:role/sagebase-github-oidc-agora-infra-v3"
1716
role-session-name: ${{ github.repository_owner }}-${{ github.event.repository.name }}-${{ github.run_id }}
1817
environment: dev

.github/workflows/deploy-prod.yaml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
name: deploy-prod
22

33
on:
4-
workflow_run:
5-
workflows:
6-
- check
7-
types:
8-
- completed
9-
branches:
10-
- prod
4+
push:
5+
branches: ['prod']
116

127
jobs:
8+
test:
9+
uses: ./.github/workflows/test.yaml
10+
with:
11+
environment: prod
1312
aws-deploy:
1413
uses: "./.github/workflows/aws-deploy.yaml"
1514
with:
16-
role-to-assume: "arn:aws:iam::XXXXXXXX:role/sagebase-github-oidc-myapp-infra"
15+
role-to-assume: "arn:aws:iam::681175625864:role/sagebase-github-oidc-agora-infra-v3"
1716
role-session-name: ${{ github.repository_owner }}-${{ github.event.repository.name }}-${{ github.run_id }}
1817
environment: prod
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
name: deploy-stage
22

33
on:
4-
workflow_run:
5-
workflows:
6-
- check
7-
types:
8-
- completed
9-
branches:
10-
- stage
4+
push:
5+
branches: ['stage']
116

127
jobs:
8+
test:
9+
uses: ./.github/workflows/test.yaml
10+
with:
11+
environment: stage
1312
aws-deploy:
1413
uses: "./.github/workflows/aws-deploy.yaml"
1514
with:
16-
role-to-assume: "arn:aws:iam::XXXXXXXX:role/sagebase-github-oidc-myapp-infra"
15+
role-to-assume: "arn:aws:iam::681175625864:role/sagebase-github-oidc-agora-infra-v3"
1716
role-session-name: ${{ github.repository_owner }}-${{ github.event.repository.name }}-${{ github.run_id }}
1817
environment: stage

.github/workflows/pr-check.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: pr-check
2+
3+
on:
4+
pull_request:
5+
branches: ['*']
6+
7+
jobs:
8+
test:
9+
uses: ./.github/workflows/test.yaml
10+
with:
11+
environment: dev
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
name: check
1+
name: test
22

33
on:
4-
pull_request:
5-
branches: ['*']
6-
push:
7-
branches: ['*']
8-
4+
workflow_call:
5+
inputs:
6+
environment:
7+
required: true
8+
type: string
99
jobs:
1010
unit-tests:
1111
runs-on: ubuntu-latest
@@ -26,7 +26,7 @@ jobs:
2626
- name: Generate cloudformation
2727
uses: youyo/aws-cdk-github-actions@v2
2828
env:
29-
ENV: dev
29+
ENV: ${{ inputs.environment }}
3030
with:
3131
cdk_subcommand: 'synth'
3232
actions_comment: false

0 commit comments

Comments
 (0)