ci: 仅测试PR变更模块

This commit is contained in:
zhouhao
2026-07-14 18:43:39 +08:00
parent de8c80823b
commit cf9af4efa4
2 changed files with 24 additions and 9 deletions

View File

@@ -8,9 +8,10 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
@@ -20,5 +21,5 @@ jobs:
with:
path: ~/.m2
key: ${{ runner.os }}-${{ hashFiles('**/pom.xml') }}
- name: Build with Maven
run: ./mvnw test -q
- name: Build changed modules with Maven
run: ./mvnw test -q -pl "$(./changes.sh)"

View File

@@ -1,18 +1,32 @@
#!/usr/bin/env bash
# 收集变更模块
modules=$(git diff --name-only HEAD~1 HEAD | \
while read file; do
set -euo pipefail
# 收集变更模块。
# PR 场景按目标分支对比,避免 CI 修复类提交只修改 .github 时退化为全仓库测试;
# push 场景保持原有 HEAD~1..HEAD 行为,兼容发布工作流。
if [ -n "${GITHUB_BASE_REF:-}" ]; then
git fetch origin "${GITHUB_BASE_REF}" --depth=1 >/dev/null 2>&1 || true
if git rev-parse --verify "origin/${GITHUB_BASE_REF}" >/dev/null 2>&1; then
diff_args=("origin/${GITHUB_BASE_REF}...HEAD")
else
diff_args=("HEAD~1" "HEAD")
fi
else
diff_args=("HEAD~1" "HEAD")
fi
modules=$(git diff --name-only "${diff_args[@]}" | while read -r file; do
dir=$(dirname "$file")
while [ "$dir" != "." ] && [ "$dir" != "/" ]; do
if [ -f "$dir/pom.xml" ]; then echo "$dir"; break; fi
dir=$(dirname "$dir")
done
done | sort -u | tr '\n' ',' | sed 's/,$//')
done | sort -u | paste -sd, -)
# 如果为空,则使用默认值 '.'
if [ -z "$modules" ]; then
echo "."
else
echo "$modules"
fi
fi