Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2f1fe50

Browse files
committed
Make string checks more robust
1 parent1ce311f commit2f1fe50

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

‎.github/workflows/test-database.yml‎

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ jobs:
280280
-name:Validate migration order for pull request
281281
if:github.event_name == 'pull_request'
282282
run:|
283+
# Use C locale for consistent, locale-independent string comparison
284+
export LC_ALL=C
285+
283286
# Get list of migrations from main branch
284287
git fetch origin main:main
285288
MAIN_MIGRATIONS=$(git ls-tree -r --name-only main -- util/Migrator/DbScripts/*.sql | sort)
@@ -312,6 +315,15 @@ jobs:
312315
while IFS= read -r migration; do
313316
MIGRATION_NAME=$(basename "$migration")
314317
318+
# Validate migration filename format (YYYY-MM-DD_NN_Description.sql with leading zeros)
319+
if ! [[ "$MIGRATION_NAME" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}_.+\.sql$ ]]; then
320+
echo "ERROR: Migration '$MIGRATION_NAME' does not match expected format"
321+
echo "Expected format: YYYY-MM-DD_NN_Description.sql (with leading zeros)"
322+
echo "Example: 2025-01-15_00_MyMigration.sql"
323+
VALIDATION_FAILED=1
324+
continue
325+
fi
326+
315327
# Compare migration name with last main migration
316328
if [[ "$MIGRATION_NAME" < "$LAST_MAIN_MIGRATION" ]]; then
317329
echo "ERROR: New migration '$MIGRATION_NAME' is not chronologically after '$LAST_MAIN_MIGRATION'"
@@ -323,16 +335,16 @@ jobs:
323335
324336
echo ""
325337
if [ $VALIDATION_FAILED -eq 1 ]; then
326-
echo "FAILED: One or more migrations are not in chronological order"
338+
echo "FAILED: One or more migrations are not in chronological order or incorrectly formatted"
327339
echo ""
328340
echo "Migration files must be named to execute in chronological order."
329341
echo "New migrations must have dates/names that come after existing migrations."
330-
echo "Expected format: YYYY-MM-DD_NN_Description.sql"
342+
echo "Expected format: YYYY-MM-DD_NN_Description.sql (with leading zeros)"
331343
echo ""
332344
echo "To fix this issue:"
333345
echo " 1. Rename your migration file(s) to use a date after $LAST_MAIN_MIGRATION"
334-
echo " 2. Ensure the date format is YYYY-MM-DD(with leading zeros)"
335-
echo " 3. Use _NN suffix if multiple migrations exist for the same date"
346+
echo " 2. Ensure the date format is YYYY-MM-DD with leading zeros (e.g., 2025-01-05, not 2025-1-5)"
347+
echo " 3. Use _NN suffix(e.g., _00, _01)if multiple migrations exist for the same date"
336348
exit 1
337349
fi
338350
@@ -342,6 +354,9 @@ jobs:
342354
-name:Validate migration order for push
343355
if:github.event_name == 'push' || github.event_name == 'workflow_dispatch'
344356
run:|
357+
# Use C locale for consistent, locale-independent string comparison
358+
export LC_ALL=C
359+
345360
# Get list of migrations from previous commit
346361
PREV_MIGRATIONS=$(git ls-tree -r --name-only HEAD~1 -- util/Migrator/DbScripts/*.sql 2>/dev/null | sort || echo "")
347362
@@ -374,6 +389,15 @@ jobs:
374389
while IFS= read -r migration; do
375390
MIGRATION_NAME=$(basename "$migration")
376391
392+
# Validate migration filename format (YYYY-MM-DD_NN_Description.sql with leading zeros)
393+
if ! [[ "$MIGRATION_NAME" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}_.+\.sql$ ]]; then
394+
echo "ERROR: Migration '$MIGRATION_NAME' does not match expected format"
395+
echo "Expected format: YYYY-MM-DD_NN_Description.sql (with leading zeros)"
396+
echo "Example: 2025-01-15_00_MyMigration.sql"
397+
VALIDATION_FAILED=1
398+
continue
399+
fi
400+
377401
# Compare migration name with last previous migration
378402
if [[ "$MIGRATION_NAME" < "$LAST_PREV_MIGRATION" ]]; then
379403
echo "ERROR: New migration '$MIGRATION_NAME' is not chronologically after '$LAST_PREV_MIGRATION'"
@@ -385,10 +409,11 @@ jobs:
385409
386410
echo ""
387411
if [ $VALIDATION_FAILED -eq 1 ]; then
388-
echo "FAILED: One or more migrations are not in chronological order"
412+
echo "FAILED: One or more migrations are not in chronological order or incorrectly formatted"
389413
echo ""
390414
echo "Migration files must be named to execute in chronological order."
391415
echo "New migrations must have dates/names that come after existing migrations."
416+
echo "Expected format: YYYY-MM-DD_NN_Description.sql (with leading zeros)"
392417
exit 1
393418
fi
394419
else

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp