Getting the job_id with toolkit
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 5.9k
- Forks
- 1.8k
- PR merge metrics
- No merged PRs in 30d
Description
Describe the enhancement
https://docs.github.com/en/rest/reference/actions#get-a-job-for-a-workflow-run
I want to use the above API from toolkit.
toolkit is currently unable to retrieve the information corresponding to the job_id.
Code Snippet
Now we need to use the list API to identify the job_id in the executed job and combine it with name(context.job, GITHUB_JOB_NAME) to identify the job.
const resp = await github.actions.listJobsForWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.runId,
});
const currentJob = resp?.data.jobs.find(job => job.name === context.job);
This works for simple jobs, but is more complicated when matrix is used.
The reason for this is that the name will be different from the context.job.
jobs:
build:
strategy:
matrix:
os: [ubuntu-18.04, ubuntu-20.04]
flavor: [dev, prod]
In the above yaml, the job name is build(ubuntu-18.04, dev), build(ubuntu-18.04, prod), build(ubuntu-20.04, dev), build(ubuntu-20.04, prod). Because context.job is a build job, the method to identify it from the result of the list is complicated.
It is simple to add information like context.jobId.
const resp = await this.github?.actions.getJobForWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
job_id: context.jobId,
})
const currentJob = resp?.data
The job_id information appears to be nowhere to be found, so it may be more than a fix for the toolkit itself.
Additional information
This may not be the issue that opens the issue here.
In that case, I'm sorry.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the toolkit usage of context.job and context.runId, the GitHub Actions getJobForWorkflowRun and listJobsForWorkflowRun calls, and the referenced runner issue #324. Trace where a workflow job identifier could enter the toolkit context, then verify that matrix jobs can retrieve their own job through getJobForWorkflowRun using the exposed value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, developer-experience
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100