简体   繁体   中英

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?

Eg 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!

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,
});

Just posting my code snippet that solved my problem here in case it helps anyone in the future :)

var workflowRuns = octokit.actions.listWorkflowRuns({
    owner: owner,
    repo: 'repo-name',
    workflow_file_name: 'file-name.yaml',
    per_page: 1
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM