forked from AgesEmpire/StellarSwipe-Backends
-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (126 loc) · 4.61 KB
/
Copy pathsdk-drift-check.yml
File metadata and controls
145 lines (126 loc) · 4.61 KB
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
name: SDK Type Drift Check
on:
pull_request:
branches: [main, develop]
push:
branches: [main, develop]
jobs:
sdk-drift:
name: Check OpenAPI → SDK type sync
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15-alpine
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: stellarswipe_test
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
redis:
image: redis:7-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
- name: Install dependencies
run: npm ci
# ── Step 1: Generate the OpenAPI spec from the built application ──────
- name: Build application
run: npm run build
env:
NODE_ENV: production
- name: Export OpenAPI spec
run: npm run export:openapi
env:
NODE_ENV: test
DATABASE_HOST: localhost
DATABASE_PORT: 5432
DATABASE_USER: test
DATABASE_PASSWORD: test
DATABASE_NAME: stellarswipe_test
REDIS_HOST: localhost
REDIS_PORT: 6379
JWT_SECRET: ci-jwt-secret-for-spec-export
STELLAR_NETWORK: testnet
SOROBAN_RPC_URL: https://soroban-testnet.stellar.org:443
- name: Upload generated OpenAPI spec
uses: actions/upload-artifact@v4
with:
name: openapi-spec
path: docs/generated/openapi.json
retention-days: 7
# ── Step 2: Regenerate SDK types into a temp location ─────────────────
- name: Regenerate SDK types to temp location
run: |
npx --yes openapi-typescript@6 \
docs/generated/openapi.json \
--output /tmp/openapi.generated.ts
# ── Step 3: Fail if committed types differ from regenerated types ──────
- name: Check for SDK type drift
run: |
COMMITTED="sdk/typescript/src/types/openapi.generated.ts"
GENERATED="/tmp/openapi.generated.ts"
# If the committed generated file doesn't exist yet, this is itself
# a drift — the file should be committed after initial generation.
if [ ! -f "${COMMITTED}" ]; then
echo "❌ ${COMMITTED} does not exist."
echo ""
echo "Generate it locally and commit:"
echo " npm run export:openapi"
echo " npm run sdk:generate-types"
echo " git add ${COMMITTED}"
echo " git commit -m 'chore(sdk): add generated OpenAPI types'"
exit 1
fi
# Strip auto-generated timestamp comments before diffing to avoid
# false positives from header-only changes.
strip_comments() {
grep -v '^\s*/\*' "$1" | grep -v '^\s*\*' | grep -v '^\s*//' || true
}
strip_comments "${COMMITTED}" > /tmp/committed_clean.ts
strip_comments "${GENERATED}" > /tmp/generated_clean.ts
if ! diff -u /tmp/committed_clean.ts /tmp/generated_clean.ts; then
echo ""
echo "❌ SDK types have drifted from the current OpenAPI spec."
echo ""
echo "To fix, run locally:"
echo " npm run export:openapi"
echo " npm run sdk:generate-types"
echo " git add sdk/typescript/src/types/openapi.generated.ts"
echo " git commit -m 'chore(sdk): regenerate types from updated OpenAPI spec'"
echo ""
echo "Then push and re-run CI."
exit 1
fi
echo "✅ SDK types are in sync with the OpenAPI spec."
# ── Upload diff artifact on failure for easier debugging ──────────────
- name: Upload drift diff on failure
if: failure()
run: |
diff \
sdk/typescript/src/types/openapi.generated.ts \
/tmp/openapi.generated.ts \
> /tmp/sdk-drift.patch || true
continue-on-error: true
- name: Upload drift diff artifact
if: failure()
uses: actions/upload-artifact@v4
with:
name: sdk-type-drift-diff
path: /tmp/sdk-drift.patch
retention-days: 3