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!

There should probably be something like:

octokit.actions.listWorkflowRuns({
    owner: owner,
    repo: repo-name,
    workflow_id: "tests.yml",
    per_page: 1,
});

or similar. This should give you the latest run for given workflow.

Thanks heaps for your help! Just posting the code snippet that solved my issue in case this helps anyone in the future.

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