Codex- / return-dispatch

⚙️ Dispatch an action to a foreign repository and output the newly created run ID.
MIT License
43 stars 11 forks source link

Is there any way to pass a variable value as a workflow_input? #87

Closed bob-ashforth-sp closed 2 years ago

bob-ashforth-sp commented 2 years ago

The comments in your repo indicate that a workflow_input can only be a string. Do you have any suggestions on how to pass the value of a variable to the dispatched workflow?

Codex- commented 2 years ago

You should be able to do this using standard github expressions

You'd probably be doing this already for your token to include it from secrets, an example of this would be:

steps:
  - name: Dispatch an action and get the run ID
    uses: codex-/return-dispatch@v1
    id: return-dispatch
    with:
      token: ${{ secrets.token }}
      ref: target_branch
      repo: repo
      owner: owner
      workflow: x.yml
      workflow_inputs: { "input_var": "${{ <expression> }}" }

Where <expression> can just be a reference to something you've populated in the environment. There are quite a few ways to populate the env or add what you need, if you need some examples of this let me know :)

On your recipient workflow you would have an input that maps to input_var:

on:
  workflow_dispatch:
    inputs:
      distinct_id:
        required: true
      input_var:
        required: true
bob-ashforth-sp commented 2 years ago

Never mind, I guessed right on the first try. 😊

From: Robert Ashforth @.> Date: Thursday, June 9, 2022 at 8:00 AM To: Codex-/return-dispatch @.> Subject: Re: [Codex-/return-dispatch] Is there any way to pass a variable value as a workflow_input? (Issue #87) Alex, we’re going to be proceeding with implementation of the project which uses your actions, and rather than poke about, I thought I would just ask: What syntax is used for multiple workflow_inputs? (That would be a great thing to add to your README, IMO… 😊 )

Thanks again-

 Bob

From: Robert Ashforth @.> Date: Wednesday, June 8, 2022 at 7:36 AM To: Codex-/return-dispatch @.> Subject: Re: [Codex-/return-dispatch] Is there any way to pass a variable value as a workflow_input? (Issue #87)

Thanks, Alex. I’m well-versed in GitHub Actions, and the reason I contacted you is that attempting to pass a normal environment variable resulted in a complaint at seeing the “$” character. I can try converting that to a variable using the ${{ }} syntax, didn’t think that would work when ${VARIABLE_NAME} did not.

BTW, it took me some time to get the await-remote-run action working with return-dispatch… but after a lot head-scratching and experimenting, I noticed that your README has a fatal typo:

steps:

The references to the return-dispatch output refer to the step as “return_dispatch…” once I fixed that, I got the pair working, and it is very valuable to my current work project, thanks.

I’ll try the GH variable format and see if that works for us.

Thanks-

 Bob

From: Alex Miller @.> Date: Tuesday, June 7, 2022 at 6:01 PM To: Codex-/return-dispatch @.> Cc: Robert Ashforth @.>, Author @.> Subject: Re: [Codex-/return-dispatch] Is there any way to pass a variable value as a workflow_input? (Issue #87)

You should be able to do this using standard github expressionshttps://docs.github.com/en/actions/learn-github-actions/expressions

You'd probably be doing this already for your token to include it from secrets, an example of this would be:

steps:

Where can just be a reference to something you've populated in the environmenthttps://docs.github.com/en/actions/learn-github-actions/environment-variables. There are quite a few ways to populate the env or add what you need, if you need some examples of this let me know :)

On your recipient workflow you would have an input that maps to input_var:

on:

workflow_dispatch:

inputs:

  distinct_id:

    required: true

  input_var:

    required: true

— Reply to this email directly, view it on GitHubhttps://github.com/Codex-/return-dispatch/issues/87#issuecomment-1149253607, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ASKCCF2UVW7YXJ4UDBBWEA3VN7IF5ANCNFSM5YDIPGIQ. You are receiving this because you authored the thread.Message ID: @.***>

Codex- commented 2 years ago

Thanks for letting me know about the missing id field on the example for await-remote-run, this has been fixed now :)

Closing as it seems as though you're up and running, if you run into any issues please feel free to open another issue

gonzaclavell commented 2 years ago

Hi all, is there anyway to do this: .... workflow_inputs: {'event_type': event_type,'client_payload': {'branch': branch,'profile': profile,'args': github_post_args + parallel_args}} ...

Codex- commented 2 years ago

Hi @gonzaclavell

Please open a new issue instead of bumping an old one.

In this case, you're asking if workflow_inputs can use a non-flat object? If so, we are constrained by what github supports first-hand: https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#inputs

Which appears to only support shallow/flat objects. If you can find documentation that outlines support for more complex inputs, please link it in a new issue and I can add support for it providing the API also supports it :)