I need to get a workflow summary (i.e. the info I published using $GITHUB_STEP_SUMMARY
) for specific RUN_ID
in my workflow.
I reviewed https://docs.github.com/en/rest, https://github.com/actions/github-script, GH CLI manual - but I still don't understand how to fetch this data.
The path to these job summaries is a bit convoluted...
First call the REST API for the runs of a job:
https://api.github.com/repos/{owner}/{repo}/actions/runs/{runid}/jobs
This will return a json payload:
{
"total_count": 1,
"jobs": [
{
"id": 13143160145,
"run_id": 4850518271,
"workflow_name": "test",
"head_branch": "main",
"run_url": "https://api.github.com/repos/{owner}/{repo}/actions/runs/4850518271",
"run_attempt": 1,
"node_id": "CR_kwDOJV3v7c8AAAADD2S1UQ",
"head_sha": "db07f0a8a0eb2104583a4165c86d4da5603c8944",
"url": "https://api.github.com/repos/{owner}/{repo}/actions/jobs/13143160145",
"html_url": "https://github.com/{owner}/{repo}/actions/runs/4850518271/jobs/8643488313",
"status": "completed",
"conclusion": "success",
"created_at": "2023-05-01T10:40:11Z",
"started_at": "2023-05-01T10:40:18Z",
"completed_at": "2023-05-01T10:40:20Z",
"name": "build",
"steps": [
...
Now grab the html_url
and take that last ID off of it: https://github.com/{owner}/{repo}/actions/runs/4850518271/jobs/**8643488313**
and use that to fetch the summary_raw
:
https://github.com/{owner}/{repo}/actions/runs/4850518271/jobs/8643488313/summary_raw
Which should return the raw markdown for the job summary.
I'm not 100% sure what that ID signifies as I can't find a reference to it elsewhere in the docs.