workflow-dispatch icon indicating copy to clipboard operation
workflow-dispatch copied to clipboard

Cannot dispatch with commit SHA

Open saliceti opened this issue 4 years ago • 8 comments

The Readme says:

The reference can be a branch, tag, or a commit SHA.

But when using a SHA, the action fails with: No ref found for: <commit sha>

Indeed, the Github API doc says:

ref: Required. The git reference for the workflow. The reference can be a branch or tag name.

Which would explain why it fails when passing a commit sha

Can we fix the Readme to remove the use case for sha?

saliceti avatar Apr 06 '21 15:04 saliceti

I don't think this is the case, I'm using the sha on multiple workflow triggers and it works just fine. I'm actually running into the same issue with ref so there must be another underlying cause.

Dispatch

name: PR Verification

on:
  pull_request:
jobs:
  # https://github.com/benc-uk/workflow-dispatch
  verification:
    name: Trigger - Lint, Test & Build
    runs-on: ubuntu-latest

    steps:
      - name: Trigger Workflow
        uses: benc-uk/workflow-dispatch@v1
        with:
          inputs: '{ "ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'
          token: ${{ secrets.REPO_ACCESS_TOKEN }}
          workflow: Lint, Test & Build

Triggered Workflow

name: Lint, Test & Build

on:
  workflow_dispatch:
    inputs:
      ref:
        description: 'GitHub REF to be used for checkout'
        required: false
      sha:
        description: 'GitHub SHA to be used for checkout'
        required: true

Error using sha

Run benc-uk/workflow-dispatch@v1
  with:
    inputs: {"sha": "86b842d5629262a44a7a1614fe361f1ffdee4597"}
    token: ***
    workflow: Lint, Test & Build
Workflow id is: 8600649
Error: No ref found for: refs/pull/547/merge

Error using ref

Run benc-uk/workflow-dispatch@v1
  with:
    inputs: {"ref": "master"}
    token: ***
    workflow: Lint, Test & Build
Workflow id is: 8600649
Error: No ref found for: refs/pull/547/merge

Error using github.event.pull_request.head.ref

Run benc-uk/workflow-dispatch@v1
  with:
    inputs: {"ref": "master"}
    token: ***
    workflow: Lint, Test & Build
Workflow id is: 8600649
Error: No ref found for: refs/pull/547/merge

CWSites avatar May 18 '21 14:05 CWSites

Following up here, any plan to address this?

CWSites avatar Aug 24 '21 16:08 CWSites

@CWSites could it be because you’re on a branch? Workflow dispatch only works when the triggered workflow is on master

saliceti avatar Aug 25 '21 06:08 saliceti

Hey @saliceti I am on a branch, trying this as part of my PR verification to use the same test config as my Release workflow. My understanding from GitHub is that workflow dispatch shouldn't be limited to master?

CWSites avatar Sep 07 '21 13:09 CWSites

Sorry I think I confused it with repository_dispatch and assumed it's the same issue

saliceti avatar Sep 07 '21 15:09 saliceti

Still an issue :(

CWSites avatar Feb 24 '22 15:02 CWSites

@saliceti @CWSites try ${{ github.head_ref }}

I used the github-script action though:

    - name: Trigger Workflow
      uses: actions/github-script@v6
      with:
        script: |
          github.rest.actions.createWorkflowDispatch({
            owner: context.repo.owner,
            repo: context.repo.repo,
            workflow_id: 'new-workflow.yml',
            ref: '${{ github.head_ref }}',
          })

joshjohanning avatar Oct 07 '22 19:10 joshjohanning

So the equivalent with this action

    - name: Invoke workflow with inputs
      uses: benc-uk/workflow-dispatch@v1
      with:
        workflow: new-workflow
        token: ${{ github.token }}
        inputs: '{ "exit-code": "1" }'
        ref: ${{ github.head_ref }}

joshjohanning avatar Oct 11 '22 22:10 joshjohanning

Thanks @joshjohanning - I'm closing this as you seem to have solved the problem

benc-uk avatar Oct 28 '22 16:10 benc-uk

How is the head_ref solving the issue faced when trying to use sha?

This looks like an API limitation: github/docs#590

matfax avatar Nov 14 '23 14:11 matfax