23
23
outputs :
24
24
repoarray : ${{ steps.graphql.outputs.repoarray }}
25
25
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
+
26
32
- name : query GitHub graphql API
27
33
id : graphql # TODO replace with CSV output when ready
28
34
run : |
44
50
echo repoarray="$REPOARRAY"
45
51
echo repoarray="$REPOARRAY" >> "$GITHUB_OUTPUT"
46
52
env :
47
- GH_TOKEN : ${{ secrets.USER_PAT }}
53
+ GH_TOKEN : ${{ steps.app-token.outputs.token }}
48
54
49
55
governance :
50
56
name : governance
53
59
env :
54
60
GITHUB_USER : matt-FFFFFF
55
61
GREPT_CONFIG : " git::https://github.com/Azure/Azure-Verified-Modules-Grept.git//terraform"
56
- outputs :
57
- result : ${{ steps.set-output.outputs.result }}
58
62
strategy :
59
63
max-parallel : 2
60
64
matrix :
@@ -63,36 +67,38 @@ jobs:
63
67
- repo : " terraform-azurerm-avm-template"
64
68
fail-fast : false
65
69
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
71
79
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
76
84
77
85
- name : grept apply and auto remediate
78
86
run : |
79
87
echo "==> Checking code repository with grept against ${{ env.GREPT_CONFIG }}..."
80
88
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 }}
82
89
env :
83
90
OVERRIDE_GITHUB_REPOSITORY : Azure/${{ matrix.repo }}
84
91
OVERRIDE_GITHUB_REPOSITORY_OWNER : Azure
85
- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
92
+ GITHUB_TOKEN : ${{ steps.app-token.outputs.token }}
86
93
87
94
- name : avm pre-commit
88
95
run : |
89
96
./avm pre-commit
90
- working-directory : ${{ matrix.repo }}
91
97
continue-on-error : true
92
98
env :
93
99
OVERRIDE_GITHUB_REPOSITORY : Azure/${{ matrix.repo }}
94
100
OVERRIDE_GITHUB_REPOSITORY_OWNER : Azure
95
- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
101
+ GITHUB_TOKEN : ${{ steps.app-token.outputs.token }}
96
102
97
103
- name : detect changes
98
104
id : changes
@@ -104,20 +110,18 @@ jobs:
104
110
fi
105
111
echo "Changes detected"
106
112
echo 'detected=true' >> "$GITHUB_OUTPUT"
107
- working-directory : ${{ matrix.repo }}
108
113
109
114
- name : commit changes to branch and push to origin
110
115
if : steps.changes.outputs.detected == 'true'
111
116
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]"
114
119
BRANCH="grept-apply-$(date +%s)"
115
120
echo "branch=$BRANCH" >> "$GITHUB_ENV"
116
121
git checkout -b "$BRANCH"
117
122
git add .
118
123
git commit -m "fix: grept apply"
119
124
git push --set-upstream origin "$BRANCH"
120
- working-directory : ${{ matrix.repo }}
121
125
122
126
- name : create PR body
123
127
if : steps.changes.outputs.detected == 'true'
@@ -135,14 +139,12 @@ jobs:
135
139
136
140
Thanks! The AVM team :heart:
137
141
EOF
138
- working-directory : ${{ matrix.repo }}
139
142
140
143
- name : show body
141
144
if : steps.changes.outputs.detected == 'true'
142
145
run : |
143
146
echo "Displaying PR body:"
144
147
cat prbody.md
145
- working-directory : ${{ matrix.repo }}
146
148
147
149
- name : create pull request
148
150
if : steps.changes.outputs.detected == 'true'
@@ -151,49 +153,17 @@ jobs:
151
153
PR_URL=$(gh pr create --title "chore: repository governance" --body-file prbody.md)
152
154
echo pull-request-number=$(gh pr view $PR_URL --json number | jq -r '.number') >> "$GITHUB_OUTPUT"
153
155
env :
154
- GH_TOKEN : ${{ secrets.USER_PAT }}
155
- working-directory : ${{ matrix.repo }}
156
+ GH_TOKEN : ${{ steps.app-token.outputs.token }}
156
157
157
158
- name : close and comment out of date prs
158
159
if : steps.changes.outputs.detected == 'true'
159
160
run : |
160
161
PULL_REQUESTS=$(gh pr list --search "chore: repository governance" --json number,headRefName)
161
162
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 }}"
162
163
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 }}
181
165
182
166
- name : sleep for rate limit
183
167
if : ${{ always() }}
184
168
id : sleep
185
169
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 }}
0 commit comments