-
Notifications
You must be signed in to change notification settings - Fork 206
173 lines (137 loc) · 6.19 KB
/
WorkflowHook.yml
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# Run after-hooks of workflow executions. Changes to this workflow file enables only if it's available on the default branch.
#
# Please note that we should not checkout the target code because it contains unverified changes.
name: Workflow Hook
on:
workflow_run:
workflows:
- UnitTest
- Format
- iOS Lint
types:
- completed
# Disable all permissions. We have to enable required permissions at job-level.
permissions: {}
run-name: ${{ github.event.workflow_run.name }} - ${{ github.event.workflow_run.head_repository.owner.login }}:${{ github.event.workflow_run.head_branch }}
# Restrict the concurrency on a pair of a repository owner and a branch.
concurrency:
group: workflow-hook-${{ github.event.workflow_run.head_repository.owner.login }}:${{ github.event.workflow_run.head_branch }}-${{ github.event.workflow_run.name }}
cancel-in-progress: true
jobs:
# Run every executions of workflows specified in workflow_run#workflows
# This job will expose an associated pull request if exists.
linked-pull-request:
# Run this job only when it's required.
# Array-literal is not available in Actions so we have to transform a json string into an array.
if: >
contains(fromJSON('["failure"]'), github.event.workflow_run.conclusion) &&
contains(fromJSON('["Format"]'), github.event.workflow.name) ||
contains(fromJSON('["success", "failure"]'), github.event.workflow_run.conclusion) &&
contains(fromJSON('["UnitTest"]'), github.event.workflow.name) ||
contains(fromJSON('["failure"]'), github.event.workflow_run.conclusion) &&
contains(fromJSON('["iOS Lint"]'), github.event.workflow.name)
permissions:
pull-requests: read # for listing pull requests
timeout-minutes: 2
outputs:
pull-request: ${{ steps.linked-pull-request.outputs.entity }} # pull request entity (string)
runs-on: ubuntu-latest
steps:
- id: linked-pull-request
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
with:
script: |
// Get the latest pull request
const headBranch = '${{ format('{0}:{1}', github.event.workflow_run.head_repository.owner.login, github.event.workflow_run.head_branch) }}';
const { data: pulls } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
head: headBranch,
direction: 'desc',
sort: 'updated',
per_page: 1
});
if (pulls.length === 0) {
core.warning('No pull request is found.');
} else {
core.setOutput('entity', pulls[0]);
}
# Run every executions of Format workflow. (failure only)
after-Format:
needs:
- linked-pull-request
if: >
github.event.workflow.name == 'Format' &&
needs.linked-pull-request.outputs.pull-request &&
fromJSON(needs.linked-pull-request.outputs.pull-request).number
permissions:
pull-requests: write # for creating a comment on pull requests
timeout-minutes: 2
runs-on: ubuntu-latest
steps:
- uses: marocchino/sticky-pull-request-comment@f6a2580ed520ae15da6076e7410b088d1c5dddd9 # v2.7.0
with:
header: ping-format
number: ${{ fromJSON(needs.linked-pull-request.outputs.pull-request).number }}
recreate: true
message: >
Hi @${{ github.event.workflow_run.actor.login }}!
Codes seem to be unformatted. To resolve this issue, please run `./gradlew spotlessKotlinApply` and fix the results of ./gradlew lintDebug..
Thank you for your contribution.
# Run every executions of UnitTest workflow. (always)
after-UnitTest:
needs:
- linked-pull-request
if: >
github.event.workflow.name == 'UnitTest' &&
needs.linked-pull-request.outputs.pull-request &&
fromJSON(needs.linked-pull-request.outputs.pull-request).number
permissions:
actions: read # for downloading artifacts
contents: read # for EnricoMi/publish-unit-test-result-action (we can remove this safely after making this repo public)
issues: read # for EnricoMi/publish-unit-test-result-action (we can remove this safely after making this repo public)
checks: write # for EnricoMi/publish-unit-test-result-action
pull-requests: write # for creating a comment on pull requests
timeout-minutes: 2
runs-on: ubuntu-latest
steps:
- uses: dawidd6/action-download-artifact@246dbf436b23d7c49e21a7ab8204ca9ecd1fe615 # v2.27.0
with:
run_id: ${{ github.event.workflow_run.id }}
name: test-results
path: .test-results
- uses: dawidd6/action-download-artifact@246dbf436b23d7c49e21a7ab8204ca9ecd1fe615 # v2.27.0
with:
run_id: ${{ github.event.workflow_run.id }}
name: event-payload
path: .event-payload
- uses: EnricoMi/publish-unit-test-result-action@283dea176069279a9076e77b548668a8e4f0c31b # v2.9.0
with:
commit: ${{ github.event.workflow_run.head_sha }}
event_file: .event-payload/event.json
event_name: ${{ github.event.workflow_run.event }}
files: |
.test-results/**/*.xml
# Run every executions of iOS Lint workflow. (failure only)
after-iOSLint:
needs:
- linked-pull-request
if: >
github.event.workflow.name == 'iOS Lint' &&
needs.linked-pull-request.outputs.pull-request &&
fromJSON(needs.linked-pull-request.outputs.pull-request).number
permissions:
pull-requests: write # for creating a comment on pull requests
timeout-minutes: 2
runs-on: ubuntu-latest
steps:
- uses: marocchino/sticky-pull-request-comment@f6a2580ed520ae15da6076e7410b088d1c5dddd9 # v2.7.0
with:
header: ping-format
number: ${{ fromJSON(needs.linked-pull-request.outputs.pull-request).number }}
recreate: true
message: >
Hi @${{ github.event.workflow_run.actor.login }}!
Codes seem to have violations. Please run `cd app-ios && swiftlint --fix` to fix this issue.
Thank you for your contribution.