Skip to content

Actions: filter to workflow runs for a specific commit #8285

@rcoup

Description

@rcoup

Describe the feature or problem you’d like to solve

My goal is to download an artifact from the latest successful workflow run for a specific commit. While releases are the general/best way to get artifacts, for development and integration testing between repos it's often helpful to incorporate artifacts from specific branches and/or commits.

After #3321 and #3349, it's gotten magnitudes simpler:

# get the latest successful CI run number for main
$ gh run list -b main -s success -w Build -L 1 --json databaseId -q .[0].databaseId
123456789
# get the artifact and extract it
$ gh run download 123456789 -n my-artifact

But it would be great to be able to point to a specific commit.

You can do it hackily via:

$ gh run list -s success -w Build -L 1000 --json headSha,databaseId -q ".[] | select(.headSha == \"${SHA}\") | .databaseId"

But it's slow with larger limits, and the limit is kinda arbitrary — if you do too many runs it will drop off the bottom.

The List Workflow runs API supports head_sha as a parameter...

Proposed solution

Add -c SHA as an option to gh run list:

Then our get-the-artifact workflow becomes:

$ gh run list -s success -c c0ffeec0ffeec0ffee -w Build -L 1 --json databaseId -q .[0].databaseId
123456789
$ gh run download 123456789 -n my-artifact

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementa request to improve CLIgh-runrelating to the gh run commandhelp wantedContributions welcome

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions