Can someone help me understand the behaviour of the Github Actions tab? As somebody new to Actions working on a third party repo I would like to be able to create an action on a branch and execute it on the workflow_dispatch event. I have not succeeded in doing this but I have discovered the following:
The workaround is the execute on a push event which is OK but that seems out of kilter with Github's high standards of design.
Does the above sound a) about right and b) whichever way you look at it, not optimal behaviour? Or, is there a better approach to building and testing actions?
Github actions can only trigger on master or the default branch.
If you do want to trigger a workflow from within a workflow run, you can use a personal access token instead of GITHUB_TOKEN to trigger events that require a token. You'll need to create a personal access token and store it as a secret.
Under your repository name, click Actions. In the left sidebar, click the workflow you want to run. Above the list of workflow runs, select Run workflow. Use the Branch dropdown to select the workflow's branch, and type the input parameters.
You can run a workflow that is still in development in a feature-branch from the command line, with Github CLI. The documentation says:
To run a workflow on a branch other than the repository's default branch, use the --ref flag.
gh workflow run workflow --ref branch-name
To add input parameters, run it like this:
gh workflow run workflow --ref branch-name -f myparameter=myvalue
You can run your workflow through the GitHub CLI, but you will first need to make sure it's run before.
gh workflow list
If your workflow isn't in that list (by name), then add pull_request:
and create a pull request so that the workflow is registered, once.
name: 'My Workflow'
on:
workflow_dispatch:
inputs:
parameter:
description: My Parameter
pull_request: -- Add this here
...
Once you've created a pull request, you should see 'My Workflow' when you run gh workflow list
. Once that's done, you can remove the added line.
Finally, now run:
gh workflow run 'My Workflow' --ref my-branch -f parameter=value
This should run your workflow dispatch from a feature branch.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With