Skip to content

Commit 956f5b7

Browse files
ci: Modify workflow
1 parent 864759d commit 956f5b7

File tree

1 file changed

+34
-19
lines changed

1 file changed

+34
-19
lines changed

.github/workflows/update-dependency-info.yml

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ jobs:
1515
steps:
1616
- name: Checkout code
1717
uses: actions/checkout@v3
18+
with:
19+
fetch-depth: 2 # 确保可以访问前一个提交
1820

1921
- name: Set up Java
2022
uses: actions/setup-java@v3
@@ -26,32 +28,45 @@ jobs:
2628
id: update-dependency-info
2729
run: |
2830
# 找到Dependabot更新的pom.xml文件
29-
UPDATED_DEP=$(git diff HEAD~1 HEAD --name-only | grep 'pom.xml')
30-
if [ -z "$UPDATED_DEP" ]; then
31-
echo "No pom.xml file updated. Exiting."
32-
exit 0
33-
fi
31+
# 检查是否有前一个提交
32+
if git rev-parse HEAD~1 >/dev/null 2>&1; then
33+
UPDATED_DEP=$(git diff HEAD~1 HEAD --name-only | grep 'pom.xml' || true)
34+
else
35+
# 如果是初始提交,只检查当前提交中的pom.xml文件
36+
UPDATED_DEP=$(git show --name-only --pretty=format: HEAD | grep 'pom.xml' || true)
37+
fi
38+
39+
if [ -z "$UPDATED_DEP" ]; then
40+
echo "No pom.xml file updated. Exiting."
41+
exit 0
42+
fi
3443
3544
# 从<properties>中提取依赖名和版本号
36-
for dep in $UPDATED_DEP; do
37-
DEP_PROPERTIES=$(xmllint --xpath "//project/properties/*" $dep 2>/dev/null)
38-
if [ -z "$DEP_PROPERTIES" ]; then
39-
echo "No properties found in $dep. Exiting."
40-
exit 0
41-
fi
45+
for dep in $UPDATED_DEP; do
46+
DEP_PROPERTIES=$(xmllint --xpath "//project/properties/*" $dep 2>/dev/null || true)
47+
if [ -z "$DEP_PROPERTIES" ]; then
48+
echo "No properties found in $dep. Skipping."
49+
continue
50+
fi
4251
43-
# 遍历<properties>中的每个依赖并更新DependencyInfo.java
44-
echo "$DEP_PROPERTIES" | while read -r line; do
45-
DEP_NAME=$(echo $line | sed -n 's/<\([^>]*\)>.*/\1/p')
46-
DEP_VERSION=$(echo $line | sed -n 's/.*>\([^<]*\)<.*/\1/p')
52+
# 遍历<properties>中的每个依赖并更新DependencyInfo.java
53+
echo "$DEP_PROPERTIES" | while read -r line; do
54+
DEP_NAME=$(echo $line | sed -n 's/<\([^>]*\)>.*/\1/p')
55+
DEP_VERSION=$(echo $line | sed -n 's/.*>\([^<]*\)<.*/\1/p')
4756
48-
# 替换DependencyInfo.java中的版本号
49-
sed -i "s/\($DEP_NAME\s*=\s*\"[^\"]*\)/\1$DEP_VERSION/" core/src/main/java/com/tlcsdm/core/util/DependencyInfo.java
50-
done
51-
done
57+
# 替换DependencyInfo.java中的版本号
58+
sed -i "s/\($DEP_NAME\s*=\s*\"\)[^\"]*/\1$DEP_VERSION/" core/src/main/java/com/tlcsdm/core/util/DependencyInfo.java
59+
done
60+
done
5261
5362
- name: Commit and Push changes
5463
run: |
64+
# 检查是否有文件需要提交
65+
if git diff --quiet --exit-code core/src/main/java/com/tlcsdm/core/util/DependencyInfo.java; then
66+
echo "No changes to DependencyInfo.java"
67+
exit 0
68+
fi
69+
5570
git config --local user.name "github-actions[bot]"
5671
git config --local user.email "github-actions[bot]@users.noreply.github.com"
5772
git add core/src/main/java/com/tlcsdm/core/util/DependencyInfo.java

0 commit comments

Comments
 (0)