Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

I would like to send a Telegram message containing the URL of a specific workflow run when it failed. I found how to send Telegram message (via appleboy/telegram-action), found the repository info using  ${{ github.repository }} , but I still haven’t found how to get that specific workflow run ID.  By ID, I mean the 12345 in https://github.com/foo/bar/actions/12345.

How can I get the workflow run ID?

You must be logged in to vote

@rffontenelle 

Do you mean the run id in https://github.com/foo/bar/actions/ runs /12345.? 

There is a run_id property of github context. You could use ${{ github.run_id }} to get the run ID.  

Replies: 5 comments · 5 replies

Comment options

@rffontenelle 

Do you mean the run id in https://github.com/foo/bar/actions/ runs /12345.? 

There is a run_id property of github context. You could use ${{ github.run_id }} to get the run ID.  

You must be logged in to vote
0 replies
Comment options

In case you need to extract it from the command line, you can use this script in bash:

RUNID=$(gh api repos/$OWNER/$REPO/commits/$COMMIT_SHA/check-runs | jq -r '.check_runs[] | select(.name == "NAME_OF_YOUR_GITHUB_ACTIONS_WORKFLOW") | .html_url | capture("/runs/(?<number>[0-9]+)/jobs") | .number' | sed 's/"//g' | head -n 1)

Full explanation on StackOverflow: https://stackoverflow.com/a/76465815/4441211

You must be logged in to vote
1 reply
@Calinou
Comment options

I've tried that one-liner to get the run ID of an older commit within https://github.com/godotengine/godot, but I can't get it to work (the variable is empty).

This is what I tried:

RUNID=$(gh api repos/godotengine/godot/commits/94dbf69f5d6b7d2fd9561692df2e71557607fddc/check-runs | jq -r '.check_runs[] | select(.name == "🔗 GHA") | .html_url | capture("/runs/(?<number>[0-9]+)/jobs") | .number' | sed 's/"//g' | head -n 1)

🔗 GHA is the name of the main workflow file I'm interested in (it's defined in .github/workflows/runner.yml). I want to get a list of its artifacts so I can download them with nightly.link and compare their binary sizes with a PR build (so I can't rely on a PAT, hence the use of nightly.link). There are premade actions out there to compare bundle sizes but here, I'm comparing sizes of compiled C++ binaries that take a long time to compile (so building them twice isn't an option). There's also an action to compare an artifact's size to a GitHub release's size, but the binaries I'm comparing against aren't uploaded to GitHub Releases, only artifacts.

Running this alone results in a lot of forks appearing in the list, which surprises me:

gh api repos/godotengine/godot/commits/94dbf69f5d6b7d2fd9561692df2e71557607fddc/check-runs
Comment options

How we can obtain run id if we dispatch workflow using api in powershell script?

You must be logged in to vote
4 replies
@Novodes
Comment options

Doesn't this answer your question: https://github.com/orgs/community/discussions/26965#discussioncomment-6164539

@seanorama
Comment options

No. A GitHub workflow can be run directly with a dispatch event.

In that case, there is no commit to build on.

This is an incredibly large oversight, that a workflow system does not return anything about it's run. It's not a useful workflow system if you can't programmatically track the result.

As seen in the API docs, a worfklow dispatch only ever returns:

Status: 204

You expect any workflow/job/... based API to respond the ID of the thing it created.

https://docs.github.com/en/rest/actions/workflows?apiVersion=2022-11-28#create-a-workflow-dispatch-event

@xzrderek
Comment options

totally agree, i would've expected a workflow dispatch to return run_id so we can correlate it back.

@seanorama
Comment options

It's basic asynchronous API development. You submit a request, you get back the id. Any solution that requires filters on other values is simply a workaround.

Comment options

A less hacky alternative to the above is to use the API endpoint for listing workflow runs and filtering by associated commit:

gh api /repos/$OWNER/$REPO/actions/workflows/$WORKFLOW_FILE_OR_ID/runs \
  --method GET -f head_sha=$COMMIT_SHA
You must be logged in to vote
0 replies
Comment options

List recent workflow runs of the current repository, with the ID present:

gh run list -R ${{ github.repository }}

Filter options are available, here is the manual.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Product Feedback Share your thoughts and suggestions on GitHub features and improvements
9 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.