Skip to content

Commit 85cef32

Browse files
ci: add backward compatibillity check
Signed-off-by: venilinvasilev <[email protected]>
1 parent 9e5d7b9 commit 85cef32

File tree

1 file changed

+131
-0
lines changed

1 file changed

+131
-0
lines changed
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
name: API Version Check
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
- develop
8+
- release/*
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
check-api-changes:
15+
name: Check API Breaking Changes
16+
runs-on: hiero-client-sdk-linux-medium
17+
18+
steps:
19+
- name: Harden Runner
20+
uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
21+
with:
22+
egress-policy: audit
23+
24+
- name: Checkout Code
25+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
26+
with:
27+
submodules: true
28+
fetch-depth: 0
29+
30+
- name: Install Task
31+
uses: arduino/setup-task@b91d5d2c96a56797b48ac1e0e89220bf64044611 # v2.0.0
32+
with:
33+
version: 3.35.1
34+
35+
- name: Install PNPM
36+
uses: step-security/action-setup@92da25bc4fa3a114b7a78c686a5ec142ccb12c8b # v4.1.1
37+
with:
38+
version: 9.15.5
39+
40+
- name: Setup Node
41+
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
42+
with:
43+
node-version: "22"
44+
cache: pnpm
45+
46+
- name: Install Dependencies
47+
run: pnpm install
48+
49+
- name: Build Base Commit
50+
run: |
51+
echo "Building base commit: ${{ github.event.pull_request.base.sha }}"
52+
git checkout ${{ github.event.pull_request.base.sha }}
53+
task build
54+
cp lib/index.d.ts base.d.ts
55+
echo "Base build completed"
56+
57+
- name: Build Head Commit
58+
run: |
59+
echo "Building head commit: ${{ github.event.pull_request.head.sha }}"
60+
git checkout ${{ github.event.pull_request.head.sha }}
61+
task build
62+
cp lib/index.d.ts head.d.ts
63+
echo "Head build completed"
64+
65+
- name: Install ts-semver-detector
66+
run: pnpm add -g ts-semver-detector
67+
68+
- name: Check API Changes
69+
run: |
70+
echo "Comparing API changes between base and head commits..."
71+
72+
# Check if both declaration files exist
73+
if [ ! -f "base.d.ts" ]; then
74+
echo "ERROR: Base TypeScript declaration file not found"
75+
exit 1
76+
fi
77+
78+
if [ ! -f "head.d.ts" ]; then
79+
echo "ERROR: Head TypeScript declaration file not found"
80+
exit 1
81+
fi
82+
83+
# Run ts-semver-detector
84+
ts-semver-detector \
85+
--old base.d.ts \
86+
--new head.d.ts \
87+
--format json \
88+
--output report.json || {
89+
echo "ERROR: ts-semver-detector failed to run"
90+
exit 1
91+
}
92+
93+
# Check the results
94+
if [ -f "report.json" ]; then
95+
echo "API Change Report:"
96+
cat report.json | jq '.'
97+
98+
# Check for breaking changes
99+
BREAKING_CHANGES=$(cat report.json | jq -r '.breakingChanges | length' 2>/dev/null || echo "0")
100+
101+
if [ "$BREAKING_CHANGES" -gt 0 ]; then
102+
echo "FAILURE: BREAKING CHANGES DETECTED!"
103+
echo "This PR contains $BREAKING_CHANGES breaking change(s)."
104+
echo "Please review the changes and consider updating the major version."
105+
echo ""
106+
echo "Breaking changes:"
107+
cat report.json | jq -r '.breakingChanges[] | "- " + .message'
108+
exit 1
109+
else
110+
echo "SUCCESS: No breaking changes detected"
111+
112+
# Show other changes
113+
NEW_FEATURES=$(cat report.json | jq -r '.newFeatures | length' 2>/dev/null || echo "0")
114+
BUG_FIXES=$(cat report.json | jq -r '.bugFixes | length' 2>/dev/null || echo "0")
115+
116+
if [ "$NEW_FEATURES" -gt 0 ] || [ "$BUG_FIXES" -gt 0 ]; then
117+
echo "Other changes detected:"
118+
if [ "$NEW_FEATURES" -gt 0 ]; then
119+
echo " - $NEW_FEATURES new feature(s)"
120+
fi
121+
if [ "$BUG_FIXES" -gt 0 ]; then
122+
echo " - $BUG_FIXES bug fix(es)"
123+
fi
124+
fi
125+
126+
echo "API changes are backward compatible"
127+
fi
128+
else
129+
echo "ERROR: No report generated by ts-semver-detector"
130+
exit 1
131+
fi

0 commit comments

Comments
 (0)