Workflow dispatch - can't set ref to commit SHA

Hi,

I’m using the GitHub workflow dispatch event to manually run an end-to-end test workflow for an open source project. However, it seems like I’m unable to pass a commit in the ref input. This workflow step is triggering it:

 - name: Trigger end-to-end tests workflow
        # Note: we only run e2e tests automatically if this PR is not from a fork, as forks won't have access to secrets
        if: ${{ github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) }}
        uses: benc-uk/workflow-dispatch@v1
        with:
          workflow: End-to-end Tests
          token: ${{ secrets.BOT_GITHUB_TOKEN }}
          ref: ${{ github.event.pull_request.head.sha || github.sha }}

This is using the plugin benc-uk/workflow-dispatch that calls the workflow dispatch REST endpoint: https://github.com/benc-uk/workflow-dispatch/blob/4c044c1613fabbe5250deadc65452d54c4ad4fc7/src/main.ts#L50-L54

Errored workflow: https://github.com/serverless-nextjs/serverless-next.js/runs/1262249685?check_suite_focus=true

The error is this:

Run benc-uk/workflow-dispatch@v1
  with:
    workflow: End-to-end Tests
    token: ***
    ref: f04d309a1b048e934b99b2e1d4d6ff77e5458203
Workflow id is: 2972449
Error: No ref found for: f04d309a1b048e934b99b2e1d4d6ff77e5458203

From REST documentation here it says ref can point to a commit:

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

So it doesn’t seem to be issue with this action.

However, this commit already exists here when run for the workflow, so not sure why it’s not picking up? https://github.com/serverless-nextjs/serverless-next.js/commit/f04d309a1b048e934b99b2e1d4d6ff77e5458203

If passing github.ref it works but then it will run on the HEAD commit of master, but we want to run on specific commit and have workflow also show that commit. I guess a workaround is to pass sha as an input and then ensure to checkout that specific commit, but it may not be ideal as it could be confusing (the workflow itself is pointing to the HEAD).

Wondering if anyone else is facing a similar issue? Thanks in advance!

I can reproduce the problem - the endpoint accepts branch names and tag names, but not SHA-1 commit hashes for the ref attribute. I also tried sha, hash, object and commit but they are not permitted:

"message": "Invalid request.\n\n\"commit\" is not a permitted key.\n\"ref\" wasn't supplied."

If I look at the List matching references API, then I don’t find anything about commit hashes as :ref. I tried a couple of things like ${sha}, commits/${sha} and objects/${sha::2}/${sha:2} but to no avail. If it’s not available there, then the dispatch API probably doesn’t accept commit hashes either and the documentation is just wrong.

This is also supported by the UI:

image

You can only choose a branch. Curiously, you cannot select a tag, even though this is supported in the API.

1 Like

I created a docs issue:
https://github.com/github/docs/issues/590

The REST API source files seem to be in a private repository
https://github.com/github/rest-api-operations

2 Likes

@dphang, @Simran-B,

This is a legacy issue that had been reported earlier.

Looks like, the issue is still existing and not fixed.

Thanks for letting us know, I was not able to find that via search. We can follow that thread in that case. It will be good to fix this as it will allow running workflows in same context as the caller - e.g in this case running end-to-end tests workflow on same commit SHA as the triggering workflow (build workflow in my case).