-
Notifications
You must be signed in to change notification settings - Fork 4
206 lines (186 loc) · 7.92 KB
/
update-client.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
name: Update clients PRs
on:
# Trigger the workflow on pull requests targeting the main branch
pull_request:
types: [assigned, unassigned, opened, reopened, synchronize, edited, labeled, unlabeled, edited, closed]
branches:
- main
jobs:
get_available_profiles:
runs-on: ubuntu-latest
outputs:
profiles: ${{ steps.get-profiles-step.outputs.profiles }}
steps:
- uses: actions/checkout@v2
- id: get-profiles-step
uses: ./.github/actions/get-profiles
update_client_pr:
if: github.event.action != 'closed'
runs-on: ubuntu-latest
needs: [ get_available_profiles ]
strategy:
fail-fast: false
matrix:
profile: ${{ fromJson(needs.get_available_profiles.outputs.profiles) }}
env:
CLIENT_PATH: generated-clients/${{ matrix.profile.name }}
CLIENT_REPOSITORY: ${{ github.repository_owner }}/${{ matrix.profile.repository }}
steps:
- name: Check out repository code
uses: actions/checkout@v2
- name: Set up JDK 8
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'adopt'
- name: Cache openapi-generator dependencies and build
uses: actions/cache@v2
with:
path: |
~/.m2/repository
${{ env.GITHUB_WORKSPACE }}/apivideo-generator/target
key: ${{ runner.os }}-build-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-build-
- name: Checkout client repository
uses: actions/checkout@v2
with:
repository: ${{ env.CLIENT_REPOSITORY }}
token: ${{ secrets.PAT }}
path: ${{ env.CLIENT_PATH }}
- name: Remove files to allow files deletion from git
run: |
cd ${{ env.CLIENT_PATH }}
shopt -s extglob
rm -Rf !(.git|examples|.|..)
- name: Generate client
run: mvn package -P ${{ matrix.profile.name }}
# Make changes to pull request here
- uses: peter-evans/create-pull-request@v3
id: cpr
with:
token: ${{ secrets.PAT }}
path: ${{ env.CLIENT_PATH }}
commit-message: ${{ github.event.pull_request.title }}
committer: GitHub <[email protected]>
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
branch: ${{ github.event.pull_request.head.ref }}
title: ${{ github.event.pull_request.title }}
body: |
> ${{ github.event.pull_request.body }}
> Created by @${{ github.actor }} via ${{ github.event.pull_request.html_url }}
delete-branch: true
labels: ${{ join(github.event.pull_request.labels.*.name) }}
assignees: ${{ join(github.event.pull_request.assignees.*.login) }}
# reviewers: ${{ join(github.event.pull_request.requested_reviewers.*.login) }} #TODO
# draft: true
- name: Check tests results
uses: apivideo/[email protected]
if: ${{ steps.cpr.outputs.pull-request-head-sha }}
with:
token: ${{ secrets.PAT }}
repo: ${{ matrix.profile.repository }}
owner: ${{ github.repository_owner }}
sha: ${{ steps.cpr.outputs.pull-request-head-sha }}
generate_documentation:
if: github.event.action != 'closed'
runs-on: ubuntu-latest
needs: [update_client_pr]
steps:
- name: Check out repository code
uses: actions/checkout@v2
- name: Checkout client repository
uses: actions/checkout@v2
with:
repository: ${{ github.repository_owner }}/api.video-documentation
token: ${{ secrets.PAT }}
path: generated-clients/documentation
- name: Copy oas_apivideo.yaml
run: |
cp -R oas_apivideo.yaml generated-clients/documentation/openapi.yaml
- uses: peter-evans/create-pull-request@v3
id: cpr
with:
token: ${{ secrets.PAT }}
path: generated-clients/documentation
commit-message: ${{ github.event.pull_request.title }}
committer: GitHub <[email protected]>
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
branch: ${{ github.event.pull_request.head.ref }}
title: ${{ github.event.pull_request.title }}
body: |
> ${{ github.event.pull_request.body }}
> Created by @${{ github.actor }} via ${{ github.event.pull_request.html_url }}
delete-branch: true
labels: ${{ join(github.event.pull_request.labels.*.name) }}
assignees: ${{ join(github.event.pull_request.assignees.*.login) }}
merge_client_pr:
# this job will only run if the PR has been merged
if: github.event.action == 'closed' && github.event.pull_request.merged == true
runs-on: ubuntu-latest
needs: [ get_available_profiles ]
strategy:
matrix:
profile:
- ${{ fromJson(needs.get_available_profiles.outputs.profiles) }}
- name: documentation
repository: api.video-documentation
env:
CLIENT_REPOSITORY: ${{ github.repository_owner }}/${{ matrix.profile.repository }}
steps:
- run: |
echo PR ${{ github.event.repo.name }}#${{ github.event.number }} has been merged
- name: Look for existing PRs and merge them
id: commit
uses: actions/github-script@v3
with:
github-token: ${{ secrets.PAT }}
script: |
const { data: pullRequests } = await github.request(`GET /repos/${process.env.CLIENT_REPOSITORY}/pulls`, { head: context.payload.pull_request.head.label });
if (pullRequests.length > 0) {
pullRequests.forEach(async (pullRequest) => {
console.log(`Found ${pullRequest.state} PR ${process.env.CLIENT_REPOSITORY}#${pullRequest.number}`);
const mergeResponse = await github.request(`PUT /repos/${process.env.CLIENT_REPOSITORY}/pulls/${pullRequest.number}/merge`);
console.log('mergeResponse', mergeResponse);
});
} else {
console.log(`There are no PRs from branch ${context.payload.pull_request.head.ref} on ${process.env.CLIENT_REPOSITORY} repository.`);
}
close_client_pr:
# this job will only run if the PR has been closed without being merged
if: github.event.action == 'closed' && github.event.pull_request.merged == false
runs-on: ubuntu-latest
needs: [ get_available_profiles ]
strategy:
matrix:
profile:
- ${{ fromJson(needs.get_available_profiles.outputs.profiles) }}
- name: documentation
repository: api.video-documentation
env:
CLIENT_REPOSITORY: ${{ github.repository_owner }}/${{ matrix.profile.repository }}
steps:
- run: |
echo PR ${{ github.event.repo.name }}#${{ github.event.number }} has been closed
- name: Look for existing PRs and close them
id: commit
uses: actions/github-script@v3
with:
github-token: ${{ secrets.PAT }}
script: |
const { data: pullRequests } = await github.request(`GET /repos/${process.env.CLIENT_REPOSITORY}/pulls`, { head: context.payload.pull_request.head.label });
if (pullRequests.length > 0) {
pullRequests.forEach(async (pullRequest) => {
console.log(`Found ${pullRequest.state} PR ${process.env.CLIENT_REPOSITORY}#${pullRequest.number}`);
await github.request(`PATCH /repos/${process.env.CLIENT_REPOSITORY}/pulls/${pullRequest.number}`, { state: 'closed' });
});
} else {
console.log(`There are no PRs from branch ${context.payload.pull_request.head.ref} on ${process.env.CLIENT_REPOSITORY} repository.`);
}
for f of *; do
case $f in
*-clients)
print $f
;;
esac
done