benc-uk / workflow-dispatch

A GitHub Action for triggering workflows, using the `workflow_dispatch` event
MIT License
327 stars 125 forks source link

Add dispatch-by-workflow-id example & ability to dispatch by file name if possible #18

Closed dradetsky closed 2 years ago

dradetsky commented 3 years ago

According to the docs, I can pass the

ID of the workflow to trigger and run

to with.workflow. I have successfully invoked a workflow by name, i.e.

    - name: Invoke workflow
      uses: benc-uk/workflow-dispatch@v1
      with:
        workflow: unit tests

But I would prefer to invoke workflows by ID, just as I refer to other tasks in a workflow by the task ID I assign to them.

But there's no example of an invocation by ID. According to the GHA docs, there's no such thing as a top-level job ID, and my attempts to add an id key alongside name and on, and then invoke the workflows by this ID failed, although I can't remember how.

According to the REST docs, you can substitute a workflow file name for a workflow ID. In other words, I should have been able to use

      with:
        workflow: project-unit-tests.yaml

although obviously this does not actually work.

FWIW, reading the REST docs quickly made me think that the file name literally was the workflow ID, so in spite of your warning about not being allowed to use the workflow file name, I somehow convinced myself that since the filename was the ID, your warning didn't apply to my use case. Obviously I should have realized that the fact that the warning wasn't irrelevant meant that my understanding of what workflow IDs are was mistaken, but I'm in a hurry & not very smart. And this caused me to be confused & annoyed for a while, which isn't your fault, but something you might want to prevent anyhow.

So for one thing, if you had an example of triggering a workflow by ID, where you pointed to something like the example workflow GET result in the REST docs and then showed (assuming I now understand it correctly)

      with:
        workflow: 161335

that would have (I like to flatter myself) prevented me from being confused.

For a 2nd thing, if there was some way to indicate the workflow to trigger by something more ID-like, that would be really nice. For example, drawing inspiration from that GET response, which includes

  "path": ".github/workflows/blank.yaml",

even something as jank as allowing me to write

      with:
        workflow_path: .github/workflows/project-unit-tests.yaml

would be good enough for my needs, although obviously the version I originally tried to use, namely

      with:
        workflow: project-unit-tests.yaml

would be nicer and cleaner.

FooBarWidget commented 3 years ago

I submitted a pull request. Check above.

benc-uk commented 2 years ago

Fixed in v1.2 and master