@@ -27,7 +27,7 @@ concurrency:
2727
2828jobs :
2929 api-compatibility-check :
30- name : API & Migration Compatibility Check
30+ name : API Compatibility Check
3131 runs-on : ubuntu-latest
3232
3333 steps :
6565
6666 if oasdiff breaking \
6767 --fail-on ERR \
68- --warn-ignore .github/oasdiff /.oasdiff-warn-ignore.yaml \
68+ --warn-ignore .github/api-migration-compatibility /.oasdiff-warn-ignore.yaml \
6969 base-v1-schema.json pr-v1-schema.json > v1-breaking-report.txt 2>&1; then
7070 echo "V1 API is backward compatible" > v1-breaking-status.txt
7171 else
7676
7777 if oasdiff breaking \
7878 --fail-on ERR \
79- --warn-ignore .github/oasdiff /.oasdiff-warn-ignore.yaml \
79+ --warn-ignore .github/api-migration-compatibility /.oasdiff-warn-ignore.yaml \
8080 base-v2-schema.json pr-v2-schema.json > v2-breaking-report.txt 2>&1; then
8181 echo "V2 API is backward compatible" > v2-breaking-status.txt
8282 else
@@ -139,39 +139,65 @@ jobs:
139139 id : migration_check
140140 run : |
141141 BASE_REF="origin/${{ github.event.pull_request.base.ref }}"
142- NEW_MIGRATIONS=$(git diff --name-only --diff-filter=AM "$BASE_REF"...HEAD -- "migrations/**/* .sql" 2>/dev/null || echo "")
142+ NEW_MIGRATIONS=$(git diff --name-only --diff-filter=AM "$BASE_REF"...HEAD -- "migrations/**/up .sql" 2>/dev/null || echo "")
143143
144144 if [[ -z "$NEW_MIGRATIONS" ]]; then
145145 echo "breaking_changes=0" >> $GITHUB_OUTPUT
146146 echo "warnings=0" >> $GITHUB_OUTPUT
147147 exit 0
148148 fi
149149
150+ # Load migration rules using yq
151+ RULES_FILE=".github/api-migration-compatibility/migration-rules.yaml"
152+
153+ # Extract breaking rule patterns for migrations folder
154+ BREAKING_PATTERNS=$(
155+ for rule in $(yq '.folder_rules.migrations.breaking[]' "$RULES_FILE"); do
156+ yq ".rule_patterns.$rule.pattern" "$RULES_FILE"
157+ done | paste -sd'|' -
158+ )
159+
160+ # Extract warning rule patterns for migrations folder
161+ WARNING_PATTERNS=$(
162+ for rule in $(yq '.folder_rules.migrations.warnings[]' "$RULES_FILE"); do
163+ yq ".rule_patterns.$rule.pattern" "$RULES_FILE"
164+ done | paste -sd'|' -
165+ )
166+
150167 BREAKING=0
151168 WARNINGS=0
152169
153170 while IFS= read -r file; do
154171 [[ -z "$file" ]] && continue
155- CONTENT=$(cat "$file")
156172
157- if echo "$CONTENT" | grep -iE "(DROP TABLE|DROP COLUMN|DELETE FROM|TRUNCATE)" >/dev/null; then
173+ # Check for breaking changes
174+ if grep -iEq "$BREAKING_PATTERNS" "$file"; then
158175 echo "BREAKING: $file"
159- echo "$CONTENT" | grep -inE "(DROP TABLE|DROP COLUMN|DELETE FROM|TRUNCATE)" | sed 's/^/ /'
160- BREAKING=$((BREAKING + 1))
176+ MATCH_COUNT=$(grep -icE "$BREAKING_PATTERNS" "$file")
177+ grep -inE "$BREAKING_PATTERNS" "$file" | sed 's/^/ /' || true
178+ BREAKING=$((BREAKING + MATCH_COUNT))
161179 fi
162180
163- if echo "$CONTENT" | grep -iE "(ALTER COLUMN .* TYPE|ALTER COLUMN .* SET NOT NULL|DROP INDEX|DROP CONSTRAINT)" >/dev/null; then
181+ # Check for warnings
182+ if grep -iEq "$WARNING_PATTERNS" "$file"; then
164183 echo "WARNING: $file"
165- echo "$CONTENT" | grep -inE "(ALTER COLUMN .* TYPE|ALTER COLUMN .* SET NOT NULL|DROP INDEX|DROP CONSTRAINT)" | sed 's/^/ /'
166- WARNINGS=$((WARNINGS + 1))
184+ MATCH_COUNT=$(grep -icE "$WARNING_PATTERNS" "$file")
185+ grep -inE "$WARNING_PATTERNS" "$file" | sed 's/^/ /' || true
186+ WARNINGS=$((WARNINGS + MATCH_COUNT))
167187 fi
168188 done <<< "$NEW_MIGRATIONS"
169189
170190 echo "breaking_changes=$BREAKING" >> $GITHUB_OUTPUT
171191 echo "warnings=$WARNINGS" >> $GITHUB_OUTPUT
172- continue-on-error : true
192+
193+ if [[ $BREAKING -gt 0 ]]; then
194+ echo "::error::Breaking changes detected in V1 database migrations."
195+ echo "::error::Found $BREAKING breaking change(s)."
196+ exit 1
197+ fi
173198
174199 - name : Validate V2 migrations
200+ if : success() || failure()
175201 id : v2_migration_check
176202 run : |
177203 if [[ ! -d "v2_migrations" ]]; then
@@ -181,38 +207,65 @@ jobs:
181207 fi
182208
183209 BASE_REF="origin/${{ github.event.pull_request.base.ref }}"
184- NEW_MIGRATIONS=$(git diff --name-only --diff-filter=AM "$BASE_REF"...HEAD -- "v2_migrations/**/* .sql" 2>/dev/null || echo "")
210+ NEW_MIGRATIONS=$(git diff --name-only --diff-filter=AM "$BASE_REF"...HEAD -- "v2_migrations/**/up .sql" 2>/dev/null || echo "")
185211
186212 if [[ -z "$NEW_MIGRATIONS" ]]; then
187213 echo "breaking_changes=0" >> $GITHUB_OUTPUT
188214 echo "warnings=0" >> $GITHUB_OUTPUT
189215 exit 0
190216 fi
191217
218+ # Load migration rules using yq
219+ RULES_FILE=".github/api-migration-compatibility/migration-rules.yaml"
220+
221+ # Extract breaking rule patterns for v2_migrations folder
222+ BREAKING_PATTERNS=$(
223+ for rule in $(yq '.folder_rules.v2_migrations.breaking[]' "$RULES_FILE"); do
224+ yq ".rule_patterns.$rule.pattern" "$RULES_FILE"
225+ done | paste -sd'|' -
226+ )
227+
228+ # Extract warning rule patterns for v2_migrations folder
229+ WARNING_PATTERNS=$(
230+ for rule in $(yq '.folder_rules.v2_migrations.warnings[]' "$RULES_FILE"); do
231+ yq ".rule_patterns.$rule.pattern" "$RULES_FILE"
232+ done | paste -sd'|' -
233+ )
234+
192235 BREAKING=0
193236 WARNINGS=0
194237
195238 while IFS= read -r file; do
196239 [[ -z "$file" ]] && continue
197- CONTENT=$(cat "$file")
198240
199- if echo "$CONTENT" | grep -iE "(DROP TABLE|DROP COLUMN|DELETE FROM|TRUNCATE)" >/dev/null; then
241+ # Check for breaking changes
242+ if grep -iEq "$BREAKING_PATTERNS" "$file"; then
200243 echo "BREAKING: $file"
201- echo "$CONTENT" | grep -inE "(DROP TABLE|DROP COLUMN|DELETE FROM|TRUNCATE)" | sed 's/^/ /'
202- BREAKING=$((BREAKING + 1))
244+ MATCH_COUNT=$(grep -icE "$BREAKING_PATTERNS" "$file")
245+ grep -inE "$BREAKING_PATTERNS" "$file" | sed 's/^/ /' || true
246+ BREAKING=$((BREAKING + MATCH_COUNT))
203247 fi
204- if echo "$CONTENT" | grep -iE "(ALTER COLUMN .* TYPE|ALTER COLUMN .* SET NOT NULL|DROP INDEX|DROP CONSTRAINT)" >/dev/null; then
248+
249+ # Check for warnings
250+ if grep -iEq "$WARNING_PATTERNS" "$file"; then
205251 echo "WARNING: $file"
206- echo "$CONTENT" | grep -inE "(ALTER COLUMN .* TYPE|ALTER COLUMN .* SET NOT NULL|DROP INDEX|DROP CONSTRAINT)" | sed 's/^/ /'
207- WARNINGS=$((WARNINGS + 1))
252+ MATCH_COUNT=$(grep -icE "$WARNING_PATTERNS" "$file")
253+ grep -inE "$WARNING_PATTERNS" "$file" | sed 's/^/ /' || true
254+ WARNINGS=$((WARNINGS + MATCH_COUNT))
208255 fi
209256 done <<< "$NEW_MIGRATIONS"
210257
211258 echo "breaking_changes=$BREAKING" >> $GITHUB_OUTPUT
212259 echo "warnings=$WARNINGS" >> $GITHUB_OUTPUT
213- continue-on-error : true
260+
261+ if [[ $BREAKING -gt 0 ]]; then
262+ echo "::error::Breaking changes detected in V2 database migrations."
263+ echo "::error::Found $BREAKING breaking change(s)."
264+ exit 1
265+ fi
214266
215267 - name : Validate V2 compatible migrations
268+ if : success() || failure()
216269 id : v2_compat_migration_check
217270 run : |
218271 if [[ ! -d "v2_compatible_migrations" ]]; then
@@ -222,39 +275,65 @@ jobs:
222275 fi
223276
224277 BASE_REF="origin/${{ github.event.pull_request.base.ref }}"
225- NEW_MIGRATIONS=$(git diff --name-only --diff-filter=AM "$BASE_REF"...HEAD -- "v2_compatible_migrations/**/* .sql" 2>/dev/null || echo "")
278+ NEW_MIGRATIONS=$(git diff --name-only --diff-filter=AM "$BASE_REF"...HEAD -- "v2_compatible_migrations/**/up .sql" 2>/dev/null || echo "")
226279
227280 if [[ -z "$NEW_MIGRATIONS" ]]; then
228281 echo "breaking_changes=0" >> $GITHUB_OUTPUT
229282 echo "warnings=0" >> $GITHUB_OUTPUT
230283 exit 0
231284 fi
232285
286+ # Load migration rules using yq
287+ RULES_FILE=".github/api-migration-compatibility/migration-rules.yaml"
288+
289+ # Extract breaking rule patterns for v2_compatible_migrations folder
290+ BREAKING_PATTERNS=$(
291+ for rule in $(yq '.folder_rules.v2_compatible_migrations.breaking[]' "$RULES_FILE"); do
292+ yq ".rule_patterns.$rule.pattern" "$RULES_FILE"
293+ done | paste -sd'|' -
294+ )
295+
296+ # Extract warning rule patterns for v2_compatible_migrations folder
297+ WARNING_PATTERNS=$(
298+ for rule in $(yq '.folder_rules.v2_compatible_migrations.warnings[]' "$RULES_FILE"); do
299+ yq ".rule_patterns.$rule.pattern" "$RULES_FILE"
300+ done | paste -sd'|' -
301+ )
302+
233303 BREAKING=0
234304 WARNINGS=0
235305
236306 while IFS= read -r file; do
237307 [[ -z "$file" ]] && continue
238- CONTENT=$(cat "$file")
239308
240- if echo "$CONTENT" | grep -iE "(DROP TABLE|DROP COLUMN|DELETE FROM|TRUNCATE)" >/dev/null; then
309+ # Check for breaking changes
310+ if grep -iEq "$BREAKING_PATTERNS" "$file"; then
241311 echo "BREAKING: $file"
242- echo "$CONTENT" | grep -inE "(DROP TABLE|DROP COLUMN|DELETE FROM|TRUNCATE)" | sed 's/^/ /'
243- BREAKING=$((BREAKING + 1))
312+ MATCH_COUNT=$(grep -icE "$BREAKING_PATTERNS" "$file")
313+ grep -inE "$BREAKING_PATTERNS" "$file" | sed 's/^/ /' || true
314+ BREAKING=$((BREAKING + MATCH_COUNT))
244315 fi
245316
246- if echo "$CONTENT" | grep -iE "(ALTER COLUMN .* TYPE|ALTER COLUMN .* SET NOT NULL|DROP INDEX|DROP CONSTRAINT)" >/dev/null; then
317+ # Check for warnings
318+ if grep -iEq "$WARNING_PATTERNS" "$file"; then
247319 echo "WARNING: $file"
248- echo "$CONTENT" | grep -inE "(ALTER COLUMN .* TYPE|ALTER COLUMN .* SET NOT NULL|DROP INDEX|DROP CONSTRAINT)" | sed 's/^/ /'
249- WARNINGS=$((WARNINGS + 1))
320+ MATCH_COUNT=$(grep -icE "$WARNING_PATTERNS" "$file")
321+ grep -inE "$WARNING_PATTERNS" "$file" | sed 's/^/ /' || true
322+ WARNINGS=$((WARNINGS + MATCH_COUNT))
250323 fi
251324 done <<< "$NEW_MIGRATIONS"
252325
253326 echo "breaking_changes=$BREAKING" >> $GITHUB_OUTPUT
254327 echo "warnings=$WARNINGS" >> $GITHUB_OUTPUT
255- continue-on-error : true
328+
329+ if [[ $BREAKING -gt 0 ]]; then
330+ echo "::error::Breaking changes detected in V2 compatible database migrations."
331+ echo "::error::Found $BREAKING breaking change(s)."
332+ exit 1
333+ fi
256334
257335 - name : Calculate migration totals
336+ if : always()
258337 id : migration_report
259338 env :
260339 MIGRATION_BREAKING : ${{ steps.migration_check.outputs.breaking_changes }}
@@ -301,9 +380,7 @@ jobs:
301380 echo "Status: ${{ steps.migration_report.outputs.validation_status }}"
302381 echo "=========================================="
303382
304- - name : Fail if migration breaking changes detected
305- if : steps.migration_report.outputs.total_breaking != '0' && steps.migration_report.outputs.total_breaking != ''
306- run : |
307- echo "::error::Breaking changes detected in database migrations."
308- echo "::error::Found ${{ steps.migration_report.outputs.total_breaking }} breaking change(s)."
309- exit 1
383+ if [[ "${{ steps.migration_report.outputs.total_breaking }}" != "0" && "${{ steps.migration_report.outputs.total_breaking }}" != "" ]]; then
384+ echo "::error::Migration validation failed with breaking changes."
385+ exit 1
386+ fi
0 commit comments