How to reliably attach a check run to the current run

Hello,

I’m working on a GitHub Actions to create annotations from a JSON file: https://github.com/yuzutech/annotations-action

Unfortunately, and as far as I know, it’s not possible to create a check run and attach it to the current run.
For instance, let’s say that my action is running on the run id 123456 (https://github.com/yuzutech/annotations-action/actions/runs/123456), how can create a new check run and attach it to this run?

When creating a new create run using the API, it’s not possible to pass a run id.

I can use GitHub context to retrieve the sha, repo and owner but not the run id:

const ref = github.context.sha
const owner = github.context.repo.owner
const repo = github.context.repo.repo

To workaround this issue, some users are using listForRef to get the current check run:

octokit.checks.listForRef({
  owner,
  repo,
  ref,
  check_run,
  status: "in_progress"
});

But this approach seems fragile because I guess that the function could return more than one result or no result. The other drawback is that we are updating an existing check run where I want to create a new one.

Am I missing something?

Thanks!
Guillaume

I got a second bug report indicating that the check run is not associated to the pull request: https://github.com/yuzutech/annotations-action/issues/3#issue-766534755

Any idea?

For reference, the source code is available at: https://github.com/yuzutech/annotations-action/blob/ec1484587c9baa1fdda306c3456bfa81d3c3749f/index.js