Skip to content

Commit 0c33a2c

Browse files
committed
ci: Check File Versions
1 parent 0aac057 commit 0c33a2c

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

.github/workflows/version.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Check File Versions
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
pull_request:
7+
branches: [main, develop]
8+
9+
jobs:
10+
check-versions:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Check file versions
18+
run: |
19+
files="ezuikit.js index.js index.mjs"
20+
21+
version=""
22+
inconsistent=false
23+
24+
for file in $files; do
25+
if [ ! -f "$file" ]; then
26+
echo "缺少文件: $file"
27+
inconsistent=true
28+
continue
29+
fi
30+
v=$(head -2 "$file" | grep -Eo 'v([0-9]+\.[0-9]+\.[0-9]+)+(-[a-z]+\.[0-9]+)?')
31+
if [ -z "$v" ]; then
32+
echo "文件 $file 未检测到版本号"
33+
inconsistent=true
34+
continue
35+
fi
36+
if [ -z "$version" ]; then
37+
version="$v"
38+
else
39+
if [ "$version" != "$v" ]; then
40+
echo "文件 $file 的版本号 $v 与其它文件版本号 $version 不一致"
41+
inconsistent=true
42+
fi
43+
fi
44+
done
45+
46+
if [ "$inconsistent" = true ]; then
47+
echo "版本号不一致,禁止推送!"
48+
exit 1
49+
fi
50+
51+
echo "所有文件版本号一致: $version"

0 commit comments

Comments
 (0)