|
| 1 | +# Trigger Workflow and Wait |
| 2 | + |
| 3 | +Github Action for trigger a workflow from another workflow. The action then waits for a response. |
| 4 | + |
| 5 | +**When would you use it?** |
| 6 | + |
| 7 | +When deploying an app you may need to deploy additional services, this Github Action helps with that. |
| 8 | + |
| 9 | + |
| 10 | +## Arguments |
| 11 | + |
| 12 | +| Argument Name | Required | Default | Description | |
| 13 | +| --------------------- | ---------- | ----------- | --------------------- | |
| 14 | +| `owner` | True | N/A | The owner of the repository where the workflow is contained. | |
| 15 | +| `repo` | True | N/A | The repository where the workflow is contained. | |
| 16 | +| `github_token` | True | N/A | The Github access token with access to the repository. Its recommended you put it under secrets. | |
| 17 | +| `workflow_file_name` | True | N/A | The reference point. For example, you could use main.yml. | |
| 18 | +| `github_user` | False | N/A | The name of the github user whose access token is being used to trigger the workflow. | |
| 19 | +| `ref` | False | main | The reference of the workflow run. The reference can be a branch, tag, or a commit SHA. | |
| 20 | +| `wait_interval` | False | 10 | The number of seconds delay between checking for result of run. | |
| 21 | +| `client_payload` | False | `{}` | Payload to pass to the workflow, must be a JSON string | |
| 22 | +| `propagate_failure` | False | `true` | Fail current job if downstream job fails. | |
| 23 | +| `trigger_workflow` | False | `true` | Trigger the specified workflow. | |
| 24 | +| `wait_workflow` | False | `true` | Wait for workflow to finish. | |
| 25 | + |
| 26 | + |
| 27 | +## Example |
| 28 | + |
| 29 | +### Simple |
| 30 | + |
| 31 | +```yaml |
| 32 | +- uses: cloudbeds/[email protected] |
| 33 | + with: |
| 34 | + owner: cloudbeds |
| 35 | + repo: myrepo |
| 36 | + github_token: ${{ secrets.CB_CI_WORKFLOW_TOKEN }} |
| 37 | +``` |
| 38 | +
|
| 39 | +### All Options |
| 40 | +
|
| 41 | +```yaml |
| 42 | +- uses: cloudbeds/[email protected] |
| 43 | + with: |
| 44 | + owner: cloudbeds |
| 45 | + repo: myrepo |
| 46 | + github_token: ${{ secrets.CB_CI_WORKFLOW_TOKEN }} |
| 47 | + github_user: github-user |
| 48 | + workflow_file_name: main.yml |
| 49 | + ref: release-branch |
| 50 | + wait_interval: 10 |
| 51 | + client_payload: '{}' |
| 52 | + propagate_failure: false |
| 53 | + trigger_workflow: true |
| 54 | + wait_workflow: true |
| 55 | +``` |
| 56 | +
|
| 57 | +
|
| 58 | +## Testing |
| 59 | +
|
| 60 | +You can test out the action locally by cloning the repository to your computer. You can run: |
| 61 | +
|
| 62 | +```shell |
| 63 | +INPUT_OWNER="cloudbeds" \ |
| 64 | +INPUT_REPO="myrepo" \ |
| 65 | +INPUT_GITHUB_TOKEN="<REDACTED>" \ |
| 66 | +INPUT_GITHUB_USER="github-user" \ |
| 67 | +INPUT_WORKFLOW_FILE_NAME="main.yml" \ |
| 68 | +INPUT_REF="release-branch" \ |
| 69 | +INPUT_WAIT_INTERVAL=10 \ |
| 70 | +INPUT_CLIENT_PAYLOAD='{}' \ |
| 71 | +INPUT_PROPAGATE_FAILURE=false \ |
| 72 | +INPUT_TRIGGER_WORKFLOW=true \ |
| 73 | +INPUT_WAIT_WORKFLOW=true \ |
| 74 | +busybox sh entrypoint.sh |
| 75 | +``` |
| 76 | + |
| 77 | +You will have to create a Github Personal access token. You can create a test workflow to be executed. In a repository, add a new `main.yml` to `.github/workflows/`. The workflow will be: |
| 78 | + |
| 79 | +```shell |
| 80 | +name: Main |
| 81 | +on: |
| 82 | + workflow_dispatch |
| 83 | +jobs: |
| 84 | + build: |
| 85 | + runs-on: ubuntu-latest |
| 86 | + steps: |
| 87 | + - uses: actions/checkout@master |
| 88 | + - name: Pause for 25 seconds |
| 89 | + run: | |
| 90 | + sleep 25 |
| 91 | +``` |
| 92 | + |
| 93 | +You can see the example [here](https://github.com/cloudbeds/trigger-workflow-and-wait-example-repo1/blob/master/.github/workflows/main.yml). For testing a failure case, just add this line after the sleep: |
| 94 | + |
| 95 | +```yaml |
| 96 | +... |
| 97 | +- name: Pause for 25 seconds |
| 98 | + run: | |
| 99 | + sleep 25 |
| 100 | + echo "For testing failure" |
| 101 | + exit 1 |
| 102 | +``` |
| 103 | +
|
| 104 | +## Potential Issues |
| 105 | +
|
| 106 | +### Changes |
| 107 | +
|
| 108 | +If you do not want the latest build all of the time, please use a versioned copy of the Github Action. You specify the version after the `@` sign. |
| 109 | + |
| 110 | +```yaml |
| 111 | +- uses: cloudbeds/[email protected] |
| 112 | + with: |
| 113 | + owner: cloudbeds |
| 114 | + repo: myrepo |
| 115 | + github_token: ${{ secrets.CB_CI_WORKFLOW_TOKEN }} |
| 116 | +``` |
0 commit comments