Getting the check_run_id in GitHub Actions

I have a usecase where I want to get check_run_id for each job while writing configuration files.
(e.g. send notifications for each jobs’ results with links… https://github.com/org/repo/pull/123/checks?check_run_id=952405280)

We have ${{ github.run_id }}, but it is for the workflow, not for each jobs.

Is there anyway to get check_run_id?
(If there’s no way, I think supporting check_run_id is good for others :slight_smile:)

Hi @hiddenest,

Glad to see you in Github Community Forum!

For pull requst check_run_id for each job, you can get it in this way:

  1. based on the ${{ github.run_id}}, use rest api to get the check_suite_url.
    https://developer.github.com/v3/actions/workflow-runs/#get-a-workflow-run
  2. Based on the check_suite_url, get the check_run_id via rest api: https://developer.github.com/v3/checks/runs/#list-check-runs-in-a-check-suite

Code sample as below:

jobs:
  prcheck:
    runs-on: ${{ matrix.os }}
    defaults:
      run:
        shell: bash
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest]
    steps:
      - name: Dump GitHub context
        env:
          GITHUB_CONTEXT: ${{ toJson(github) }}
        run: echo "$GITHUB_CONTEXT"
      - name: get the check run id for each job
        run: |
          CHECK_SUITE_URL=$(curl -s -H "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID} | jq -r '.check_suite_url')
          CHECK_RUN_ID=$(curl -s -H "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.antiope-preview+json" $CHECK_SUITE_URL/check-runs | jq '.check_runs[] | select(.name=="prcheck (${{ matrix.os }})") | .id ')
          echo $CHECK_RUN_ID

My workflow for your reference:

Edit: based on the different job name, add jq select filter for each job, get the exact check_run_id.

Thanks