-
Notifications
You must be signed in to change notification settings - Fork 30
232 lines (206 loc) · 9.48 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
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'
# sshKey: ${{ secrets.POSTMAN_DEPLOY_KEY }}
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.SDK_APP_ID }}
private-key: ${{ secrets.SDK_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"
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/importapi/api.raml"
ML_RAML: "../commercetools-api-reference/api-specs/ml/api.raml"
HISTORY_RAML: "../commercetools-api-reference/api-specs/history/api.raml"
- 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)"
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/importapi/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: '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: "check pending changes"
run: echo "CHANGES_PENDING=`git status --porcelain -- ':(exclude)*gen.properties' | 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'
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: 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 }}