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 8b365e1 commit c101d50
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
33 changes: 27 additions & 6 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,45 @@ 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}}"
# Here we compute a "taget 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=="${{ input.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"
4 changes: 4 additions & 0 deletions .github/workflows/selenium-lab-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ jobs:
uses: ./.github/workflows/custom-actions/set-commit-status
with:
context: Selenium / Build
job_name: 'Pre-build Player'
state: pending
token: ${{ secrets.GITHUB_TOKEN }}

Expand Down Expand Up @@ -186,6 +187,7 @@ jobs:
uses: ./.github/workflows/custom-actions/set-commit-status
with:
context: Selenium / Build
job_name: 'Pre-build Player'
state: ${{ job.status }}
token: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -210,6 +212,7 @@ jobs:
uses: ./.github/workflows/custom-actions/set-commit-status
with:
context: Selenium / ${{ matrix.browser }}
job_name: ${{ matrix.browser }}
state: pending
token: ${{ secrets.GITHUB_TOKEN }}

Expand Down Expand Up @@ -366,5 +369,6 @@ jobs:
uses: ./.github/workflows/custom-actions/set-commit-status
with:
context: Selenium / ${{ matrix.browser }}
job_name: ${{ matrix.browser }}
state: ${{ job.status }}
token: ${{ secrets.GITHUB_TOKEN }}
9 changes: 1 addition & 8 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 @@ -121,7 +114,7 @@ jobs:
if [ "$LAB_TEST_STATUS" == "success" ]; then
echo "status=$UPDATE_PR_STATUS" >> $GITHUB_OUTPUT
else
echo "status=$LAST_TEST_STATUS" >> $GITHUB_OUTPUT
echo "status=$LAB_TEST_STATUS" >> $GITHUB_OUTPUT
fi
- name: Report final status
Expand Down

0 comments on commit c101d50

Please sign in to comment.