mirror of
https://github.com/hs-web/hsweb-framework.git
synced 2026-09-03 06:35:25 +08:00
ci: 仅测试PR变更模块
This commit is contained in:
9
.github/workflows/pull_request_5x.yml
vendored
9
.github/workflows/pull_request_5x.yml
vendored
@@ -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)"
|
||||
|
||||
24
changes.sh
24
changes.sh
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user