-
Notifications
You must be signed in to change notification settings - Fork 23
279 lines (271 loc) · 11.1 KB
/
update-specs-and-client-libraries.yaml
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
name: update-specs-and-client-libraries
run-name: Update specs and client libraries
on:
push:
branches:
- master
paths-ignore:
- "generated/artifacts/**"
pull_request:
branches:
- master
workflow_dispatch:
inputs:
update-onfido-java:
description: "Refresh onfido-java?"
required: true
default: false
type: boolean
update-onfido-node:
description: "Refresh onfido-node?"
required: true
default: false
type: boolean
update-onfido-php:
description: "Refresh onfido-php?"
required: true
default: false
type: boolean
update-onfido-python:
description: "Refresh onfido-python?"
required: true
default: false
type: boolean
update-onfido-ruby:
description: "Refresh onfido-ruby?"
required: true
default: false
type: boolean
type-of-change:
description: "Type of change?"
required: true
default: No change
type: choice
options:
- Major
- Minor
- Patch
- No change
lib-version-suffix:
description: "Add a suffix to version? (e.g `-pre`)"
type: string
override-spec-version:
description: "Override onfido-spec version? (e.g `v2.8.0-beta`)"
type: string
override-lib-version:
description: "Override client library version? (e.g `3.0.1-alpha`)"
type: string
jobs:
validate_input_specs:
name: Validate multi file specification
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Validate OpenAPI Specification YAML
run: ./shell/run-prettier.sh check
generate_specs_and_libraries:
name: Build single-file OpenAPI specifications and client libraries
runs-on: ubuntu-latest
outputs:
last_commit_long_sha: ${{ steps.retriever.outputs.last_commit_long_sha }}
last_commit_short_sha: ${{ steps.retriever.outputs.last_commit_short_sha }}
last_commit_tag: ${{ steps.retriever.outputs.last_commit_tag }}
java_version: ${{ steps.generator.outputs.java_okhttp_gson_version }}
typescript_axios_version: ${{ steps.generator.outputs.typescript_axios_version }}
php_version: ${{ steps.generator.outputs.php_version }}
python_version: ${{ steps.generator.outputs.python_urllib3_version }}
ruby_version: ${{ steps.generator.outputs.ruby_faraday_version }}
container:
image: openapitools/openapi-generator-cli:v7.6.0
env:
OPENAPI_GENERATOR_COMMAND: docker-entrypoint.sh
BUMP_CLIENT_LIBRARY_VERSION: ${{ inputs.type-of-change }}
CLIENT_LIBRARY_VERSION_SUFFIX: ${{ inputs.lib-version-suffix }}
OVERRIDE_CLIENT_LIBRARY_VERSION: ${{ inputs.override-lib-version }}
steps:
- name: Install pre-requisites
run: |
apt-get update
apt-get install -yqq \
gettext-base \
git \
jq
- uses: actions/checkout@v4
with:
fetch-depth: 10
fetch-tags: true
- name: Retrieve information about last commit not authored by GitHub Actions Bot and release (if any)
id: retriever
run: |
git config --global --add safe.directory $(pwd)
LAST_COMMIT_LONG_SHA=$(git rev-list --perl-regexp --author='^((?!GitHub Actions Bot).*)$' HEAD | head -n 1)
echo "last_commit_long_sha=$LAST_COMMIT_LONG_SHA" >> $GITHUB_OUTPUT
echo "last_commit_short_sha=$(git rev-parse --short $LAST_COMMIT_LONG_SHA)" >> $GITHUB_OUTPUT
echo "last_commit_tag=$(git tag --contains HEAD | grep ^v | sort | tail -n 1 || true)" >> $GITHUB_OUTPUT
- name: Validate multi-file OpenAPI specification
run: |
$OPENAPI_GENERATOR_COMMAND validate -i openapi.yaml
- name: Generate specifications and client libraries
id: generator
run: |
./shell/generate.sh
- name: Store generated artifacts and finalization scripts
uses: actions/upload-artifact@v4
with:
name: artifacts-${{ github.workflow }}-${{ github.run_id }}-${{ github.run_number }}
include-hidden-files: true
path: |
shell/sync-lib.sh
generated/artifacts
generators/**/exclusions.txt
update_specs:
name: Update and commit single-file OpenAPI specifications
runs-on: ubuntu-latest
needs: generate_specs_and_libraries
if: github.event_name == 'push'
environment: generation
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GH_ACTION_ACCESS_TOKEN }}
ref: ${{ github.ref_name }}
- uses: actions/download-artifact@v4
with:
name: artifacts-${{ github.workflow }}-${{ github.run_id }}-${{ github.run_number }}
- name: Create reference OpenAPI Specification and refresh Postman Collection
run: |
npm install prettier openapi-to-postmanv2
mkdir -p generated/artifacts/{openapi-reference,postman}
./shell/patch-openapi-definition.py \
generated/artifacts/openapi/openapi.json \
generated/artifacts/openapi-reference/openapi.json
npx prettier --write \
generated/artifacts/openapi-reference/openapi.json
npx openapi2postmanv2 \
-s generated/artifacts/openapi-reference/openapi.json \
-o generated/artifacts/postman/collection.json \
-p -O folderStrategy=Tags,parametersResolution=Example
./shell/publish-postman-collection.py \
generated/artifacts/postman/collection.json \
38453665-3be48048-00b8-43bf-8c91-82953801b7aa
env:
POSTMAN_API_KEY: ${{ secrets.POSTMAN_API_KEY }}
- name: Commit and push single-file OpenAPI specifications
run: |
if [ -z "$(git status --porcelain=v1 generated/artifacts/openapi*)" ];
then
echo "no change detected"
else
echo "changes detected"
git config user.name "GitHub Actions Bot"
git config user.email "<>"
git add generated/artifacts/openapi* && git status
git commit -m "Single file specifications refresh (${{ needs.generate_specs_and_libraries.outputs.last_commit_short_sha }})" generated/artifacts/openapi*
git push
fi
update_client_libraries:
name: "Create PR to ${{ matrix.git_repo_id }} repository using ${{ matrix.generator }} generator (${{matrix.version}})"
runs-on: ubuntu-latest
container:
image: ${{ matrix.image }}
needs: generate_specs_and_libraries
strategy:
max-parallel: 1
matrix:
include:
- generator: java/okhttp-gson
git_repo_id: onfido-java
version: ${{ needs.generate_specs_and_libraries.outputs.java_version }}
update: ${{ inputs.update-onfido-java }}
- generator: typescript-axios
git_repo_id: onfido-node
version: ${{ needs.generate_specs_and_libraries.outputs.typescript_axios_version }}
update: ${{ inputs.update-onfido-node }}
- generator: php
git_repo_id: onfido-php
image: composer:2.7
version: ${{ needs.generate_specs_and_libraries.outputs.php_version }}
update: ${{ inputs.update-onfido-php }}
- generator: python/urllib3
git_repo_id: onfido-python
image: python:3.11
extra: pipx
version: ${{ needs.generate_specs_and_libraries.outputs.python_version }}
update: ${{ inputs.update-onfido-python }}
- generator: ruby/faraday
git_repo_id: onfido-ruby
image: ruby:3.2
version: ${{ needs.generate_specs_and_libraries.outputs.ruby_version }}
update: ${{ inputs.update-onfido-ruby }}
if: github.event_name == 'workflow_dispatch'
environment: generation
steps:
- name: Install pre-requisites
if: ${{ matrix.update }}
run: |
if [ "$(command -v rsync)" = "" ];
then
if [ "$(command -v apt-get)" != "" ];
then
apt-get update
UPDATE_COMMAND="apt-get install -yqq"
else
UPDATE_COMMAND="apk add"
fi
${UPDATE_COMMAND} \
rsync \
npm \
jq \
pipx \
${{ matrix.extra }}
fi
- uses: actions/checkout@v4
if: ${{ matrix.update }}
with:
repository: onfido/${{ matrix.git_repo_id }}
- uses: actions/download-artifact@v4
if: ${{ matrix.update }}
with:
name: artifacts-${{ github.workflow }}-${{ github.run_id }}-${{ github.run_number }}
- name: Integrate generated code (${{ matrix.version }})
if: ${{ matrix.update }}
env:
ONFIDO_OPENAPI_SPEC_FOLDER: .
run: |
chmod +x shell/sync-lib.sh
shell/sync-lib.sh $(echo ${{ matrix.git_repo_id }} | sed 's/^onfido-//') ${{ matrix.generator }}
- name: Update release file and lint .md files as needed
if: ${{ matrix.update }}
run: |
TMP_FILE=$(mktemp)
RELEASE_FILE=.release.json
if [ ! -f $RELEASE_FILE ]
then
echo "{}" > $RELEASE_FILE
fi
SOURCE_REPO_URL=https://github.com/${{ github.repository_owner }}/onfido-openapi-spec
SOURCE_SHORT_SHA=${{ needs.generate_specs_and_libraries.outputs.last_commit_short_sha }}
SOURCE_LONG_SHA=${{ needs.generate_specs_and_libraries.outputs.last_commit_long_sha }}
SOURCE_VERSION=${{ inputs.override-spec-version }}
SOURCE_VERSION=${SOURCE_VERSION:-${{ needs.generate_specs_and_libraries.outputs.last_commit_tag }}}
jq --arg source_repo_url "$SOURCE_REPO_URL" --arg source_short_sha "$SOURCE_SHORT_SHA" \
--arg source_long_sha "$SOURCE_LONG_SHA" --arg source_version "$SOURCE_VERSION" \
'. += {"source": {"repo_url": $source_repo_url, "short_sha": $source_short_sha,
"long_sha": $source_long_sha, "version": $source_version},
"release": "v${{ matrix.version }}"}' $RELEASE_FILE >| $TMP_FILE
mv $TMP_FILE $RELEASE_FILE
npx prettier --write *.md
- name: Create Pull Request with changes after library update
uses: peter-evans/create-pull-request@v6
if: ${{ matrix.update }}
with:
token: ${{ secrets.GH_ACTION_ACCESS_TOKEN }}
commit-message: Upgrade after onfido-openapi-spec change ${{ needs.generate_specs_and_libraries.outputs.last_commit_short_sha }}
title: Refresh ${{ matrix.git_repo_id }} after onfido-openapi-spec update (${{ needs.generate_specs_and_libraries.outputs.last_commit_short_sha }})
body: |
Auto-generated PR with changes till commit ${{ github.repository_owner }}/onfido-openapi-spec@${{ needs.generate_specs_and_libraries.outputs.last_commit_long_sha }} (included)
Additional changes:
- None
labels: |
automated pr
branch: release-upgrade