cli: Trigger Github Actions workflow

Describe the feature or problem you’d like to solve

It’s not possible to trigger Github Actions from the CLI. This would drastically improve how I manually trigger release workflows.

Documentation GitHub Actions: Manual triggers with workflow_dispatch

It is already possible to do this from the website, so it should be possible from the CLI

Proposed solution

Add gh workflow run <workflow name> -b <branch> which starts of workflows registered with trigger workflow_displatch for a specific branch

Workflows may have custom-defined inputs. It must be possible to specify those as well but I’m not aware of an elegant CLI api. One solution is -Parg1=foo -Parg2=bar as used by gradle.

on: 
  workflow_dispatch:
    inputs:
      logLevel:
        description: 'Log level'     
        required: true
        default: 'warning'
      tags:
        description: 'Test scenario tags'  

Additional context

86147571-2de93700-babf-11ea-8a08-e4beffd3abe9

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 40
  • Comments: 16 (4 by maintainers)

Most upvoted comments

Here’s what I came up with!

gh alias set runWorkflow --shell 'gh api /repos/:owner/:repo/actions/workflows/$1/dispatches -F ref=":branch"'

Then you can use gh runWorkflow <workflow file>.yml to run a workflow in any repo.

check out gh workflow run

Hey everyone thanks for your interest in Actions in GitHub CLI. We’re looking to chat with a couple folks about their Actions and GitHub CLI experience to better inform our solutions. If you’d be interested in speaking with us, please 👍 on this comment! Thank you!

We’ll be contacting people through their public GitHub emails, so if you’re interested please make sure yours is available.

Thanks for the offer, @cjdenio . We’re hoping to plan a suite of behaviors around actions and are still designing that so we’re not looking for community contributions there. That said, please do feel free to experiment with gh api and gh alias and share any stopgap hacks you come up with while we work on the official implementation.

@ampinsk Happy to share my thoughts, especially as I just wrote a blog post on adding it using aliases and gh api 🤣

@cjdenio did you manage to make it work with inputs (e.g. pipeline parameters)?

Seems like this would be simple enough through the use of this API method. I’d be glad to start development on this if/when y’all decide it’s a desired feature! I know that I personally would benefit from it.

💭 I want it to be packed in “act” command like below

  • gh act
    • kick-wf (workflow-dispatch)
    • kick-repo (repository-dispatch)
    • status
    • list