Skip to content

Commit 3896ca7

Browse files
authored
Modify GCP User Roles workflow to run when a PR is merged (#36430)
* Update user.yml for testing * Modify GCP User Roles workflow to run when a PR is merged
1 parent ebe8de6 commit 3896ca7

2 files changed

Lines changed: 11 additions & 15 deletions

File tree

.github/workflows/beam_Infrastructure_UsersPermissions.yml

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,8 @@ name: Modify the GCP User Roles according to the infra/users.yml file
2424

2525
on:
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
4437
permissions:
45-
contents: write
38+
contents: read
4639
pull-requests: write
4740

4841
jobs:
@@ -51,7 +44,10 @@ jobs:
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

infra/iam/users.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@
367367
- username: enriquecaol04
368368
email: enriquecaol04@gmail.com
369369
permissions:
370-
- role: roles/viewer
370+
- role: projects/apache-beam-testing/roles/beam_viewer
371371
- username: eventarc-workflow-sa
372372
email: eventarc-workflow-sa@apache-beam-testing.iam.gserviceaccount.com
373373
permissions:

0 commit comments

Comments
 (0)