-
Notifications
You must be signed in to change notification settings - Fork 30
295 lines (264 loc) · 13 KB
/
sdks.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
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
on:
push:
paths:
- 'api-specs/**'
workflow_dispatch:
name: "SDK Generator"
permissions: {}
jobs:
sdk:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
language:
- java
- csharp
- typescript
- php
- postman
include:
- language: java
repository: 'commercetools/commercetools-sdk-java-v2'
apiMixin: true
API_RAML: "../commercetools-api-reference/api-specs/api/api-mixin.raml"
diffFormat: JAVA_MARKDOWN
- language: csharp
repository: 'commercetools/commercetools-dotnet-core-sdk-v2'
apiMixin: true
API_RAML: "../commercetools-api-reference/api-specs/api/api-mixin.raml"
diffFormat: DOTNET_MARKDOWN
- language: typescript
repository: 'commercetools/commercetools-sdk-typescript'
API_RAML: "../commercetools-api-reference/api-specs/api/api.raml"
diffFormat: TS_MARKDOWN
- language: php
repository: 'commercetools/commercetools-sdk-php-v2'
apiMixin: true
makeParams: "-j2"
API_RAML: "../commercetools-api-reference/api-specs/api/api-mixin.raml"
diffFormat: PHP_MARKDOWN
- language: postman
repository: 'commercetools/commercetools-postman-collection'
diffFormat: MARKDOWN
steps:
# Get GitHub token via the CT SDKs App
- name: Generate GitHub token (via CT SDKs App)
id: generate_github_token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.CT_SDKS_APP_ID }}
private-key: ${{ secrets.CT_SDKS_APP_PEM }}
owner: ${{ github.repository_owner }}
- name: Get App user
id: get_app_user
env:
GITHUB_TOKEN: ${{ steps.generate_github_token.outputs.token }}
run: |
export GH_APP_USER=`gh api /users/ct-sdks%5Bbot%5D | jq .id`
echo "email=${GH_APP_USER}+ct-sdks[bot]@users.noreply.github.com" >> "$GITHUB_OUTPUT"
- name: "Checkout api reference"
uses: actions/checkout@v4
with:
path: commercetools-api-reference
# Pass a personal access token (using our CT SDKs App) to be able to trigger other workflows
# https://help.github.com/en/actions/reference/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token
# https://github.community/t/action-does-not-trigger-another-on-push-tag-action/17148/8
token: ${{ steps.generate_github_token.outputs.token }}
- name: "Checkout SDK"
uses: actions/checkout@v4
with:
repository: ${{ matrix.repository }}
path: commercetools-sdk
token: ${{ steps.generate_github_token.outputs.token }}
- name: 'Setup Java'
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: '16'
- name: "Install Csharp"
if: ${{ matrix.language == 'csharp' }}
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
3.1.x
7.0.x
- name: "Install PHP with extensions"
if: ${{ matrix.language == 'php' }}
uses: shivammathur/setup-php@v2
with:
php-version: "7.4"
coverage: pcov
extensions: json, mbstring, intl
tools: composer
ini-values: assert.exception=1, zend.assertions=1
- name: Setup Node (uses version in .nvmrc)
if: ${{ matrix.language == 'typescript' }}
uses: actions/setup-node@v2
with:
node-version-file: 'commercetools-sdk/.nvmrc'
- name: "Switch SDK to update branch"
if: github.ref == 'refs/heads/main'
run: |
git fetch --depth=1 origin gen-sdk-updates || true
git checkout -B gen-sdk-updates origin/gen-sdk-updates || true
git checkout -B gen-sdk-updates
git log -1
working-directory: commercetools-sdk
- name: "Switch SDK to update branch"
if: github.ref != 'refs/heads/main'
run: |
git fetch --depth=1 origin ${{ github.ref_name }} || true
git checkout -B gen-sdk-updates origin/${{ github.ref_name }} || true
git checkout -B ${{ github.ref_name }}
git log -1
working-directory: commercetools-sdk
- name: "Apply SDK mixin"
if: ${{ matrix.apiMixin }}
run: |
cp commercetools-sdk/api-${{ matrix.language }}-mixin.raml commercetools-api-reference/api-specs/api/api-mixin.raml
- name: "Update GraphQL schema (CSharp)"
if: ${{ matrix.language == 'csharp' }}
run: |
cp commercetools-api-reference/api-specs/graphql/schema.sdl commercetools-sdk/commercetools.Sdk/commercetools.Sdk.GraphQL.Api/schema.graphqls
sed -i 's/^type Query implements.*/type Query {/' commercetools-sdk/commercetools.Sdk/commercetools.Sdk.GraphQL.Api/schema.graphqls
- name: "Update GraphQL schema (Java)"
if: ${{ matrix.language == 'java' }}
run: |
cp commercetools-api-reference/api-specs/graphql/schema.sdl commercetools-sdk/commercetools/commercetools-graphql-api/src/main/resources/graphql/schema.graphqls
sed -i 's/^type Query implements.*/type Query {/' commercetools-sdk/commercetools/commercetools-graphql-api/src/main/resources/graphql/schema.graphqls
- name: "Generate SDK"
if: ${{ matrix.language != 'postman' }}
run: sudo chmod 777 /usr/local/bin && make ${{ matrix.makeParams }} build
working-directory: commercetools-sdk
env:
RAML_FILE: "../commercetools-api-reference/api-specs/api/api.raml"
API_RAML: ${{ matrix.API_RAML }}
IMPORT_RAML: "../commercetools-api-reference/api-specs/import/api.raml"
ML_RAML: "../commercetools-api-reference/api-specs/ml/api.raml"
HISTORY_RAML: "../commercetools-api-reference/api-specs/history/api.raml"
- name: "Generate postman collections"
if: ${{ matrix.language == 'postman' }}
working-directory: commercetools-sdk
run: |-
sudo chmod 777 /usr/local/bin
make RAML_FILE=../commercetools-api-reference/api-specs/api/postman.raml LIB_NAME=api build
make RAML_FILE=../commercetools-api-reference/api-specs/import/api.raml LIB_NAME=import build
make RAML_FILE=../commercetools-api-reference/api-specs/connect/api.raml LIB_NAME=connect build
jq -r tostring api/collection.json > api/minified.json
mv api/minified.json api/collection.json
- name: "Checkout previous api reference"
uses: actions/checkout@v4
with:
fetch-depth: 0
path: commercetools-api-reference-previous
token: ${{ steps.generate_github_token.outputs.token }}
- name: "Store api reference version"
run: |
if [ ! -f ../commercetools-sdk/reference.txt ]; then
git log --format='%H' --no-merges -n 1 --skip 1 > ../commercetools-sdk/reference.txt
fi
echo "${{ github.sha}}" >> ../commercetools-sdk/references.txt
echo "previous=$(cat ../commercetools-sdk/reference.txt | head -n 1)" >> $GITHUB_ENV
working-directory: commercetools-api-reference-previous
- name: "Switch to previous commit"
run: git checkout ${{ env.previous }}
working-directory: commercetools-api-reference-previous
- name: "Calculate diff (API)"
run: rmf-codegen diff -f ${{ matrix.diffFormat }} -o ./changes_api.md commercetools-api-reference-previous/api-specs/api/api.raml commercetools-api-reference/api-specs/api/api.raml
- name: "Calculate diff (Import API)"
continue-on-error: true
run: rmf-codegen diff -f ${{ matrix.diffFormat }} -o ./changes_import.md commercetools-api-reference-previous/api-specs/import/api.raml commercetools-api-reference/api-specs/import/api.raml
- name: "Calculate diff (Import API)"
continue-on-error: true
run: rmf-codegen diff -f ${{ matrix.diffFormat }} -o ./changes_import.md commercetools-api-reference-previous/api-specs/importapi/api.raml commercetools-api-reference/api-specs/import/api.raml
- name: "Calculate diff (History)"
run: rmf-codegen diff -f ${{ matrix.diffFormat }} -o ./changes_history.md commercetools-api-reference-previous/api-specs/history/api.raml commercetools-api-reference/api-specs/history/api.raml
- name: 'TS changesets'
if: ${{ matrix.language == 'typescript' }}
run: |
if [ -f ./changes_api.md ]; then
echo "---" > ./commercetools-sdk/.changeset/changes_api.md
echo '"@commercetools/platform-sdk": minor' >> ./commercetools-sdk/.changeset/changes_api.md
echo "---" >> ./commercetools-sdk/.changeset/changes_api.md
echo "**Api changes**" >> ./commercetools-sdk/.changeset/changes_api.md
echo "" >> ./commercetools-sdk/.changeset/changes_api.md
cat ./changes_api.md >> ./commercetools-sdk/.changeset/changes_api.md
echo "" >> ./commercetools-sdk/.changeset/changes_api.md
fi
if [ -f ./changes_import.md ]; then
echo "---" > ./commercetools-sdk/.changeset/changes_import.md
echo '"@commercetools/importapi-sdk": minor' >> ./commercetools-sdk/.changeset/changes_import.md
echo "---" >> ./commercetools-sdk/.changeset/changes_import.md
echo "**Import changes**" >> ./commercetools-sdk/.changeset/changes_import.md
echo "" >> ./commercetools-sdk/.changeset/changes_import.md
cat ./changes_import.md >> ./commercetools-sdk/.changeset/changes_import.md
echo "" >> ./commercetools-sdk/.changeset/changes_import.md
fi
if [ -f ./changes_history.md ]; then
echo "---" > ./commercetools-sdk/.changeset/changes_history.md
echo '"@commercetools/history-sdk": minor' >> ./commercetools-sdk/.changeset/changes_history.md
echo "---" >> ./commercetools-sdk/.changeset/changes_history.md
echo "**History changes**" >> ./commercetools-sdk/.changeset/changes_history.md
echo "" >> ./commercetools-sdk/.changeset/changes_history.md
cat ./changes_history.md >> ./commercetools-sdk/.changeset/changes_history.md
echo "" >> ./commercetools-sdk/.changeset/changes_history.md
fi
- name: 'Create change file'
run: |
if [ -f ./changes_api.md ]; then
echo "**Api changes**" >> ./changes.md
echo "" >> ./changes.md
cat ./changes_api.md >> ./changes.md
echo "" >> ./changes.md
fi
if [ -f ./changes_import.md ]; then
echo "**Import changes**" >> ./changes.md
echo "" >> ./changes.md
cat ./changes_import.md >> ./changes.md
echo "" >> ./changes.md
fi
if [ -f ./changes_history.md ]; then
echo "**History changes**" >> ./changes.md
echo "" >> ./changes.md
cat ./changes_history.md >> ./changes.md
echo "" >> ./changes.md
fi
if [ -f ./changes.md ]; then
cat ./changes.md
cp ./changes.md ./commercetools-sdk/changes.md
fi
- name: "prettier"
if: ${{ matrix.language == 'typescript' }}
working-directory: commercetools-sdk
run: make prettify
- name: "check pending changes"
run: echo "CHANGES_PENDING=`git status --porcelain -- ':(exclude)*references.txt' | grep -c ^`" >> $GITHUB_ENV
working-directory: commercetools-sdk
- uses: stefanzweifel/git-auto-commit-action@v4
if: env.CHANGES_PENDING != '0' && github.ref == 'refs/heads/main' && matrix.language != 'postman'
with:
repository: commercetools-sdk
branch: gen-sdk-updates
commit_message: "build(codegen): updating SDK"
commit_author: ct-sdks[bot] <${{ steps.get_app_user.outputs.email }}>
commit_user_name: ct-sdks[bot]
commit_user_email: ${{ steps.get_app_user.outputs.email }}
- uses: stefanzweifel/git-auto-commit-action@v4
if: ${{ matrix.language == 'postman' && env.CHANGES_PENDING != '0' && github.ref == 'refs/heads/main' }}
with:
repository: commercetools-sdk
branch: master
commit_message: "TASK: Updating Postman collection"
commit_author: ct-sdks[bot] <${{ steps.get_app_user.outputs.email }}>
commit_user_name: ct-sdks[bot]
commit_user_email: ${{ steps.get_app_user.outputs.email }}
- uses: stefanzweifel/git-auto-commit-action@v4
if: github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/main'
with:
repository: commercetools-sdk
branch: ${{ github.ref_name }}
commit_message: "build(codegen): updating SDK"
commit_author: ct-sdks[bot] <${{ steps.get_app_user.outputs.email }}>
commit_user_name: ct-sdks[bot]
commit_user_email: ${{ steps.get_app_user.outputs.email }}