actions / actions/toolkit

Getting the job_id with toolkit

Open
#550 4 comments 9 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
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.

refs: https://github.com/actions/runner/issues/324

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.