-
Notifications
You must be signed in to change notification settings - Fork 5
260 lines (251 loc) · 9.2 KB
/
pull_request_merge_checks.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
name: API Contracts CI
'on':
push:
branches:
- main
pull_request:
branches:
- main
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
openapi_changed: '${{ steps.changed-files-specific.outputs.any_changed }}'
graphql_changed: '${{ steps.changed-graphqls-files.outputs.any_changed }}'
examples_changed: '${{ steps.changed-examples.outputs.any_changed }}'
changed_graphql_files: '${{ steps.changed-graphqls-files.outputs.all_changed_files }}'
changed_openapi_files: '${{steps.changed-files-specific.outputs.all_changed_files}}'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: '20'
- name: Detect OpenAPI Changes
id: changed-files-specific
uses: tj-actions/changed-files@v34
with:
files: |
io/**/*.yaml
io/**/*.yml
io/**/*.json
files_ignore: |
kafka.yaml
**/*_examples/**/*.json
**/*_examples/**/*.yaml
- name: Detect GraphQL Changes
id: changed-graphqls-files
uses: tj-actions/changed-files@v34
with:
files: |
io/**/*.graphqls
- name: Detect Examples Changes
id: changed-examples
uses: tj-actions/changed-files@v34
with:
files: |
**/*_examples/**/*.json
**/*_examples/**/*.yaml
setup-environment:
needs: detect-changes
if: >-
needs.detect-changes.outputs.openapi_changed == 'true' ||
needs.detect-changes.outputs.graphql_changed == 'true'
runs-on: ubuntu-latest
steps:
- name: Create Environment File
run: echo "Environment variables are set"
env:
GITHUB_SHA: ${{ github.sha }}
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_WORKFLOW: ${{ github.workflow }}
GITHUB_HEAD_REF: ${{ github.head_ref }}
GITHUB_BASE_REF: ${{ github.base_ref || github.ref }}
linting-openAPI:
needs: detect-changes
if: 'needs.detect-changes.outputs.openapi_changed == ''true'' '
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: '20'
- name: Install Spectral
run: npm install -g @stoplight/spectral-cli
- name: Run Spectral Linter for OpenAPI
run: |
echo "Running Spectral linter on changed OpenAPI files"
for file in ${{ needs.detect-changes.outputs.changed_openapi_files }};
do
echo "Linting $file..."
spectral lint "$file"
done
linting-graphQL:
needs: detect-changes
if: needs.detect-changes.outputs.graphql_changed == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: '20'
- name: Install GraphQL Schema Linter
run: npm install -g graphql-schema-linter
- name: Run GraphQL Schema Linter
run: >
echo "Running GraphQL schema linter on changed files"
for file in ${{ needs.detect-changes.outputs.changed_graphql_files }};
do
echo "Linting $file..."
graphql-schema-linter "$file"
done
specmatic-examples-validation-openAPI:
needs: detect-changes
runs-on: ubuntu-latest
if: >-
needs.detect-changes.outputs.examples_changed == 'true' ||
needs.detect-changes.outputs.openapi_changed == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Validate Specmatic OpenAPI examples
run: >
docker run -v "$(pwd):/central-contract-repo:rw" znsio/specmatic
examples validate \
--contract-file /central-contract-repo/io/specmatic/examples/store/openapi/product_search_bff_v4.yaml
specmatic-examples-validation-graphQL:
needs: detect-changes
runs-on: ubuntu-latest
if: >-
needs.detect-changes.outputs.examples_changed == 'true' ||
needs.detect-changes.outputs.graphql_changed == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Validate Specmatic GraphQL examples
run: |
docker run -v "$(pwd):/central-contract-repo:rw" \
--entrypoint /bin/sh \
znsio/specmatic-graphql-trial \
-c "cd /central-contract-repo && java -jar /usr/src/app/specmatic-graphql.jar examples validate --spec-file io/specmatic/examples/store/graphql/products_bff.graphqls"
specmatic-backward-compatibility-openAPI:
needs: setup-environment
runs-on: ubuntu-latest
if: needs.detect-changes.outputs.openapi_changed == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Specmatic OpenAPI Backward Compatibility Check
run: |
docker run -v "$(pwd):/central-contract-repo:rw" \
--env GITHUB_SHA=${{ env.GITHUB_SHA }} \
--env GITHUB_REPOSITORY=${{ env.GITHUB_REPOSITORY }} \
--env GITHUB_ACTOR=${{ env.GITHUB_ACTOR }} \
--env GITHUB_WORKFLOW=${{ env.GITHUB_WORKFLOW }} \
--env GITHUB_HEAD_REF=${{ env.GITHUB_HEAD_REF }} \
--env GITHUB_BASE_REF=${{ env.GITHUB_BASE_REF }} \
--entrypoint /bin/sh znsio/specmatic \
-c "git config --global --add safe.directory /central-contract-repo && cd /central-contract-repo && java -jar /usr/src/app/specmatic.jar backward-compatibility-check --base-branch origin/main"
specmatic-backward-compatibility-graphQL:
needs: setup-environment
runs-on: ubuntu-latest
if: needs.detect-changes.outputs.graphql_changed == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Specmatic GraphQL Backward Compatibility Check
run: |
docker run -v "$(pwd):/central-contract-repo:rw" \
--env GITHUB_SHA=${{ env.GITHUB_SHA }} \
--env GITHUB_REPOSITORY=${{ env.GITHUB_REPOSITORY }} \
--env GITHUB_ACTOR=${{ env.GITHUB_ACTOR }} \
--env GITHUB_WORKFLOW=${{ env.GITHUB_WORKFLOW }} \
--env GITHUB_HEAD_REF=${{ env.GITHUB_HEAD_REF }} \
--env GITHUB_BASE_REF=${{ env.GITHUB_BASE_REF }} \
--entrypoint /bin/sh \
znsio/specmatic-graphql-trial \
-c "git config --global --add safe.directory /central-contract-repo && cd /central-contract-repo && java -jar /usr/bin/specmatic-graphql.jar backwardCompatibilityCheck"
build-summary-openAPI:
needs:
- linting-openAPI
- specmatic-examples-validation-openAPI
- specmatic-backward-compatibility-openAPI
if: always()
runs-on: ubuntu-latest
steps:
- name: Check Pipeline Status
run: >
if [[ "${{ needs.linting-openAPI.result }}" == "failure" ]];
then
echo "linting-openAPI failed!"
exit 1
fi
if [[ "${{ needs.specmatic-examples-validation-openAPI.result }}" ==
"failure" ]]; then
echo "specmatic-examples-validation-openAPI failed!"
exit 1
fi
if [[ "${{ needs.specmatic-backward-compatibility-openAPI.result }}"
== "failure" ]]; then
echo "specmatic-backward-compatibility-openAPI failed!"
exit 1
fi
echo "All OpenAPI build jobs completed successfully!"
build-summary-graphQL:
needs:
- linting-graphQL
- specmatic-examples-validation-graphQL
- specmatic-backward-compatibility-graphQL
if: always()
runs-on: ubuntu-latest
steps:
- name: Check Pipeline Status
run: >
if [[ "${{ needs.linting-graphQL.result }}" == "failure" ]];
then
echo "linting-graphQL failed!"
exit 1
fi
if [[ "${{ needs.specmatic-examples-validation-graphQL.result }}" ==
"failure" ]]; then
echo "specmatic-examples-validation-graphQL failed!"
exit 1
fi
if [[ "${{ needs.specmatic-backward-compatibility-graphQL.result }}"
== "failure" ]]; then
echo "specmatic-backward-compatibility-graphQL failed!"
exit 1
fi
echo "All GraphQL build jobs completed successfully!"
overall-build-summary:
needs:
- build-summary-graphQL
- build-summary-openAPI
if: always()
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check OpenAPI and GraphQL Summary
run: |
if [[ "${{ needs.build-summary-openAPI.result }}" == "failure" ]]; then
echo "OpenAPI related jobs failed!"
exit 1
fi
if [[ "${{ needs.build-summary-graphQL.result }}" == "failure" ]]; then
echo "GraphQL related jobs failed!"
exit 1
fi
echo "All build jobs completed successfully!"