-
Notifications
You must be signed in to change notification settings - Fork 17
338 lines (301 loc) · 15.8 KB
/
Copy pathpr-comment-artifact-url.yml
File metadata and controls
338 lines (301 loc) · 15.8 KB
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# pr-comment-artifact-url.yml
---
name: Comment Artifact URL on PR
# Writes only the "build" section of the unified CI status comment via the
# ci-status-comment composite action (build / lint / tests live in one comment).
#
# 'requested' -> reset the build section to "pending" the moment a new build
# starts, so last build's download links never linger as stale.
# 'completed' -> fill the section back in: Success (with artifact links) /
# Failed / Skipped (no changes under Explorer/).
on:
workflow_run:
types:
- "requested"
- "completed"
workflows:
- "Unity Cloud Build"
branches-ignore:
- "main"
workflow_dispatch:
permissions:
contents: read
pull-requests: write
jobs:
pre-validation:
runs-on: ubuntu-latest
outputs:
pr-number: ${{ steps.check-pr.outputs.pr-number }}
steps:
- name: Check if PR number exists
id: check-pr
env:
WORKFLOW_RUN_EVENT_OBJ: ${{ toJSON(github.event.workflow_run) }}
run: |
PR_NUMBER=$(jq -r '.pull_requests[0].number' <<< "$WORKFLOW_RUN_EVENT_OBJ")
echo "Pull request Number: $PR_NUMBER"
if [[ -z "$PR_NUMBER" || "$PR_NUMBER" == "null" ]]; then
echo "PR_NUMBER is not set, skipping comment update."
exit 0
fi
echo "pr-number=$PR_NUMBER" >> $GITHUB_OUTPUT
comment-pending:
needs: pre-validation
if: github.event.action == 'requested' && needs.pre-validation.outputs.pr-number != ''
runs-on: ubuntu-latest
steps:
- name: Checkout CI status action
uses: actions/checkout@v6
with:
sparse-checkout: .github/actions/ci-status-comment
sparse-checkout-cone-mode: false
persist-credentials: false
- name: Reset build section to pending
uses: ./.github/actions/ci-status-comment
with:
pr-number: ${{ needs.pre-validation.outputs.pr-number }}
section: build
github-token: ${{ github.token }}
body: |-
[](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}) <img src="https://ui.decentraland.org/decentraland_256x256.png" width="30">
New build in progress, come back later!
check-build-ran:
needs: pre-validation
if: github.event.action == 'completed' && needs.pre-validation.outputs.pr-number != ''
runs-on: ubuntu-latest
outputs:
build-ran: ${{ steps.check.outputs.build-ran }}
player-artifacts: ${{ steps.check.outputs.player-artifacts }}
steps:
- name: Check if build jobs actually ran
id: check
env:
GITHUB_TOKEN: ${{ github.token }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
RUN_ID: ${{ github.event.workflow_run.id }}
run: |
# player-artifacts: Decentraland_* zips exist. comment-success interpolates
# their artifact ids into download URLs, so the success/skipped split must
# keep gating on this and only this.
# build-ran: any evidence a Unity-side build started. unity_build_info_* is
# uploaded as soon as the build id is known, so a build that failed before
# producing player artifacts still posts a failure comment (with the Unity
# Cloud link) instead of leaving the comment stuck on "Pending".
NAMES=$(gh api "/repos/$OWNER/$REPO/actions/runs/$RUN_ID/artifacts" \
--jq '[.artifacts[].name]')
PLAYER_COUNT=$(jq 'map(select(startswith("Decentraland_"))) | length' <<< "$NAMES")
INFO_COUNT=$(jq 'map(select(startswith("unity_build_info_"))) | length' <<< "$NAMES")
echo "Player artifact count: $PLAYER_COUNT; build info artifact count: $INFO_COUNT"
if [ "$PLAYER_COUNT" -gt 0 ]; then
echo "player-artifacts=true" >> "$GITHUB_OUTPUT"
else
echo "player-artifacts=false" >> "$GITHUB_OUTPUT"
fi
if [ "$PLAYER_COUNT" -gt 0 ] || [ "$INFO_COUNT" -gt 0 ]; then
echo "build-ran=true" >> "$GITHUB_OUTPUT"
else
echo "build-ran=false" >> "$GITHUB_OUTPUT"
fi
comment-skipped:
needs: [pre-validation, check-build-ran]
if: github.event.workflow_run.conclusion == 'success' && needs.pre-validation.outputs.pr-number != '' && needs.check-build-ran.outputs.player-artifacts == 'false'
runs-on: ubuntu-latest
steps:
- name: Checkout CI status action
uses: actions/checkout@v6
with:
sparse-checkout: .github/actions/ci-status-comment
sparse-checkout-cone-mode: false
persist-credentials: false
- name: Post skipped build section
uses: ./.github/actions/ci-status-comment
with:
pr-number: ${{ needs.pre-validation.outputs.pr-number }}
section: build
github-token: ${{ github.token }}
body: |-
[](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}) <img src="https://ui.decentraland.org/decentraland_256x256.png" width="30">
Build skipped — no changes detected under `Explorer/`.
comment-success:
needs: [pre-validation, check-build-ran]
if: github.event.workflow_run.conclusion == 'success' && needs.pre-validation.outputs.pr-number != '' && needs.check-build-ran.outputs.player-artifacts == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout CI status action
uses: actions/checkout@v6
with:
sparse-checkout: |
.github/actions/ci-status-comment
.github/actions/ucb-build-links
sparse-checkout-cone-mode: false
persist-credentials: false
- name: Get Artifact and Pull request info
env:
GITHUB_TOKEN: ${{ github.token }}
WORKFLOW_RUN_EVENT_OBJ: ${{ toJSON(github.event.workflow_run) }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
run: |
PREVIOUS_JOB_ID=$(jq -r '.id' <<< "$WORKFLOW_RUN_EVENT_OBJ")
echo "Previous Job ID: $PREVIOUS_JOB_ID"
echo "PREVIOUS_JOB_ID=$PREVIOUS_JOB_ID" >> "$GITHUB_ENV"
SUITE_ID=$(jq -r '.check_suite_id' <<< "$WORKFLOW_RUN_EVENT_OBJ")
echo "Previous Suite ID: $SUITE_ID"
echo "SUITE_ID=$SUITE_ID" >> "$GITHUB_ENV"
WINDOWS_ARTIFACT_ID=$(gh api "/repos/$OWNER/$REPO/actions/artifacts" \
--jq ".artifacts.[] |
select(.workflow_run.id==${PREVIOUS_JOB_ID}) |
select(.expired==false) |
select(.name==\"Decentraland_windows64\") |
.id")
echo "Windows Artifact ID: $WINDOWS_ARTIFACT_ID"
echo "WINDOWS_ARTIFACT_ID=$WINDOWS_ARTIFACT_ID" >> "$GITHUB_ENV"
MAC_ARTIFACT_ID=$(gh api "/repos/$OWNER/$REPO/actions/artifacts" \
--jq ".artifacts.[] |
select(.workflow_run.id==${PREVIOUS_JOB_ID}) |
select(.expired==false) |
select(.name==\"Decentraland_macos\") |
.id")
echo "Mac Artifact ID: $MAC_ARTIFACT_ID"
echo "MAC_ARTIFACT_ID=$MAC_ARTIFACT_ID" >> "$GITHUB_ENV"
ORIGINAL_EVENT=$(jq -r '.event' <<< "$WORKFLOW_RUN_EVENT_OBJ")
echo "Original Event: $ORIGINAL_EVENT"
HEAD_SHA=$(jq -r '.pull_requests[0].head.sha // .head_sha' <<< "$WORKFLOW_RUN_EVENT_OBJ")
echo "Head SHA: $HEAD_SHA"
echo "HEAD_SHA=$HEAD_SHA" >> "$GITHUB_ENV"
SHORT_SHA=$(echo "$HEAD_SHA" | cut -c1-7)
echo "Short SHA: $SHORT_SHA"
SAFE_BRANCH_NAME=$(jq -r '.pull_requests[0].head.ref // .head_branch' <<< "$WORKFLOW_RUN_EVENT_OBJ")
echo "Safe Branch Name: $SAFE_BRANCH_NAME"
echo "SAFE_BRANCH_NAME=$SAFE_BRANCH_NAME" >> "$GITHUB_ENV"
RUN_NUMBER=$(jq -r '.run_number' <<< "$WORKFLOW_RUN_EVENT_OBJ")
echo "Run number: $RUN_NUMBER"
echo "RUN_NUMBER=$RUN_NUMBER" >> "$GITHUB_ENV"
case "$ORIGINAL_EVENT" in
pull_request) BUILD_PREFIX="pr" ;;
push) BUILD_PREFIX="pu" ;;
merge_group) BUILD_PREFIX="mg" ;;
workflow_dispatch) BUILD_PREFIX="wd" ;;
workflow_call) BUILD_PREFIX="wc" ;;
schedule) BUILD_PREFIX="sc" ;;
*) BUILD_PREFIX="gn" ;;
esac
echo "Build Prefix: $BUILD_PREFIX"
ARTIFACT_S3_DESTINATION_PATH="@dcl/$REPO/branch/$SAFE_BRANCH_NAME/${BUILD_PREFIX}-${RUN_NUMBER}-${SHORT_SHA}"
echo "Artifact S3 Destination Path: $ARTIFACT_S3_DESTINATION_PATH"
echo "ARTIFACT_S3_DESTINATION_PATH=$ARTIFACT_S3_DESTINATION_PATH" >> "$GITHUB_ENV"
BUILD_DATE=$(jq -r '.updated_at' <<< "$WORKFLOW_RUN_EVENT_OBJ")
echo "Build done on: $BUILD_DATE"
echo "BUILD_DATE=$BUILD_DATE" >> "$GITHUB_ENV"
- name: Download size reports
env:
GITHUB_TOKEN: ${{ github.token }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
run: |
gh run download "$PREVIOUS_JOB_ID" \
--repo "$OWNER/$REPO" \
--name size_report_windows64_launcher \
--dir size_reports 2>/dev/null || true
gh run download "$PREVIOUS_JOB_ID" \
--repo "$OWNER/$REPO" \
--name size_report_macos_launcher \
--dir size_reports 2>/dev/null || true
WINDOWS_ROW=$(grep "^|" size_reports/size_report_windows64_launcher.md 2>/dev/null || true)
MACOS_ROW=$(grep "^|" size_reports/size_report_macos_launcher.md 2>/dev/null || true)
RELEASE_TAG=$(grep "^release_tag=" size_reports/size_report_windows64_launcher.md size_reports/size_report_macos_launcher.md 2>/dev/null | head -1 | cut -d= -f2 || true)
if [ -n "$WINDOWS_ROW" ] || [ -n "$MACOS_ROW" ]; then
{
echo "SIZE_REPORT<<EOF"
echo "### Artifact size check"
echo ""
echo "| Target | Size (MB / MiB) | Cap (MB) | Δ MB vs release | Δ % vs release | Result |"
echo "|--------|----------------:|--------:|----------------:|---------------:|--------|"
[ -n "$WINDOWS_ROW" ] && echo "$WINDOWS_ROW"
[ -n "$MACOS_ROW" ] && echo "$MACOS_ROW"
[ -n "$RELEASE_TAG" ] && echo "" && echo "_Comparing against: **${RELEASE_TAG}**_"
echo "EOF"
} >> "$GITHUB_ENV"
else
echo "SIZE_REPORT=" >> "$GITHUB_ENV"
fi
- name: Fetch Unity Cloud build links
id: ucb
uses: ./.github/actions/ucb-build-links
with:
run-id: ${{ env.PREVIOUS_JOB_ID }}
github-token: ${{ github.token }}
- name: Update build section
uses: ./.github/actions/ci-status-comment
with:
pr-number: ${{ needs.pre-validation.outputs.pr-number }}
section: build
github-token: ${{ github.token }}
body: |-
[](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ env.PREVIOUS_JOB_ID }}) <img src="https://ui.decentraland.org/decentraland_256x256.png" width="30">
Windows and Mac build successful in Unity Cloud! You can find a link to the downloadable artifact below.
| Name | Link |
| -------- | ----------------------- |
| Commit | ${{ env.HEAD_SHA }} |
| Logs | ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ env.PREVIOUS_JOB_ID }} |
| Download Windows | ${{ github.server_url }}/${{ github.repository }}/suites/${{ env.SUITE_ID }}/artifacts/${{ env.WINDOWS_ARTIFACT_ID }} |
| Download Windows S3 | ${{ format('{0}/{1}/Decentraland_windows64.zip', vars.EXPLORER_TEAM_S3_BUCKET_PUBLIC_URL, env.ARTIFACT_S3_DESTINATION_PATH) }} |
| Download Mac | ${{ github.server_url }}/${{ github.repository }}/suites/${{ env.SUITE_ID }}/artifacts/${{ env.MAC_ARTIFACT_ID }} |
| Download Mac S3 | ${{ format('{0}/{1}/Decentraland_macos.zip', vars.EXPLORER_TEAM_S3_BUCKET_PUBLIC_URL, env.ARTIFACT_S3_DESTINATION_PATH) }} |
| Built on | ${{ env.BUILD_DATE }} |
${{ steps.ucb.outputs.rows }}
${{ env.SIZE_REPORT }}
- name: Find latest release
env:
GITHUB_TOKEN: ${{ github.token }}
run: gh release view -R $GITHUB_REPOSITORY --json tagName --template "RELEASE_TAG={{.tagName}}" >> $GITHUB_ENV
- name: Trigger performance test
uses: peter-evans/repository-dispatch@v4
with:
repository: decentraland/performance-testing
event-type: unity-explorer
token: ${{ secrets.PERFORMANCE_TESTING_PAT }}
# Fork-controlled fields (display_title, and the branch name inside
# ARTIFACT_S3_DESTINATION_PATH) are wrapped in toJSON so they are JSON-escaped
# rather than spliced raw into the payload — a title/branch containing a quote
# can't break out of its string and inject or override other fields.
client-payload: |-
{
"run_name": ${{ toJSON(github.event.workflow_run.display_title) }},
"pr_number": "${{ needs.pre-validation.outputs.pr-number }}",
"win_change_build_url": ${{ toJSON(format('{0}/{1}/Decentraland_windows64.zip', vars.EXPLORER_TEAM_S3_BUCKET_PUBLIC_URL, env.ARTIFACT_S3_DESTINATION_PATH)) }},
"win_base_build_url": "${{ vars.EXPLORER_TEAM_S3_BUCKET_PUBLIC_URL }}/@dcl/unity-explorer/releases/${{ env.RELEASE_TAG }}/Decentraland_windows64.zip",
"mac_change_build_url": ${{ toJSON(format('{0}/{1}/Decentraland_macos.zip', vars.EXPLORER_TEAM_S3_BUCKET_PUBLIC_URL, env.ARTIFACT_S3_DESTINATION_PATH)) }},
"mac_base_build_url": "${{ vars.EXPLORER_TEAM_S3_BUCKET_PUBLIC_URL }}/@dcl/unity-explorer/releases/${{ env.RELEASE_TAG }}/Decentraland_macos.zip"
}
comment-failed:
needs: [pre-validation, check-build-ran]
if: github.event.workflow_run.conclusion == 'failure' && needs.pre-validation.outputs.pr-number != '' && needs.check-build-ran.outputs.build-ran == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout CI status action
uses: actions/checkout@v6
with:
sparse-checkout: |
.github/actions/ci-status-comment
.github/actions/ucb-build-links
sparse-checkout-cone-mode: false
persist-credentials: false
- name: Fetch Unity Cloud build links
id: ucb
uses: ./.github/actions/ucb-build-links
with:
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ github.token }}
- name: Update build section
uses: ./.github/actions/ci-status-comment
with:
pr-number: ${{ needs.pre-validation.outputs.pr-number }}
section: build
github-token: ${{ github.token }}
body: |-
[](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}) <img src="https://ui.decentraland.org/decentraland_256x256.png" width="30">
Build failed! Check the [logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}) to see what went wrong.
If the error repeats please consider the `clean-build` tag.
${{ steps.ucb.outputs.section }}