'Setting default path in Github Actions `repository_dispatch`
I have a repo containing E2E tests (and only tests) for several separate repos. These tests are activated using a Github Actions workflow on the repo, against applications hosted on a testing server.
There are 2 ways to trigger this workflow: workflow_dispatch so the workflow can be manually triggered on Github, and repository_dispatch so the workflow can be triggered from an external source.
on:
workflow_dispatch:
inputs:
TARGET_SUITE:
default: 'application_A'
repository_dispatch:
types: [run-e2e]
jobs:
# run the workflow
To run a specific suite of tests, I'm relying on the request body from repository_dispatch, i.e. { "target_suite" : "application_A" }
jobs:
...
- if: ${{ github.event.client_payload.target_suite == "application_A" }}
# run test suite for application A
- if: ${{ github.event.client_payload.target_suite == "application_B" }}
# run test suite for application B
However, if the workflow is triggered via Github, there would be no client_payload, and none of the tests would run.
How can I setup this workflow so it can accept triggers from either dispatch method? Hopefully not something like this:
- if: ${{ github.event.client_payload.target_suite == "application_A" }}
# run application A
- if: ${{ github.event.client_payload.target_suite == "application_B" }}
# run application B
- if: ${{ github.event.inputs.TARGET_SUITE == "application_A" }}
# run application A
- if: ${{ github.event.inputs.TARGET_SUITE == "application_B" }}
# run application B
Solution 1:[1]
If you're using two different types of events to trigger the workflow, then I don't think it is possible to have the same payloads.
I can think of two options:
- You could write some boilerplate that looks at the
client_payloadandinputsand sets thetarget_suiteas an output. Subsequent steps could then just look at the output instead of looking at both theinputsand theclient_payload - Alternatively, unless there's a specific reason to trigger a
repository_dispatch, you could also trigger aworkflow_dispatchfrom the external source: https://docs.github.com/en/rest/reference/actions#create-a-workflow-dispatch-event
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | rethab |
