Skip to content

Commit 331b793

Browse files
authored
Merge pull request #2701 from GiganticMinecraft/ci/2609
ci: マイグレーションファイルバージョンにつき、全PRをチェックするようにする
2 parents c269988 + f4dbbc1 commit 331b793

File tree

1 file changed

+88
-10
lines changed

1 file changed

+88
-10
lines changed

.github/workflows/check-sql-version-duplicated-files.yml

Lines changed: 88 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,98 @@ on:
1414
- src/main/resources/db/migration/**
1515
- .github/workflows/check-sql-version-duplicated-files.yml
1616
jobs:
17-
check:
17+
check-duplicates:
1818
runs-on: ubuntu-24.04
1919
steps:
20-
- name: Checkout repository
21-
uses: actions/checkout@v5
20+
- uses: actions/checkout@v5
2221
with:
2322
fetch-depth: '0'
24-
- name: Fetch and merge develop
25-
run: git fetch origin develop && git merge --no-ff origin/develop
26-
- name: Check SQL migration files
23+
- name: Check for duplicate migration versions
2724
run: |
28-
ls src/main/resources/db/migration | grep -o -E "^V([0-9]+\.)?([0-9]+\.)?([0-9]+)" | awk 'a[$0]++ {print $0 > "result.txt"}'
29-
if [ -s result.txt ]; then
30-
echo "Some migration files have duplicated ver:"
31-
cat result.txt
25+
echo "=== Checking for duplicate Flyway migration versions ==="
26+
27+
CURRENT_FILES=$(find src/main/resources/db/migration -name "*.sql" 2>/dev/null || true)
28+
29+
if [ -z "$CURRENT_FILES" ]; then
30+
echo "No migration files found in current branch"
31+
exit 0
32+
fi
33+
34+
echo "Migration files in current branch:"
35+
echo "$CURRENT_FILES"
36+
echo ""
37+
38+
declare -A VERSION_MAP
39+
DUPLICATES_FOUND=false
40+
41+
for file in $CURRENT_FILES; do
42+
filename=$(basename "$file")
43+
# V で始まるバージョン番号を抽出(例: V1.0.0, V2.1.3__description.sql -> V1.0.0, V2.1.3)
44+
if [[ $filename =~ ^(V[0-9]+(\.[0-9]+)*) ]]; then
45+
version="${BASH_REMATCH[1]}"
46+
47+
if [ -n "${VERSION_MAP[$version]}" ]; then
48+
echo "❌ ERROR: Duplicate version found: $version"
49+
echo " File 1: ${VERSION_MAP[$version]}"
50+
echo " File 2: $file"
51+
DUPLICATES_FOUND=true
52+
else
53+
VERSION_MAP[$version]="$file"
54+
fi
55+
fi
56+
done
57+
58+
echo "=== Checking other PRs for version conflicts ==="
59+
60+
PR_DATA=$(gh pr list --state open --json number,url,files \
61+
--jq '[.[] | select(.files[].path | contains("src/main/resources/db/migration")) | {number: .number, url: .url, files: (.files | map(select(.path | contains("src/main/resources/db/migration"))) | map(.path))}]')
62+
63+
if [ "$PR_DATA" = "[]" ] || [ -z "$PR_DATA" ]; then
64+
echo "No other open PRs with migration files found"
65+
else
66+
echo "Found PRs with migration files:"
67+
echo "$PR_DATA" | jq -r '.[] | "PR #\(.number): \(.url)"'
68+
echo ""
69+
70+
echo "$PR_DATA" | jq -r '.[] | "PR#\(.number)|\(.files | join(","))"' | while IFS='|' read -r pr_info files; do
71+
pr_number=$(echo "$pr_info" | cut -d'#' -f2)
72+
73+
if [ "${{ github.event.pull_request.number }}" = "$pr_number" ]; then
74+
echo "Skipping current PR #$pr_number"
75+
continue
76+
fi
77+
78+
echo "Checking PR #$pr_number"
79+
80+
# ファイルパスをカンマ区切りから改行区切りに変換
81+
echo "$files" | tr ',' '\n' | while read -r other_file; do
82+
if [ -z "$other_file" ]; then
83+
continue
84+
fi
85+
86+
filename=$(basename "$other_file")
87+
if [[ $filename =~ ^(V[0-9]+(\.[0-9]+)*) ]]; then
88+
other_version="${BASH_REMATCH[1]}"
89+
90+
if [ -n "${VERSION_MAP[$other_version]}" ]; then
91+
echo "❌ ERROR: Version conflict with PR #$pr_number!"
92+
echo " Version: $other_version"
93+
echo " Current PR: ${VERSION_MAP[$other_version]}"
94+
echo " Other PR #$pr_number: $other_file"
95+
DUPLICATES_FOUND=true
96+
fi
97+
fi
98+
done
99+
done
100+
fi
101+
102+
echo ""
103+
if [ "$DUPLICATES_FOUND" = true ]; then
104+
echo "=== ❌ Duplicate migration versions detected ==="
32105
exit 1
106+
else
107+
echo "=== ✅ No duplicate migration versions found ==="
108+
exit 0
33109
fi
110+
env:
111+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)