Skip to content

Commit d98ed84

Browse files
lobsterkatieAbhiPrasad
authored andcommitted
ref(dev): Improve labeling of checkout step in GHA (#5156)
Currently, when looking at runs of our `Build & Test` GHA workflow, it's often hard to tell exactly what commit is being used. When the workflow is triggered by a push to a PR, the PR title ends up as the label, which can be pretty uninformative. Runs triggered manually are no better, as they're merely labeled "Build & Test." Runs triggered by pushes _are_ better, at least from the Actions tab, because they're labeled for their commit, but once you open one up, it's not obvious from the logs which commit is being used, since "Check out current commit (<some SHA here>)" doesn't actually list the branch's `HEAD` commit but rather a made-up merge commit between `HEAD` and the base branch, making it useless for identifying `HEAD`. (See the PR description for screenshots of these different cases.) This fixes that problem, by adding a preliminary GHA job to gather and store the SHA of the actual branch head (along with its commit message). Subsequent jobs can then use that information to label their checkout step, making it much easier to tell where in the commit history the job falls.
1 parent 9abca91 commit d98ed84

File tree

1 file changed

+48
-25
lines changed

1 file changed

+48
-25
lines changed

.github/workflows/build.yml

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,35 @@ env:
3838
BUILD_CACHE_KEY: ${{ github.event.inputs.commit || github.sha }}
3939

4040
jobs:
41+
job_get_metadata:
42+
name: Get Metadata
43+
runs-on: ubuntu-latest
44+
steps:
45+
- name: Check out current commit
46+
uses: actions/checkout@v2
47+
with:
48+
ref: ${{ env.HEAD_COMMIT }}
49+
# We need to check out not only the fake merge commit between the PR and the base branch which GH creates, but
50+
# also its parents, so that we can pull the commit message from the head commit of the PR
51+
fetch-depth: 2
52+
- name: Get metadata
53+
id: get_metadata
54+
# We need to try a number of different options for finding the head commit, because each kind of trigger event
55+
# stores it in a different location
56+
run: |
57+
COMMIT_SHA=$(git rev-parse --short ${{ github.event.pull_request.head.sha || github.event.head_commit.id || env.HEAD_COMMIT }})
58+
echo "COMMIT_SHA=$COMMIT_SHA" >> $GITHUB_ENV
59+
echo "COMMIT_MESSAGE=$(git log -n 1 --pretty=format:%s $COMMIT_SHA)" >> $GITHUB_ENV
60+
outputs:
61+
commit_label: "${{ env.COMMIT_SHA }}: ${{ env.COMMIT_MESSAGE }}"
62+
4163
job_install_deps:
4264
name: Install Dependencies
65+
needs: job_get_metadata
4366
runs-on: ubuntu-latest
4467
timeout-minutes: 15
4568
steps:
46-
- name: Check out current commit (${{ env.HEAD_COMMIT }})
69+
- name: "Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})"
4770
uses: actions/checkout@v2
4871
with:
4972
ref: ${{ env.HEAD_COMMIT }}
@@ -70,11 +93,11 @@ jobs:
7093

7194
job_build:
7295
name: Build
73-
needs: job_install_deps
96+
needs: [ job_get_metadata, job_install_deps ]
7497
runs-on: ubuntu-latest
7598
timeout-minutes: 20
7699
steps:
77-
- name: Check out current commit (${{ env.HEAD_COMMIT }})
100+
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
78101
uses: actions/checkout@v2
79102
with:
80103
ref: ${{ env.HEAD_COMMIT }}
@@ -150,13 +173,13 @@ jobs:
150173

151174
job_size_check:
152175
name: Size Check
153-
needs: job_build
176+
needs: [job_get_metadata, job_build]
154177
timeout-minutes: 15
155178
runs-on: ubuntu-latest
156179
# Size Check will error out outside of the context of a PR
157180
if: ${{ github.event_name == 'pull_request' }}
158181
steps:
159-
- name: Check out current commit (${{ env.HEAD_COMMIT }})
182+
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
160183
uses: actions/checkout@v2
161184
with:
162185
ref: ${{ env.HEAD_COMMIT }}
@@ -184,11 +207,11 @@ jobs:
184207

185208
job_lint:
186209
name: Lint
187-
needs: job_build
210+
needs: [job_get_metadata, job_build]
188211
timeout-minutes: 10
189212
runs-on: ubuntu-latest
190213
steps:
191-
- name: Check out current commit (${{ env.HEAD_COMMIT }})
214+
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
192215
uses: actions/checkout@v2
193216
with:
194217
ref: ${{ env.HEAD_COMMIT }}
@@ -211,11 +234,11 @@ jobs:
211234

212235
job_circular_dep_check:
213236
name: Circular Dependency Check
214-
needs: job_build
237+
needs: [job_get_metadata, job_build]
215238
timeout-minutes: 10
216239
runs-on: ubuntu-latest
217240
steps:
218-
- name: Check out current commit (${{ env.HEAD_COMMIT }})
241+
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
219242
uses: actions/checkout@v2
220243
with:
221244
ref: ${{ env.HEAD_COMMIT }}
@@ -238,12 +261,12 @@ jobs:
238261

239262
job_artifacts:
240263
name: Upload Artifacts
241-
needs: job_build
264+
needs: [job_get_metadata, job_build]
242265
runs-on: ubuntu-latest
243266
# Build artifacts are only needed for releasing workflow.
244267
if: startsWith(github.ref, 'refs/heads/release/')
245268
steps:
246-
- name: Check out current commit (${{ github.sha }})
269+
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
247270
uses: actions/checkout@v2
248271
with:
249272
ref: ${{ env.HEAD_COMMIT }}
@@ -275,15 +298,15 @@ jobs:
275298
276299
job_unit_test:
277300
name: Test (Node ${{ matrix.node }})
278-
needs: job_build
301+
needs: [job_get_metadata, job_build]
279302
continue-on-error: true
280303
timeout-minutes: 30
281304
runs-on: ubuntu-latest
282305
strategy:
283306
matrix:
284307
node: [8, 10, 12, 14, 16, 18]
285308
steps:
286-
- name: Check out current commit (${{ env.HEAD_COMMIT }})
309+
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
287310
uses: actions/checkout@v2
288311
with:
289312
ref: ${{ env.HEAD_COMMIT }}
@@ -312,15 +335,15 @@ jobs:
312335

313336
job_nextjs_integration_test:
314337
name: Test @sentry/nextjs on (Node ${{ matrix.node }})
315-
needs: job_build
338+
needs: [job_get_metadata, job_build]
316339
continue-on-error: true
317340
timeout-minutes: 30
318341
runs-on: ubuntu-latest
319342
strategy:
320343
matrix:
321344
node: [10, 12, 14, 16, 18]
322345
steps:
323-
- name: Check out current commit (${{ env.HEAD_COMMIT }})
346+
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
324347
uses: actions/checkout@v2
325348
with:
326349
ref: ${{ env.HEAD_COMMIT }}
@@ -349,12 +372,12 @@ jobs:
349372
# separate job allows them to run in parallel with the other tests.
350373
job_ember_tests:
351374
name: Test @sentry/ember
352-
needs: job_build
375+
needs: [job_get_metadata, job_build]
353376
continue-on-error: true
354377
timeout-minutes: 30
355378
runs-on: ubuntu-latest
356379
steps:
357-
- name: Check out current commit (${{ env.HEAD_COMMIT }})
380+
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
358381
uses: actions/checkout@v2
359382
with:
360383
ref: ${{ env.HEAD_COMMIT }}
@@ -388,7 +411,7 @@ jobs:
388411

389412
job_browser_playwright_tests:
390413
name: Playwright - ${{ (matrix.tracing_only && 'Browser + Tracing') || 'Browser' }} (${{ matrix.bundle }})
391-
needs: job_build
414+
needs: [job_get_metadata, job_build]
392415
runs-on: ubuntu-latest
393416
strategy:
394417
matrix:
@@ -410,7 +433,7 @@ jobs:
410433
- bundle: cjs
411434
tracing_only: false
412435
steps:
413-
- name: Check out current commit (${{ env.HEAD_COMMIT }})
436+
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
414437
uses: actions/checkout@v2
415438
with:
416439
ref: ${{ env.HEAD_COMMIT }}
@@ -439,7 +462,7 @@ jobs:
439462
440463
job_browser_integration_tests:
441464
name: Old Browser Integration Tests (${{ matrix.browser }})
442-
needs: job_build
465+
needs: [job_get_metadata, job_build]
443466
runs-on: ubuntu-latest
444467
timeout-minutes: 10
445468
continue-on-error: true
@@ -450,7 +473,7 @@ jobs:
450473
- FirefoxHeadless
451474
- WebkitHeadless
452475
steps:
453-
- name: Check out current commit (${{ env.HEAD_COMMIT }})
476+
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
454477
uses: actions/checkout@v2
455478
with:
456479
ref: ${{ env.HEAD_COMMIT }}
@@ -478,12 +501,12 @@ jobs:
478501
479502
job_browser_build_tests:
480503
name: Browser Build Tests
481-
needs: job_build
504+
needs: [job_get_metadata, job_build]
482505
runs-on: ubuntu-latest
483506
timeout-minutes: 5
484507
continue-on-error: true
485508
steps:
486-
- name: Check out current commit (${ env.HEAD_COMMIT }})
509+
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
487510
uses: actions/checkout@v2
488511
with:
489512
ref: ${{ env.HEAD_COMMIT }}
@@ -512,15 +535,15 @@ jobs:
512535
513536
job_node_integration_tests:
514537
name: Node SDK Integration Tests (${{ matrix.node }})
515-
needs: job_build
538+
needs: [job_get_metadata, job_build]
516539
runs-on: ubuntu-latest
517540
timeout-minutes: 10
518541
continue-on-error: true
519542
strategy:
520543
matrix:
521544
node: [10, 12, 14, 16, 18]
522545
steps:
523-
- name: Check out current commit (${{ github.sha }})
546+
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
524547
uses: actions/checkout@v2
525548
with:
526549
ref: ${{ env.HEAD_COMMIT }}

0 commit comments

Comments
 (0)