-
Notifications
You must be signed in to change notification settings - Fork 40
277 lines (252 loc) · 9.86 KB
/
upload_results.reusable.yaml
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# Parse test results and
# Send upload notifications and
# Generate new snapshots via PR
name: Parse Test Results
on:
workflow_call:
inputs:
plugin-version:
required: false
type: string
results-prefix:
required: false
type: string
upload-validated-versions:
required: false
type: boolean
default: false
test-type:
required: false
type: string
default: linter
test-ref:
required: false
type: string
default: latest release
secrets:
TRUNKBOT_SLACK_BOT_TOKEN:
required: true
TRUNK_STAGING_API_TOKEN:
required: false
TRUNK_API_TOKEN:
required: false
TRUNK_OPEN_PR_APP_ID:
required: false
TRUNK_OPEN_PR_APP_PRIVATE_KEY:
required: false
TRUNK_SOURCERY_TOKEN:
required: false
TRUNK_DEBUGGER_TOKEN:
required: false
TRUNK_ORG_PROD_TOKEN:
required: false
permissions:
actions: write
contents: read
statuses: read
pull-requests: write
jobs:
upload_test_results:
name: Upload Test Results
runs-on: ubuntu-latest
timeout-minutes: 10
env:
SLACK_CHANNEL_ID: plugins-notifications
outputs:
reruns: ${{ steps.parse.outputs.reruns }}
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Retrieve Test Outputs ubuntu
id: download-ubuntu
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
continue-on-error: true
with:
name: ${{ inputs.results-prefix }}ubuntu-latest-test-results
- name: Retrieve Test Outputs macOS
id: download-macos
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
continue-on-error: true
with:
name: ${{ inputs.results-prefix }}macos-latest-test-results
- name: Retrieve Test Outputs Windows
id: download-windows
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
continue-on-error: true
with:
name: ${{ inputs.results-prefix }}windows-latest-test-results
- name: Print Test Outputs
continue-on-error: true
shell: bash
run: |
echo "::group::Ubuntu results"
cat "ubuntu-latest-res.json" || echo "missing"
echo "::endgroup::"
echo "::group::Macos results"
cat "macos-latest-res.json" || echo "missing"
echo "::endgroup::"
echo "::group::Windows results"
cat "windows-latest-res.json" || echo "missing"
echo "::endgroup::"
- name: Slack Notification For Missing Artifacts
uses: slackapi/slack-github-action@485a9d42d3a73031f12ec201c457e2162c45d02d # v2.0.0
if:
steps.download-ubuntu.outcome == 'failure' || steps.download-macos.outcome == 'failure' ||
steps.download-windows.outcome == 'failure'
with:
method: chat.postMessage
token: ${{ secrets.TRUNKBOT_SLACK_BOT_TOKEN }}
payload: |
channel: ${{ env.SLACK_CHANNEL_ID }}
text: "Artifact Download Failure"
blocks:
- type: section
text:
type: mrkdwn
text: "Failure: <https://github.com/trunk-io/plugins/actions/runs/${{ github.run_id }}| Unable to download some ${{ inputs.results-prefix }}test result artifacts (ubuntu: ${{ steps.download-ubuntu.outcome }}, macos: ${{ steps.download-macos.outcome }}, windows: ${{ steps.download-windows.outcome }}) >"
- name: Setup Node
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: 18
- name: Install Dependencies
shell: bash
run: npm ci
- name: Add npm bin to path
shell: bash
run: echo "$PWD/node_modules/.bin" >> "$GITHUB_PATH"
- name: Parse Test Results
shell: bash
continue-on-error: true
id: parse
run: |
npm run parse
echo "failures=$([[ -f failures.yaml ]] && echo "true" || echo "false")" >> "$GITHUB_OUTPUT"
failures_payload=$(cat failures.yaml)
printf "failures-payload<<EOF\n%s\nEOF\n" "$failures_payload" >> "$GITHUB_OUTPUT"
echo "reruns=$(cat reruns.txt)" >> "$GITHUB_OUTPUT"
env:
PLUGIN_VERSION: ${{ inputs.plugin-version }}
# Used to format Slack notification for failures
RUN_ID: ${{ github.run_id }}
TEST_REF: ${{ inputs.test-ref }}
TEST_TYPE: ${{ inputs.test-type }}
SLACK_CHANNEL_ID: ${{ env.SLACK_CHANNEL_ID }}
- name: Upload Test Results Staging
if: inputs.upload-validated-versions == true
continue-on-error: true
id: upload-staging
env:
TRUNK_API_TOKEN: ${{ secrets.TRUNK_STAGING_API_TOKEN }}
TRUNK_API_ADDRESS: api.trunk-staging.io:8443
# upload-linter-versions is a hidden command reserved exclusively for uploading
# validated results from the plugins repo.
# daemon must be restarted in order to propagate environment variable
shell: bash
run: |
trunk daemon shutdown
trunk upload-linter-versions --token="$TRUNK_API_TOKEN" results.json
- name: Upload Test Results Prod
if: inputs.upload-validated-versions == true
continue-on-error: true
id: upload-prod
env:
TRUNK_API_TOKEN: ${{ secrets.TRUNK_API_TOKEN }}
TRUNK_API_ADDRESS: api.trunk.io:8443
# upload-linter-versions is a hidden command reserved exclusively for uploading
# validated results from the plugins repo.
# daemon must be restarted in order to propagate environment variable
shell: bash
run: |
trunk daemon shutdown
trunk upload-linter-versions --token="$TRUNK_API_TOKEN" results.json
# Slack notifications
- name: Slack Notification For Failures
uses: slackapi/slack-github-action@485a9d42d3a73031f12ec201c457e2162c45d02d # v2.0.0
if: always() && steps.parse.outputs.failures == 'true'
with:
method: chat.postMessage
token: ${{ secrets.TRUNKBOT_SLACK_BOT_TOKEN }}
payload: ${{ steps.parse.outputs.failures-payload }}
- name: Slack Notification For Staging Upload Failure
uses: slackapi/slack-github-action@485a9d42d3a73031f12ec201c457e2162c45d02d # v2.0.0
if: inputs.upload-validated-versions == true && steps.upload-staging.outcome == 'failure'
with:
method: chat.postMessage
token: ${{ secrets.TRUNKBOT_SLACK_BOT_TOKEN }}
payload: |
channel: ${{ env.SLACK_CHANNEL_ID }}
text: "Upload Failure"
blocks:
- type: section
text:
type: mrkdwn
text: "Failure: <https://github.com/trunk-io/plugins/actions/runs/${{ github.run_id }}| Upload Test Results to Staging >"
- name: Slack Notification For Prod Upload Failure
uses: slackapi/slack-github-action@485a9d42d3a73031f12ec201c457e2162c45d02d # v2.0.0
if: inputs.upload-validated-versions == true && steps.upload-prod.outcome == 'failure'
with:
method: chat.postMessage
token: ${{ secrets.TRUNKBOT_SLACK_BOT_TOKEN }}
payload: |
channel: ${{ env.SLACK_CHANNEL_ID }}
text: "Upload Failure"
blocks:
- type: section
text:
type: mrkdwn
text: "Failure: <https://github.com/trunk-io/plugins/actions/runs/${{ github.run_id }}| Upload Test Results to Prod >"
generate_snapshots_pr:
name: Generate Snapshots PR
runs-on: ubuntu-latest
timeout-minutes: 30
needs: upload_test_results
if: needs.upload_test_results.outputs.reruns != ''
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Setup Node
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: 18
- name: Install Dependencies
shell: bash
run: npm ci
- name: Add npm bin to path
shell: bash
run: echo "$PWD/node_modules/.bin" >> "$GITHUB_PATH"
- name: Linter Tests Rerun Linux
uses: ./.github/actions/linter_tests
with:
linter-version: Latest
ref-type: main
append-args: ${{ needs.upload_test_results.outputs.reruns }} -- -u
sourcery-token: ${{ secrets.TRUNK_SOURCERY_TOKEN }}
trunk-staging-token: ${{ secrets.TRUNK_DEBUGGER_TOKEN }}
trunk-prod-token: ${{ secrets.TRUNK_ORG_PROD_TOKEN }}
env:
PLUGINS_TEST_UPDATE_SNAPSHOTS: "true"
- name: Mark generated snapshots as ready for release
shell: bash
run: |
git ls-files --others --exclude-standard | grep ".shot" | xargs sed -i '2i // trunk-upgrade-validation:RELEASE'
- name: Create App Token for TrunkBuild App (Internal)
uses: tibdex/github-app-token@v2
id: generate-token
with:
app_id: ${{ secrets.TRUNK_OPEN_PR_APP_ID }}
private_key: ${{ secrets.TRUNK_OPEN_PR_APP_PRIVATE_KEY }}
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
with:
title: Auto-add missing snapshots
body:
Create new snapshots from https://github.com/trunk-io/plugins/actions/runs/${{
github.run_id }}
base: main
branch: trunk-io/auto-update-snapshots
labels: trunk
add-paths: "**/*.shot"
commit-message: Auto add snapshots
delete-branch: true
token: ${{ steps.generate-token.outputs.token }}
reviewers: TylerJang27