Skip to content

Commit

Permalink
wip: Set full job ID
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyparrish committed Feb 27, 2024
1 parent 9df1a1f commit 1408fcf
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 28 deletions.
36 changes: 29 additions & 7 deletions .github/workflows/custom-actions/set-commit-status/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,46 @@ inputs:
token:
description: A GitHub access token.
required: true
job_name:
description: A job name, so that the status' target URL can point to a specific job.
required: false

runs:
using: composite
steps:
- name: Report Commit Status
shell: bash
run: |
# This is the URL to view this workflow run on GitHub. It will be
# attached to the commit status, so that when someone clicks "details"
# next to the status on the PR, it will link to this run where they can
# see the logs.
RUN_URL="https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
export GITHUB_TOKEN="${{ inputs.token }}"
# Here we compute a "target URL". It will be attached to the commit
# status, so that when someone clicks "details" next to the status on
# the PR, it will link to the appropriate logs.
if [[ "${{ inputs.job_name }}" != "" ]]; then
# There are three identifiers for the job:
# - The job's key in YAML, which is "github.job"
# - The job's name, which is not provided by any runner environment
# - The job's numerical ID, which is not provided either
# To link to this specific job in the status, we need the numerical
# job ID. The GH API provides a list of jobs, which contain
# numerical IDs and names, but not keys. So the caller of this
# action must provide the string name, and then we look up the
# numerical ID in the API. "github.job" is useless here.
job_id=$(
gh api /repos/${{github.repository}}/actions/runs/${{github.run_id}}/jobs \
| jq '.jobs | map(select(.name=="${{ inputs.job_name }}")) | .[].id'
)
TARGET_URL="https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}/job/$job_id"
else
# Generic link to the run, without any specific job.
TARGET_URL="https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
fi
SHA1=$(git rev-parse HEAD)
GITHUB_TOKEN=${{ inputs.token }} \
gh api \
-X POST \
-F "context=${{ inputs.context }}" \
-F "state=${{ inputs.state }}" \
-F "target_url=$RUN_URL" \
-F "target_url=$TARGET_URL" \
"repos/${{ github.repository }}/statuses/$SHA1"
30 changes: 21 additions & 9 deletions .github/workflows/selenium-lab-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,17 @@ on:
required: false
type: string
ignore_test_status:
description: "If true, ignore test success or failure, never set the commit status, and always upload screenshots."
description: "If true, ignore test success or failure, and always upload screenshots."
required: false
type: boolean
skip_commit_status:
description: "If true, skip the commit status."
required: false
type: boolean
token:
description: "A GitHub token used to set commit status."
required: false
type: string
schedule:
# Runs every night at 2am PST / 10am UTC, testing against the main branch.
- cron: '0 10 * * *'
Expand Down Expand Up @@ -138,12 +146,13 @@ jobs:
ref: ${{ needs.compute-ref.outputs.REF }}

- name: Set commit status to pending
if: ${{ inputs.ignore_test_status == false }}
if: ${{ inputs.skip_test_status == false }}
uses: ./.github/workflows/custom-actions/set-commit-status
with:
context: Selenium / Build
job_name: 'Pre-build Player'
state: pending
token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ inputs.token || secrets.GITHUB_TOKEN }}

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

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

- name: Set commit status to pending
if: ${{ inputs.ignore_test_status == false }}
if: ${{ inputs.skip_commit_status == false }}
uses: ./.github/workflows/custom-actions/set-commit-status
with:
context: Selenium / ${{ matrix.browser }}
job_name: ${{ matrix.browser }}
state: pending
token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ inputs.token || secrets.GITHUB_TOKEN }}

- uses: actions/setup-node@v4
with:
Expand Down Expand Up @@ -362,9 +373,10 @@ jobs:
- name: Report final commit status
# Will run on success or failure, but not if the workflow is cancelled
# or if we were asked to ignore the test status.
if: ${{ (success() || failure()) && inputs.ignore_test_status == false }}
if: ${{ (success() || failure()) && inputs.skip_commit_status == false }}
uses: ./.github/workflows/custom-actions/set-commit-status
with:
context: Selenium / ${{ matrix.browser }}
job_name: ${{ matrix.browser }}
state: ${{ job.status }}
token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ inputs.token || secrets.GITHUB_TOKEN }}
19 changes: 7 additions & 12 deletions .github/workflows/update-screenshots.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ jobs:
with:
ref: refs/pull/${{ inputs.pr }}/head

- name: Set commit status to pending
uses: ./.github/workflows/custom-actions/set-commit-status
with:
context: Update All Screenshots
state: pending
token: ${{ secrets.GITHUB_TOKEN }}

- name: Get artifacts
uses: actions/download-artifact@v4
with:
Expand Down Expand Up @@ -111,12 +104,14 @@ jobs:
LAB_TEST_STATUS="${{ needs.run-lab-tests.status }}"
UPDATE_PR_STATUS="${{ needs.update-pr.status }}"
# If run-lab-tests succeeded, use the status of update-pr, otherwise
# use run-lab-tests (which is "failed" or "error").
if [ "$LAB_TEST_STATUS" == "success" ]; then
echo "status=$UPDATE_PR_STATUS" >> $GITHUB_OUTPUT
if [[ "$LAB_TEST_STATUS" == "success" ]]; then
# If run-lab-tests succeeded, use the status of update-pr.
# If that is blank, default to "error".
echo "status=${UPDATE_PR_STATUS:-error}" >> $GITHUB_OUTPUT
else
echo "status=$LAST_TEST_STATUS" >> $GITHUB_OUTPUT
# If lab status is not success, use that status.
# If that is blank, default to "error".
echo "status=${LAB_TEST_STATUS:-error}" >> $GITHUB_OUTPUT
fi
- name: Report final status
Expand Down

0 comments on commit 1408fcf

Please sign in to comment.