Workflow Dispatch from a tag in actions tab

Hi there,

According to rest api documentation, workflow_dispatch takes in a ref

ref Required . The reference of the workflow run. The reference can be a branch, tag, or a commit SHA.

However, the UI only provides branch as the option. Is there anyway we can add tags?

Thanks!

6 Likes

@wei ,

When trying to manually trigger a workflow on the workflow_dispatch event, there are some differences between triggering from GitHub and triggering using the REST API.

  1. To trigger the workflow_dispatch event on GitHub, your workflow must be in the default branch, otherwise you can’t see the “Run workflow” button on GitHub. If you want other branches can be the optional ref of the workflow, the workflow also must be in these branches. Currently, the optional ref only can be branch. Tag and commit SHA are not supported here.

  2. To trigger the workflow_dispatch event using the REST API, your workflow does not have to be in the default branch as long as the workflow is in the optional ref (branch, tag, or a commit SHA).

If you really need the feature that can select branch, tag or commit SHA as ref when triggering the workflow_dispatch event on GitHub, I recommend that you can directly report a feature request here.
That will allow you to directly interact with the appropriate engineering team, and make it more convenient for the engineering team to collect and categorize your suggestions.

2 Likes

I am lost when trying to use the workflow_dispatch API, the response is either 422 nil is not an object, or not found

Also see Workflow dispatch - can't set ref to commit SHA

A commit hash isn’t supported, but tags are accepted by the REST API.

curl \
  -d '{"ref":"{tag}"}' \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/vnd.github.v3+json' \
  -H 'Authorization: token {access-token}' \
  'https://api.github.com/repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches'

The expected reply in case of a successful dispatch is HTTP/1.1 204 No Content without payload.

Depending on the shell you use, it will require a slightly different syntax for the curl command. For example, in PowerShell Core, there is a long-standing issue with quoting. The data part needs special escaping:

  • single quoted string, " escaped as \":
    -d '{\"ref\": \"...\"}'
    – or –
  • double quoted string, " escaped as \`":
    -d "{\`"ref\`": \`"...\`"}"

(Note that this was tested with actual curl, not the aliased command for Invoke-WebRequest)

1 Like

@brightran @andreagriffiths11 I report a feature request, but what is needed for this functionality to get into the Github roadmap?

We use deploy by tag, because deploy from brunch is not reliable. A tag is harder to change than a brunch. The lack of trigger the workflow_dispatch event on UI by tag stops us from migrating to GA.

It seems to me that this is not a difficult task to add this functionality at the frontend level. And do not look for workarounds.

Thanks!

3 Likes

@ahdbilal ^^^
What is needed to trigger the workflow_dispatch event on UI by tag to get into the Github roadmap?

1 Like