Skip to content

Commit d66393e

Browse files
committed
wip: Set full job ID
1 parent 9df1a1f commit d66393e

File tree

3 files changed

+49
-23
lines changed

3 files changed

+49
-23
lines changed

.github/workflows/custom-actions/set-commit-status/action.yaml

+27-6
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,45 @@ inputs:
1414
token:
1515
description: A GitHub access token.
1616
required: true
17+
job_name:
18+
description: A job name, so that the status' target URL can point to a specific job.
19+
required: false
1720

1821
runs:
1922
using: composite
2023
steps:
2124
- name: Report Commit Status
2225
shell: bash
2326
run: |
24-
# This is the URL to view this workflow run on GitHub. It will be
25-
# attached to the commit status, so that when someone clicks "details"
26-
# next to the status on the PR, it will link to this run where they can
27-
# see the logs.
28-
RUN_URL="https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
27+
# Here we compute a "target URL". It will be attached to the commit
28+
# status, so that when someone clicks "details" next to the status on
29+
# the PR, it will link to the appropriate logs.
30+
if [[ "${{ inputs.job_name }}" != "" ]]; then
31+
# There are three identifiers for the job:
32+
# - The job's key in YAML, which is "github.job"
33+
# - The job's name, which is not provided by any runner environment
34+
# - The job's numerical ID, which is not provided either
35+
# To link to this specific job in the status, we need the numerical
36+
# job ID. The GH API provides a list of jobs, which contain
37+
# numerical IDs and names, but not keys. So the caller of this
38+
# action must provide the string name, and then we look up the
39+
# numerical ID in the API. "github.job" is useless here.
40+
job_id=$(
41+
gh api /repos/${{github.repository}}/actions/runs/${{github.run_id}}/jobs \
42+
| jq '.jobs | map(select(.name=="${{ inputs.job_name }}")) | .[].id'
43+
)
44+
TARGET_URL="https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}/job/$job_id"
45+
else
46+
# Generic link to the run, without any specific job.
47+
TARGET_URL="https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
48+
fi
49+
2950
SHA1=$(git rev-parse HEAD)
3051
3152
GITHUB_TOKEN=${{ inputs.token }} \
3253
gh api \
3354
-X POST \
3455
-F "context=${{ inputs.context }}" \
3556
-F "state=${{ inputs.state }}" \
36-
-F "target_url=$RUN_URL" \
57+
-F "target_url=$TARGET_URL" \
3758
"repos/${{ github.repository }}/statuses/$SHA1"

.github/workflows/selenium-lab-tests.yaml

+21-9
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,17 @@ on:
3131
required: false
3232
type: string
3333
ignore_test_status:
34-
description: "If true, ignore test success or failure, never set the commit status, and always upload screenshots."
34+
description: "If true, ignore test success or failure, and always upload screenshots."
3535
required: false
3636
type: boolean
37+
skip_commit_status:
38+
description: "If true, skip the commit status."
39+
required: false
40+
type: boolean
41+
token:
42+
description: "A GitHub token used to set commit status."
43+
required: false
44+
type: string
3745
schedule:
3846
# Runs every night at 2am PST / 10am UTC, testing against the main branch.
3947
- cron: '0 10 * * *'
@@ -138,12 +146,13 @@ jobs:
138146
ref: ${{ needs.compute-ref.outputs.REF }}
139147

140148
- name: Set commit status to pending
141-
if: ${{ inputs.ignore_test_status == false }}
149+
if: ${{ inputs.skip_test_status == false }}
142150
uses: ./.github/workflows/custom-actions/set-commit-status
143151
with:
144152
context: Selenium / Build
153+
job_name: 'Pre-build Player'
145154
state: pending
146-
token: ${{ secrets.GITHUB_TOKEN }}
155+
token: ${{ inputs.token || secrets.GITHUB_TOKEN }}
147156

148157
- name: Build Player
149158
run: python3 build/all.py
@@ -182,12 +191,13 @@ jobs:
182191
- name: Report final commit status
183192
# Will run on success or failure, but not if the workflow is cancelled
184193
# or if we were asked to ignore the test status.
185-
if: ${{ (success() || failure()) && inputs.ignore_test_status == false }}
194+
if: ${{ (success() || failure()) && inputs.skip_commit_status == false }}
186195
uses: ./.github/workflows/custom-actions/set-commit-status
187196
with:
188197
context: Selenium / Build
198+
job_name: 'Pre-build Player'
189199
state: ${{ job.status }}
190-
token: ${{ secrets.GITHUB_TOKEN }}
200+
token: ${{ inputs.token || secrets.GITHUB_TOKEN }}
191201

192202
lab-tests:
193203
# This is a self-hosted runner in a Docker container, with access to our
@@ -206,12 +216,13 @@ jobs:
206216
ref: ${{ needs.compute-ref.outputs.REF }}
207217

208218
- name: Set commit status to pending
209-
if: ${{ inputs.ignore_test_status == false }}
219+
if: ${{ inputs.skip_commit_status == false }}
210220
uses: ./.github/workflows/custom-actions/set-commit-status
211221
with:
212222
context: Selenium / ${{ matrix.browser }}
223+
job_name: ${{ matrix.browser }}
213224
state: pending
214-
token: ${{ secrets.GITHUB_TOKEN }}
225+
token: ${{ inputs.token || secrets.GITHUB_TOKEN }}
215226

216227
- uses: actions/setup-node@v4
217228
with:
@@ -362,9 +373,10 @@ jobs:
362373
- name: Report final commit status
363374
# Will run on success or failure, but not if the workflow is cancelled
364375
# or if we were asked to ignore the test status.
365-
if: ${{ (success() || failure()) && inputs.ignore_test_status == false }}
376+
if: ${{ (success() || failure()) && inputs.skip_commit_status == false }}
366377
uses: ./.github/workflows/custom-actions/set-commit-status
367378
with:
368379
context: Selenium / ${{ matrix.browser }}
380+
job_name: ${{ matrix.browser }}
369381
state: ${{ job.status }}
370-
token: ${{ secrets.GITHUB_TOKEN }}
382+
token: ${{ inputs.token || secrets.GITHUB_TOKEN }}

.github/workflows/update-screenshots.yaml

+1-8
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,6 @@ jobs:
4545
with:
4646
ref: refs/pull/${{ inputs.pr }}/head
4747

48-
- name: Set commit status to pending
49-
uses: ./.github/workflows/custom-actions/set-commit-status
50-
with:
51-
context: Update All Screenshots
52-
state: pending
53-
token: ${{ secrets.GITHUB_TOKEN }}
54-
5548
- name: Get artifacts
5649
uses: actions/download-artifact@v4
5750
with:
@@ -116,7 +109,7 @@ jobs:
116109
if [ "$LAB_TEST_STATUS" == "success" ]; then
117110
echo "status=$UPDATE_PR_STATUS" >> $GITHUB_OUTPUT
118111
else
119-
echo "status=$LAST_TEST_STATUS" >> $GITHUB_OUTPUT
112+
echo "status=$LAB_TEST_STATUS" >> $GITHUB_OUTPUT
120113
fi
121114
122115
- name: Report final status

0 commit comments

Comments
 (0)