Skip to content

Commit 944d9f1

Browse files
ci: Add Update DependencyInfo action
Signed-off-by: unknowIfGuestInDream <[email protected]>
1 parent c8f21aa commit 944d9f1

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Update DependencyInfo
2+
3+
on:
4+
push:
5+
branches:
6+
- dependabot/** # 监听 Dependabot 创建的分支
7+
pull_request:
8+
branches:
9+
- dependabot/** # 针对 Dependabot 的 PR
10+
11+
jobs:
12+
update-dependency-info:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v3
18+
19+
- name: Set up Java
20+
uses: actions/setup-java@v3
21+
with:
22+
distribution: 'temurin'
23+
java-version: '17'
24+
25+
- name: Update DependencyInfo.java
26+
id: update-dependency-info
27+
run: |
28+
# 找到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
34+
35+
# 从<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
42+
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')
47+
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
52+
53+
- name: Commit and Push changes
54+
run: |
55+
git config --local user.name "github-actions[bot]"
56+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
57+
git add core/src/main/java/com/tlcsdm/core/util/DependencyInfo.java
58+
git commit -m "docs: Update DependencyInfo.java with latest dependency versions"
59+
git push origin HEAD
60+
61+
- name: Create Pull Request
62+
uses: peter-evans/create-pull-request@v5
63+
with:
64+
commit-message: Update DependencyInfo.java
65+
title: "docs: Update DependencyInfo.java"
66+
body: |
67+
This PR updates `DependencyInfo.java` with the latest dependency versions updated by Dependabot.
68+
branch: update-dependency-info

0 commit comments

Comments
 (0)