githubgithub-apigithub-actionsoctokit

Get the latest workflow run from GitHub Actions using the Octokit API


I'm using the Octokit API to request a specific workflow run. I can see in the documentation that I can request a specific workflow run by providing a workflow run ID. However I would like to always request the latest workflow run. How do I achieve this if I don't know what the ID will be?

E.g. the value of workflow-run-latest here would always be changing.

octokit.actions.getWorkflowRun({
    owner: owner,
    repo: repo-name,
    run_id: workflow-run-latest,
});

Thanks!


Solution

  • When using the list API it looks to me like the latest is always the first in the list. So one option might be to request with per_page set to 1 so you only get the latest.

    octokit.actions.listWorkflowRunsForRepo({
      owner: owner,
      repo: repo-name,
      per_page: 1,
    });