-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreusable_repository_dispatch.yml
More file actions
111 lines (105 loc) · 3.71 KB
/
reusable_repository_dispatch.yml
File metadata and controls
111 lines (105 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
name: Repository Dispatch
# This workflow is used to call workflows in external repositories and bring the
# result back into the calling repository.
#
# This is ideal for E2E testing when a repository can trigger a dependent
# repository's integration tests in order to check for breaking changes.
#
# The called repository should have a workflow that triggers on `workflow_dispatch`
#
# Example:
#
# name: Repository Dispatch
# on:
# workflow_dispatch:
# inputs:
# distinct_id:
# key:
#
# jobs:
# test:
# runs-on: ubuntu-latest
# steps:
# - name: echo distinct ID ${{ github.event.inputs.distinct_id }}
# run: |
# echo ${{ github.event.inputs.distinct_id }}
# echo 'my input key ${{ inputs.key }}'
#
#
# At a minimum a `distinct_id` input is required in the called workflow so that
# this workflow can find the workflow run in the API since the `distinct_id` is
# then printed in the run name. This is just needed in one step, so as a
# template, the echo statement can be used for debugging purposes.
#
# This example also shows how you can access addition inputs via the
# `workflow_inputs` variable. These `workflow_inputs` should correspond with
# `workflow_dispatch` inputs. In this example, the `workflow_inputs` would have
# been '{"key": "my_value"}'
on:
workflow_call:
inputs:
owner:
description: "Repository owner for the target repository"
type: string
required: true
repo:
description: "Repository being targeted"
type: string
required: true
ref:
description: "The branch of the target repository that should be targeted, i.e. main or refs/heads/main"
type: string
required: false
default: main
workflow:
description: "The workflow in the target repository that should be triggered"
type: string
required: true
workflow_inputs:
description: "A key value map of custom inputs, i.e. `{'my_key':'my_value'}`"
type: string
required: false
default: ""
workflow_timeout_seconds:
description: "Timeout for called workflow"
type: number
required: false
default: 300
jobs:
triggerMyEvent:
runs-on: ubuntu-latest
steps:
- name: Dispatch an action and get the run ID
uses: codex-/return-dispatch@v1
id: return_dispatch
with:
token: ${{ secrets.PAT_REPO_DISPATCH }} # this is an org level secret
ref: ${{inputs.repo}}
repo: ${{inputs.repo}}
owner: ${{inputs.owner}}
workflow: ${{inputs.workflow}}
workflow_inputs: ${{ inputs.workflow_inputs }} # Optional
workflow_timeout_seconds: ${{inputs.workflow_timeout_seconds}} # Default: 300
# I added this as I observed the API response sometimes being empty as the
# API route used to get the conclusion is different than the API route
# used in the previous action
- name: Delay for api to update
run: sleep 2
- name: Get Conclusion
uses: octokit/[email protected]
id: get_run_conclusion
with:
route: GET /repos/{owner}/{repo}/actions/runs/{run_id}
owner: ${{inputs.owner}}
repo: ${{inputs.repo}}
run_id: ${{steps.return_dispatch.outputs.run_id}}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Fail if not successful
if: ${{ fromJSON(steps.get_run_conclusion.outputs.data).conclusion != 'success' }}
run: exit 1
# Alternative if descriptive exit code is helpful
# uses: actions/github-script@v3
# with:
# script: |
# core.setFailed('My detailed error response')