Skip to content

Commit c222ebf

Browse files
authored
feat: GH app (#159)
* fix: app token * feat: app token * ci: fix get repos * ci: update token * ci: change username to oauth2 * ci: remove reporting * ci: really remove reporting * try: change GH username * ci: try another email * ci: switch to action checkout * ci: remove work dir * ci: add repo target for token * add repo to token * fix: remove unnecessary set-output * fix: env to secret * fix: remove unneeded GH user * fix: oops
1 parent 322a8fc commit c222ebf

File tree

3 files changed

+54
-75
lines changed

3 files changed

+54
-75
lines changed

.github/policies/eventResponder.yml

+12-12
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ disabled: false
77
configuration:
88
resourceManagementConfiguration:
99
eventResponderTasks:
10-
- description: PR - close requests from thos without write access
10+
- description: PR - close requests from this without write access
1111
if:
1212
- payloadType: Pull_Request
1313
- and:
14-
- isOpen
15-
- or:
16-
- isAction:
17-
action: Opened
18-
- isAction:
19-
action: Reopened
20-
- or:
21-
- activitySenderHasPermission:
22-
permission: read
23-
- activitySenderHasPermission:
24-
permission: none
14+
- isOpen
15+
- or:
16+
- isAction:
17+
action: Opened
18+
- isAction:
19+
action: Reopened
20+
- or:
21+
- activitySenderHasPermission:
22+
permission: read
23+
- activitySenderHasPermission:
24+
permission: none
2525
then:
2626
- addReply:
2727
reply: We do not accept pull requests from contributors without write access. Please contact a maintainer to make changes.

.github/workflows/grept-cronjob.yml

+26-56
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ jobs:
2323
outputs:
2424
repoarray: ${{ steps.graphql.outputs.repoarray }}
2525
steps:
26+
- uses: actions/create-github-app-token@c1a285145b9d317df6ced56c09f525b5c2b6f755 # v1.11.1
27+
id: app-token
28+
with:
29+
app-id: ${{ secrets.APP_ID }}
30+
private-key: ${{ secrets.APP_PRIVATE_KEY }}
31+
2632
- name: query GitHub graphql API
2733
id: graphql # TODO replace with CSV output when ready
2834
run: |
@@ -44,7 +50,7 @@ jobs:
4450
echo repoarray="$REPOARRAY"
4551
echo repoarray="$REPOARRAY" >> "$GITHUB_OUTPUT"
4652
env:
47-
GH_TOKEN: ${{ secrets.USER_PAT }}
53+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
4854

4955
governance:
5056
name: governance
@@ -53,8 +59,6 @@ jobs:
5359
env:
5460
GITHUB_USER: matt-FFFFFF
5561
GREPT_CONFIG: "git::https://github.com/Azure/Azure-Verified-Modules-Grept.git//terraform"
56-
outputs:
57-
result: ${{ steps.set-output.outputs.result }}
5862
strategy:
5963
max-parallel: 2
6064
matrix:
@@ -63,36 +67,38 @@ jobs:
6367
- repo: "terraform-azurerm-avm-template"
6468
fail-fast: false
6569
steps:
66-
- name: set env result=success
67-
run: |
68-
echo 'result=success' >> "$GITHUB_ENV"
69-
70-
- name: checkout remote
70+
- uses: actions/create-github-app-token@c1a285145b9d317df6ced56c09f525b5c2b6f755 # v1.11.1
71+
id: app-token
72+
with:
73+
app-id: ${{ secrets.APP_ID }}
74+
private-key: ${{ secrets.APP_PRIVATE_KEY }}
75+
owner: Azure
76+
repositories: ${{ matrix.repo }}
77+
78+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
7179
id: checkout
72-
run: |
73-
git clone "https://${{ env.GITHUB_USER }}:${{ secrets.USER_PAT }}@github.com/Azure/${{ matrix.repo }}.git"
74-
env:
75-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
80+
with:
81+
token: ${{ steps.app-token.outputs.token }}
82+
repository: Azure/${{ matrix.repo }}
83+
persist-credentials: true
7684

7785
- name: grept apply and auto remediate
7886
run: |
7987
echo "==> Checking code repository with grept against ${{ env.GREPT_CONFIG }}..."
8088
docker run --pull always --rm -v "$(pwd)":/src -w /src -e OVERRIDE_GITHUB_REPOSITORY="$OVERRIDE_GITHUB_REPOSITORY" -e OVERRIDE_GITHUB_REPOSITORY_OWNER="$OVERRIDE_GITHUB_REPOSITORY_OWNER" mcr.microsoft.com/azterraform:latest /usr/local/go/bin/grept apply --auto "${{ env.GREPT_CONFIG }}"
81-
working-directory: ${{ matrix.repo }}
8289
env:
8390
OVERRIDE_GITHUB_REPOSITORY: Azure/${{ matrix.repo }}
8491
OVERRIDE_GITHUB_REPOSITORY_OWNER: Azure
85-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
92+
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
8693

8794
- name: avm pre-commit
8895
run: |
8996
./avm pre-commit
90-
working-directory: ${{ matrix.repo }}
9197
continue-on-error: true
9298
env:
9399
OVERRIDE_GITHUB_REPOSITORY: Azure/${{ matrix.repo }}
94100
OVERRIDE_GITHUB_REPOSITORY_OWNER: Azure
95-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
101+
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
96102

97103
- name: detect changes
98104
id: changes
@@ -104,20 +110,18 @@ jobs:
104110
fi
105111
echo "Changes detected"
106112
echo 'detected=true' >> "$GITHUB_OUTPUT"
107-
working-directory: ${{ matrix.repo }}
108113
109114
- name: commit changes to branch and push to origin
110115
if: steps.changes.outputs.detected == 'true'
111116
run: |
112-
git config --global user.email "github-actions[bot]@users.noreply.github.com"
113-
git config --global user.name "github-actions[bot]"
117+
git config --global user.email "187664033+azure-verified-modules[bot]@users.noreply.github.com"
118+
git config --global user.name "azure-verified-modules[bot]"
114119
BRANCH="grept-apply-$(date +%s)"
115120
echo "branch=$BRANCH" >> "$GITHUB_ENV"
116121
git checkout -b "$BRANCH"
117122
git add .
118123
git commit -m "fix: grept apply"
119124
git push --set-upstream origin "$BRANCH"
120-
working-directory: ${{ matrix.repo }}
121125
122126
- name: create PR body
123127
if: steps.changes.outputs.detected == 'true'
@@ -135,14 +139,12 @@ jobs:
135139
136140
Thanks! The AVM team :heart:
137141
EOF
138-
working-directory: ${{ matrix.repo }}
139142
140143
- name: show body
141144
if: steps.changes.outputs.detected == 'true'
142145
run: |
143146
echo "Displaying PR body:"
144147
cat prbody.md
145-
working-directory: ${{ matrix.repo }}
146148
147149
- name: create pull request
148150
if: steps.changes.outputs.detected == 'true'
@@ -151,49 +153,17 @@ jobs:
151153
PR_URL=$(gh pr create --title "chore: repository governance" --body-file prbody.md)
152154
echo pull-request-number=$(gh pr view $PR_URL --json number | jq -r '.number') >> "$GITHUB_OUTPUT"
153155
env:
154-
GH_TOKEN: ${{ secrets.USER_PAT }}
155-
working-directory: ${{ matrix.repo }}
156+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
156157

157158
- name: close and comment out of date prs
158159
if: steps.changes.outputs.detected == 'true'
159160
run: |
160161
PULL_REQUESTS=$(gh pr list --search "chore: repository governance" --json number,headRefName)
161162
echo "$PULL_REQUESTS" | jq -r '.[] | select(.number != ${{ steps.pr.outputs.pull-request-number }}) | .number' | xargs -I {} gh pr close {} --delete-branch --comment "Supersceeded by #${{ steps.pr.outputs.pull-request-number }}"
162163
env:
163-
GH_TOKEN: ${{ secrets.USER_PAT }}
164-
working-directory: ${{ matrix.repo }}
165-
166-
- name: set env result=failure
167-
if: ${{ failure() }}
168-
run: |
169-
echo 'result=failed' >> "$GITHUB_ENV"
170-
if [ ! -z "${{ env.branch }}" ]; then
171-
git push origin --delete "${{ env.branch }}"
172-
fi
173-
working-directory: ${{ matrix.repo }}
174-
175-
176-
- name: set output
177-
if: ${{ always() }}
178-
id: set-output
179-
run: |
180-
echo "result=${{ env.result }}" >> "$GITHUB_OUTPUT"
164+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
181165

182166
- name: sleep for rate limit
183167
if: ${{ always() }}
184168
id: sleep
185169
run: sleep 30
186-
187-
report:
188-
name: report
189-
runs-on: ubuntu-latest
190-
needs: governance
191-
if: ${{ failure() }}
192-
steps:
193-
- name: raise issue
194-
run: |
195-
## BLOCKED on matrix outputs: https://github.com/actions/runner/pull/2477
196-
## gh issue create --repo ${{ github.repository }} --title "Repository governance failure" --body "The following repositories failed governance checks:\n\n```json\n${{ toJSON(join(needs.governance.outputs)) }}\n```\n"
197-
gh issue create --repo ${{ github.repository }} --assignee matt-FFFFFF --title "Repository governance failure" --body "The following repositories failed governance checks: <${{ github.server_url}}/${{ github.repository }}/actions/runs/${{ github.run_id}}>"
198-
env:
199-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/repo-labels.yml

+16-7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ jobs:
2323
outputs:
2424
repoarray: ${{ steps.graphql.outputs.repoarray }}
2525
steps:
26+
- uses: actions/create-github-app-token@c1a285145b9d317df6ced56c09f525b5c2b6f755 # v1.11.1
27+
id: app-token
28+
with:
29+
app-id: ${{ secrets.APP_ID }}
30+
private-key: ${{ secrets.APP_PRIVATE_KEY }}
31+
2632
- name: query GitHub graphql API
2733
id: graphql # TODO replace with CSV output when ready
2834
run: |
@@ -44,16 +50,12 @@ jobs:
4450
echo repoarray="$REPOARRAY"
4551
echo repoarray="$REPOARRAY" >> "$GITHUB_OUTPUT"
4652
env:
47-
GITHUB_TOKEN: ${{ secrets.USER_PAT }}
53+
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
4854

4955
sync-labels:
5056
name: sync
5157
runs-on: ubuntu-latest
5258
needs: getrepos
53-
env:
54-
GITHUB_USER: matt-FFFFFF
55-
outputs:
56-
result: ${{ steps.set-output.outputs.result }}
5759
strategy:
5860
max-parallel: 5
5961
matrix:
@@ -62,12 +64,19 @@ jobs:
6264
- repo: "terraform-azurerm-avm-template"
6365
fail-fast: false
6466
steps:
67+
- uses: actions/create-github-app-token@c1a285145b9d317df6ced56c09f525b5c2b6f755 # v1.11.1
68+
id: app-token
69+
with:
70+
app-id: ${{ secrets.APP_ID }}
71+
private-key: ${{ secrets.APP_PRIVATE_KEY }}
72+
owner: Azure
73+
repositories: ${{ matrix.repo }}
74+
6575
- name: run avm github labels script
6676
shell: pwsh
6777
run: |
6878
Invoke-WebRequest -Uri "https://raw.githubusercontent.com/Azure/Azure-Verified-Modules/main/docs/static/scripts/Set-AvmGitHubLabels.ps1" -OutFile "./Set-AvmGitHubLabels.ps1"
6979
./Set-AvmGitHubLabels.ps1 -RepositoryName "Azure/${{ matrix.repo }}" -CreateCsvLabelExports $false -RemoveExistingLabels $false -NoUserPrompts $true
7080
echo ${{ matrix.repo }}
7181
env:
72-
GITHUB_TOKEN: ${{ secrets.USER_PAT }}
73-
82+
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}

0 commit comments

Comments
 (0)