generated from snout-router/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 1
206 lines (181 loc) · 10.6 KB
/
renovate-terraform.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
name: Renovate Terraform
on: status
jobs:
collect_details:
name: Collect details
runs-on: ubuntu-latest
outputs:
branch: ${{ steps.event.outputs.branch }}
commit_author: ${{ steps.event.outputs.commit_author }}
commit_sha: ${{ steps.event.outputs.commit_sha }}
context: ${{ steps.event.outputs.context }}
description: ${{ steps.event.outputs.description }}
pr_is_draft: ${{ steps.pr.outputs.pr_is_draft }}
pr_labels: ${{ steps.pr.outputs.pr_labels }}
pr_mergeable: ${{ steps.pr.outputs.pr_mergeable }}
pr_number: ${{ steps.pr.outputs.pr_number }}
sender: ${{ steps.event.outputs.sender }}
state: ${{ steps.event.outputs.state }}
verified: ${{ steps.event.outputs.verified }}
steps:
- name: Obtain token
id: token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.RENOVATE_APP_ID }}
private_key: ${{ secrets.RENOVATE_APP_PK }}
- name: Event details
id: event
run: |
echo "branch=${{ github.event.branches[0].name }}" >> $GITHUB_OUTPUT
echo "commit_author=${{ github.event.commit.author.login }}" >> $GITHUB_OUTPUT
echo "commit_sha=${{ github.event.sha }}" >> $GITHUB_OUTPUT
echo "context=${{ github.event.context }}" >> $GITHUB_OUTPUT
echo "description=${{ github.event.description }}" >> $GITHUB_OUTPUT
echo "sender=${{ github.event.sender.login }}" >> $GITHUB_OUTPUT
echo "state=${{ github.event.state }}" >> $GITHUB_OUTPUT
echo "verified=${{ github.event.commit.commit.verification.verified }}" >> $GITHUB_OUTPUT
- name: Pull request details
if: >-
startsWith(steps.event.outputs.branch, 'renovate/') &&
steps.event.outputs.commit_author == 'snout-router-renovate[bot]' &&
steps.event.outputs.context == 'Terraform Cloud/snout-router/repos' &&
steps.event.outputs.description == 'Terraform plan has no changes' &&
steps.event.outputs.sender == 'terraform-cloud[bot]' &&
steps.event.outputs.state == 'success' &&
steps.event.outputs.verified == 'true'
id: pr
env:
GITHUB_TOKEN: ${{ steps.token.outputs.token }}
run: |
PR=$(
gh pr list \
--repo "$GITHUB_REPOSITORY" \
--author app/snout-router-renovate \
--state OPEN \
--json author,isDraft,labels,mergeable,number \
--search '${{ steps.event.outputs.commit_sha }}'
)
echo "pr_is_draft=$(echo $PR | jq -r '.[0].isDraft')" >> $GITHUB_OUTPUT
echo "pr_labels=$(echo $PR | jq -c -r '.[0].labels | map(.name)')" >> $GITHUB_OUTPUT
echo "pr_mergeable=$(echo $PR | jq -r '.[0].mergeable')" >> $GITHUB_OUTPUT
echo "pr_number=$(echo $PR | jq -r '.[0].number')" >> $GITHUB_OUTPUT
output_details:
name: Output details
runs-on: ubuntu-latest
needs: collect_details
steps:
- name: Details
run: |
echo "branch=${{ needs.collect_details.outputs.branch }}"
echo "commit_author=${{ needs.collect_details.outputs.commit_author }}"
echo "commit_sha=${{ needs.collect_details.outputs.commit_sha }}"
echo "context=${{ needs.collect_details.outputs.context }}"
echo "description=${{ needs.collect_details.outputs.description }}"
echo "pr_is_draft=${{ needs.collect_details.outputs.pr_is_draft }}"
echo "pr_labels=${{ needs.collect_details.outputs.pr_labels }}"
echo "pr_mergeable=${{ needs.collect_details.outputs.pr_mergeable }}"
echo "pr_number=${{ needs.collect_details.outputs.pr_number }}"
echo "sender=${{ needs.collect_details.outputs.sender }}"
echo "state=${{ needs.collect_details.outputs.state }}"
echo "verified=${{ needs.collect_details.outputs.verified }}"
analyze_details:
name: Analyze details
runs-on: ubuntu-latest
needs: collect_details
outputs:
branch: ${{ steps.analyze_details.outputs.branch }}
commit_author: ${{ steps.analyze_details.outputs.commit_author }}
context: ${{ steps.analyze_details.outputs.context }}
description: ${{ steps.analyze_details.outputs.description }}
pr_is_draft: ${{ steps.analyze_details.outputs.pr_is_draft }}
pr_labels: ${{ steps.analyze_details.outputs.pr_labels }}
pr_mergeable: ${{ steps.analyze_details.outputs.pr_mergeable }}
sender: ${{ steps.analyze_details.outputs.sender }}
state: ${{ steps.analyze_details.outputs.state }}
verified: ${{ steps.analyze_details.outputs.verified }}
should_merge: ${{ steps.analyze_auto_merge.outputs.should_merge }}
steps:
- name: Analyze details
id: analyze_details
run: |
echo "branch=${{ startsWith(needs.collect_details.outputs.branch, 'renovate/') }}" >> $GITHUB_OUTPUT
echo "commit_author=${{ needs.collect_details.outputs.commit_author == 'snout-router-renovate[bot]' }}" >> $GITHUB_OUTPUT
echo "context=${{ needs.collect_details.outputs.context == 'Terraform Cloud/snout-router/repos' }}" >> $GITHUB_OUTPUT
echo "description=${{ needs.collect_details.outputs.description == 'Terraform plan has no changes' }}" >> $GITHUB_OUTPUT
echo "pr_is_draft=${{ needs.collect_details.outputs.pr_is_draft == 'false' }}" >> $GITHUB_OUTPUT
echo "pr_labels=${{ needs.collect_details.outputs.pr_labels && contains(fromJSON(needs.collect_details.outputs.pr_labels), 'renovate') && contains(fromJSON(needs.collect_details.outputs.pr_labels), 'terraform') }}" >> $GITHUB_OUTPUT
echo "pr_mergeable=${{ needs.collect_details.outputs.pr_mergeable == 'MERGEABLE' }}" >> $GITHUB_OUTPUT
echo "sender=${{ needs.collect_details.outputs.sender == 'terraform-cloud[bot]' }}" >> $GITHUB_OUTPUT
echo "state=${{ needs.collect_details.outputs.state == 'success' }}" >> $GITHUB_OUTPUT
echo "verified=${{ needs.collect_details.outputs.verified == 'true' }}" >> $GITHUB_OUTPUT
- name: Analyze auto-merge
id: analyze_auto_merge
run: |
echo "should_merge=${{
steps.analyze_details.outputs.branch == 'true' &&
steps.analyze_details.outputs.commit_author == 'true' &&
steps.analyze_details.outputs.context == 'true' &&
steps.analyze_details.outputs.description == 'true' &&
steps.analyze_details.outputs.pr_is_draft == 'true' &&
steps.analyze_details.outputs.pr_labels == 'true' &&
steps.analyze_details.outputs.pr_mergeable == 'true' &&
steps.analyze_details.outputs.sender == 'true' &&
steps.analyze_details.outputs.state == 'true' &&
steps.analyze_details.outputs.verified == 'true'
}}" >> $GITHUB_OUTPUT
analyze_auto_merge:
name: Renovate Terraform auto-merge analysis
runs-on: ubuntu-latest
needs:
- collect_details
- analyze_details
steps:
- name: Summarize
run: |
if [[ '${{ needs.analyze_details.outputs.should_merge }}' == 'true' ]]; then
echo "### Renovate Terraform auto-merge ✅" >> $GITHUB_STEP_SUMMARY
else
echo "### Renovate Terraform auto-merge 💤" >> $GITHUB_STEP_SUMMARY
fi
echo >> $GITHUB_STEP_SUMMARY
echo '| Field | Match | Wanted | Got |' >> $GITHUB_STEP_SUMMARY
echo '| :-- | :--: | :-- | :-- |' >> $GITHUB_STEP_SUMMARY
echo '| Branch | ${{ needs.analyze_details.outputs.branch == 'true' && '✅' || '❌' }} | Starts with `renovate/` | `${{ needs.collect_details.outputs.branch || '<null>' }}` |' >> $GITHUB_STEP_SUMMARY
echo '| Commit author | ${{ needs.analyze_details.outputs.commit_author == 'true' && '✅' || '❌' }} | `snout-router-renovate[bot]` | `${{ needs.collect_details.outputs.commit_author || '<null>' }}` |' >> $GITHUB_STEP_SUMMARY
echo '| Context | ${{ needs.analyze_details.outputs.context == 'true' && '✅' || '❌' }} | `Terraform Cloud/snout-router/repos` | `${{ needs.collect_details.outputs.context || '<null>' }}` |' >> $GITHUB_STEP_SUMMARY
echo '| Description | ${{ needs.analyze_details.outputs.description == 'true' && '✅' || '❌' }} | `Terraform plan has no changes` | `${{ needs.collect_details.outputs.description || '<null>' }}` |' >> $GITHUB_STEP_SUMMARY
echo '| PR is draft | ${{ needs.analyze_details.outputs.pr_is_draft == 'true' && '✅' || '❌' }} | `false` | `${{ needs.collect_details.outputs.pr_is_draft || '<null>' }}` |' >> $GITHUB_STEP_SUMMARY
echo '| PR labels | ${{ needs.analyze_details.outputs.pr_labels == 'true' && '✅' || '❌' }} | `["renovate","terraform"]` | `${{ needs.collect_details.outputs.pr_labels || '<null>' }}` |' >> $GITHUB_STEP_SUMMARY
echo '| PR mergeable | ${{ needs.analyze_details.outputs.pr_mergeable == 'true' && '✅' || '❌' }} | `MERGEABLE` | `${{ needs.collect_details.outputs.pr_mergeable || '<null>' }}` |' >> $GITHUB_STEP_SUMMARY
echo '| Sender | ${{ needs.analyze_details.outputs.sender == 'true' && '✅' || '❌' }} | `terraform-cloud[bot]` | `${{ needs.collect_details.outputs.sender || '<null>' }}` |' >> $GITHUB_STEP_SUMMARY
echo '| State | ${{ needs.analyze_details.outputs.state == 'true' && '✅' || '❌' }} | `success` | `${{ needs.collect_details.outputs.state || '<null>' }}` |' >> $GITHUB_STEP_SUMMARY
echo '| Verified | ${{ needs.analyze_details.outputs.verified == 'true' && '✅' || '❌' }} | `true` | `${{ needs.collect_details.outputs.verified || '<null>' }}` |' >> $GITHUB_STEP_SUMMARY
automerge:
name: Auto-merge
runs-on: ubuntu-latest
needs:
- collect_details
- analyze_details
if: needs.analyze_details.outputs.should_merge == 'true'
steps:
- name: Obtain token
id: token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.RENOVATE_APP_ID }}
private_key: ${{ secrets.RENOVATE_APP_PK }}
- name: Merge
env:
GITHUB_TOKEN: ${{ steps.token.outputs.token }}
run: |
gh pr comment \
--repo "$GITHUB_REPOSITORY" \
--body 'Looks like the Terraform plan has no changes, so this PR will be merged automatically.' \
'${{ needs.collect_details.outputs.pr_number }}'
gh pr merge \
--repo "$GITHUB_REPOSITORY" \
--match-head-commit '${{ needs.collect_details.outputs.commit_sha }}' \
--merge \
--delete-branch \
'${{ needs.collect_details.outputs.pr_number }}'