@@ -24,14 +24,8 @@ name: Modify the GCP User Roles according to the infra/users.yml file
2424
2525on :
2626 workflow_dispatch :
27- # Trigger when the users.yml file is modified on the main branch
28- push :
29- branches :
30- - main
31- paths :
32- - ' infra/iam/users.yml'
3327 pull_request_target :
34- types : [opened, synchronize, reopened]
28+ types : [opened, synchronize, reopened, closed ]
3529 paths :
3630 - ' infra/iam/users.yml'
3731
@@ -40,9 +34,8 @@ concurrency:
4034 group : ' ${{ github.workflow }} @ ${{ github.event.issue.number || github.sha || github.head_ref || github.ref }}-${{ github.event.schedule || github.event.comment.id || github.event.sender.login }}'
4135 cancel-in-progress : true
4236
43- # Setting explicit permissions for the action to avoid the default permissions which are `write-all` in case of pull_request_target event
4437permissions :
45- contents : write
38+ contents : read
4639 pull-requests : write
4740
4841jobs :
5144 runs-on : [self-hosted, ubuntu-20.04, main]
5245 timeout-minutes : 30
5346 steps :
54- - uses : actions/checkout@v4
47+ - name : Checkout code
48+ uses : actions/checkout@v4
49+ with :
50+ ref : ${{ github.event.pull_request.merged == true && github.base_ref || github.event.pull_request.head.sha }}
5551 - name : Setup gcloud
5652 uses : google-github-actions/setup-gcloud@v3
5753 - name : Install Terraform
@@ -66,12 +62,12 @@ jobs:
6662 run : terraform plan -out=tfplan
6763
6864 - name : Convert plan to plaintext
69- if : github.event_name == 'pull_request_target '
65+ if : github.event.action == 'opened' || github.event.action == 'synchronize' || github.event.action == 'reopened '
7066 working-directory : ./infra/iam
7167 run : terraform show -no-color tfplan > tfplan.txt
7268
7369 - name : Create comment body
74- if : github.event_name == 'pull_request_target '
70+ if : github.event.action == 'opened' || github.event.action == 'synchronize' || github.event.action == 'reopened '
7571 run : |
7672 PLAN_SIZE=$(wc -c < ./infra/iam/tfplan.txt)
7773 if [ "$PLAN_SIZE" -gt 60000 ]; then
@@ -85,13 +81,13 @@ jobs:
8581 fi
8682
8783 - name : Upload plan as a comment to PR
88- if : github.event_name == 'pull_request_target '
84+ if : github.event.action == 'opened' || github.event.action == 'synchronize' || github.event.action == 'reopened '
8985 env :
9086 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
9187 GH_REPO : ${{ github.repository }}
9288 run : gh pr comment ${{ github.event.pull_request.number }} --body-file comment_body.txt
9389
9490 - name : Terraform Apply
95- if : github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'apache/beam'
91+ if : github.event.pull_request.merged == true
9692 working-directory : ./infra/iam
9793 run : terraform apply -auto-approve tfplan
0 commit comments