Skip to content

Commit 026966f

Browse files
committed
wip: Set full job ID
1 parent 543dafc commit 026966f

File tree

3 files changed

+54
-24
lines changed

3 files changed

+54
-24
lines changed

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

+29-7
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,46 @@ 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+
export GITHUB_TOKEN="${{ inputs.token }}"
28+
29+
# Here we compute a "target URL". It will be attached to the commit
30+
# status, so that when someone clicks "details" next to the status on
31+
# the PR, it will link to the appropriate logs.
32+
if [[ "${{ inputs.job_name }}" != "" ]]; then
33+
# There are three identifiers for the job:
34+
# - The job's key in YAML, which is "github.job"
35+
# - The job's name, which is not provided by any runner environment
36+
# - The job's numerical ID, which is not provided either
37+
# To link to this specific job in the status, we need the numerical
38+
# job ID. The GH API provides a list of jobs, which contain
39+
# numerical IDs and names, but not keys. So the caller of this
40+
# action must provide the string name, and then we look up the
41+
# numerical ID in the API. "github.job" is useless here.
42+
job_id=$(
43+
gh api /repos/${{github.repository}}/actions/runs/${{github.run_id}}/jobs \
44+
| jq '.jobs | map(select(.name=="${{ inputs.job_name }}")) | .[].id'
45+
)
46+
TARGET_URL="https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}/job/$job_id"
47+
else
48+
# Generic link to the run, without any specific job.
49+
TARGET_URL="https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
50+
fi
51+
2952
SHA1=$(git rev-parse HEAD)
3053
31-
GITHUB_TOKEN=${{ inputs.token }} \
3254
gh api \
3355
-X POST \
3456
-F "context=${{ inputs.context }}" \
3557
-F "state=${{ inputs.state }}" \
36-
-F "target_url=$RUN_URL" \
58+
-F "target_url=$TARGET_URL" \
3759
"repos/${{ github.repository }}/statuses/$SHA1"

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

+17-5
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+
job_name_prefix:
42+
description: "A prefix added to the job name when setting commit status. Use when skip_commit_status is false."
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,10 +146,11 @@ 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: "${{ inputs.job_name_prefix }}Pre-build Player"
145154
state: pending
146155
token: ${{ secrets.GITHUB_TOKEN }}
147156

@@ -182,10 +191,11 @@ 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: "${{ inputs.job_name_prefix }}Pre-build Player"
189199
state: ${{ job.status }}
190200
token: ${{ secrets.GITHUB_TOKEN }}
191201

@@ -206,10 +216,11 @@ 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: "${{ inputs.job_name_prefix }}${{ matrix.browser }}"
213224
state: pending
214225
token: ${{ secrets.GITHUB_TOKEN }}
215226

@@ -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: "${{ inputs.job_name_prefix }}${{ matrix.browser }}"
369381
state: ${{ job.status }}
370382
token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/update-screenshots.yaml

+8-12
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
pr: ${{ inputs.pr }}
3636
test_filter: layout
3737
ignore_test_status: true
38+
job_name_prefix: "Get Selenium Lab Screenshots / "
3839

3940
update-pr:
4041
name: Update PR
@@ -45,13 +46,6 @@ jobs:
4546
with:
4647
ref: refs/pull/${{ inputs.pr }}/head
4748

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-
5549
- name: Get artifacts
5650
uses: actions/download-artifact@v4
5751
with:
@@ -111,12 +105,14 @@ jobs:
111105
LAB_TEST_STATUS="${{ needs.run-lab-tests.status }}"
112106
UPDATE_PR_STATUS="${{ needs.update-pr.status }}"
113107
114-
# If run-lab-tests succeeded, use the status of update-pr, otherwise
115-
# use run-lab-tests (which is "failed" or "error").
116-
if [ "$LAB_TEST_STATUS" == "success" ]; then
117-
echo "status=$UPDATE_PR_STATUS" >> $GITHUB_OUTPUT
108+
if [[ "$LAB_TEST_STATUS" == "success" ]]; then
109+
# If run-lab-tests succeeded, use the status of update-pr.
110+
# If that is blank, default to "error".
111+
echo "status=${UPDATE_PR_STATUS:-error}" >> $GITHUB_OUTPUT
118112
else
119-
echo "status=$LAST_TEST_STATUS" >> $GITHUB_OUTPUT
113+
# If lab status is not success, use that status.
114+
# If that is blank, default to "error".
115+
echo "status=${LAB_TEST_STATUS:-error}" >> $GITHUB_OUTPUT
120116
fi
121117
122118
- name: Report final status

0 commit comments

Comments
 (0)