Skip to content

Commit c970695

Browse files
committed
update workflow job steps
1 parent 1e2aa18 commit c970695

1 file changed

Lines changed: 8 additions & 65 deletions

File tree

.github/workflows/api-compatibility.yml

Lines changed: 8 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
name: API Schema Compatibility Check
22

3+
permissions:
4+
contents: read
5+
36
# This workflow:
47
# - Runs on ALL PRs that modify API-related files
58
# - Always fails if breaking changes are detected
@@ -47,55 +50,17 @@ jobs:
4750
go install github.com/oasdiff/oasdiff@v1.11.7
4851
echo "$HOME/go/bin" >> $GITHUB_PATH
4952
50-
- name: Use committed API schemas
53+
- name: Prepare PR schemas
5154
run: |
52-
echo "Using OpenAPI schemas from PR (generated by validate-openapi-spec workflow)..."
53-
54-
# Verify schemas exist (they should be committed by validate-openapi-spec workflow)
55-
if [[ ! -f "api-reference/v1/openapi_spec_v1.json" ]]; then
56-
echo "::error::V1 schema not found. The validate-openapi-spec workflow should have generated it."
57-
exit 1
58-
fi
59-
60-
if [[ ! -f "api-reference/v2/openapi_spec_v2.json" ]]; then
61-
echo "::error::V2 schema not found. The validate-openapi-spec workflow should have generated it."
62-
exit 1
63-
fi
64-
65-
# Validate JSON format
66-
if ! jq empty api-reference/v1/openapi_spec_v1.json 2>/dev/null; then
67-
echo "::error::V1 schema contains invalid JSON"
68-
exit 1
69-
fi
70-
71-
if ! jq empty api-reference/v2/openapi_spec_v2.json 2>/dev/null; then
72-
echo "::error::V2 schema contains invalid JSON"
73-
exit 1
74-
fi
75-
76-
# Copy to working files
77-
cp api-reference/v1/openapi_spec_v1.json pr-v1-schema.json
78-
cp api-reference/v2/openapi_spec_v2.json pr-v2-schema.json
79-
80-
echo "V1 schema: $(wc -c < pr-v1-schema.json) bytes"
81-
echo "V2 schema: $(wc -c < pr-v2-schema.json) bytes"
55+
jq empty api-reference/v1/openapi_spec_v1.json && cp api-reference/v1/openapi_spec_v1.json pr-v1-schema.json || { echo "::error::V1 schema invalid or missing"; exit 1; }
56+
jq empty api-reference/v2/openapi_spec_v2.json && cp api-reference/v2/openapi_spec_v2.json pr-v2-schema.json || { echo "::error::V2 schema invalid or missing"; exit 1; }
8257
8358
- name: Extract base branch schemas
8459
env:
85-
BASE_REF: ${{ github.event.pull_request.base.ref }}
8660
BASE_SHA: ${{ github.event.pull_request.base.sha }}
8761
run: |
88-
if git show "$BASE_SHA:api-reference/v1/openapi_spec_v1.json" > base-v1-schema.json 2>/dev/null; then
89-
echo "V1 schema extracted from $BASE_REF"
90-
else
91-
echo "{}" > base-v1-schema.json
92-
fi
93-
94-
if git show "$BASE_SHA:api-reference/v2/openapi_spec_v2.json" > base-v2-schema.json 2>/dev/null; then
95-
echo "V2 schema extracted from $BASE_REF"
96-
else
97-
echo "{}" > base-v2-schema.json
98-
fi
62+
git show "$BASE_SHA:api-reference/v1/openapi_spec_v1.json" > base-v1-schema.json 2>/dev/null || echo "{}" > base-v1-schema.json
63+
git show "$BASE_SHA:api-reference/v2/openapi_spec_v2.json" > base-v2-schema.json 2>/dev/null || echo "{}" > base-v2-schema.json
9964
10065
- name: Run breaking change detection
10166
id: breaking_changes
@@ -156,30 +121,8 @@ jobs:
156121
run: |
157122
echo "::error::Breaking changes detected in API schema."
158123
echo "::error::Found ${{ steps.breaking_changes.outputs.breaking_changes }} breaking change(s)."
159-
echo "::error::Please review the compatibility report and consider:"
160-
echo "::error::- Creating a new API version (v3)"
161-
echo "::error::- Using backward-compatible changes instead"
162-
echo "::error::- Coordinating with API consumers before deployment"
163124
exit 1
164125
165-
- name: Upload validation artifacts
166-
if: always()
167-
uses: actions/upload-artifact@v4
168-
with:
169-
name: api-validation-artifacts-${{ github.run_number }}
170-
path: |
171-
pr-v1-schema.json
172-
pr-v2-schema.json
173-
base-v1-schema.json
174-
base-v2-schema.json
175-
v1-breaking-report.txt
176-
v2-breaking-report.txt
177-
v1-detailed-diff.txt
178-
v2-detailed-diff.txt
179-
v1-breaking-status.txt
180-
v2-breaking-status.txt
181-
retention-days: 30
182-
183126
migration-compatibility-check:
184127
name: Migration Breaking Change Detection
185128
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)