Skip to content

Commit 20f3279

Browse files
authored
Refine: skip pr-test for dts-only changes (cocos#649)
1 parent f25e88f commit 20f3279

2 files changed

Lines changed: 79 additions & 25 deletions

File tree

.github/workflows/check-dts.yml

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,37 +52,48 @@ jobs:
5252
exit 0
5353
fi
5454
55-
GREP_FILTER='grep -v "^---" | grep -v "^-exports\[" | grep -v "^-$" | grep -v "^\-[[:space:]]*$" | grep -v "^\-\`;$"'
55+
# Detect truly removed API lines by comparing deleted vs added lines.
56+
# Lines that appear in both deleted and added sets are modifications or
57+
# snapshot reorganizations (due to index.d.ts duplication), not removals.
58+
# Only lines present in deleted but NOT in added are real breaking changes.
59+
extract_truly_deleted() {
60+
local diff_output="$1"
61+
local noise_filter='grep -v "^exports\[" | grep -v "^$" | grep -v "^[[:space:]]*$" | grep -v "^\`;" | grep -v "^[[:space:]]*}[;,]\?$" | grep -v "^export { }$" | grep -v "^[[:space:]]*static readonly version" | grep -v "^export { .*_[0-9]\+ as "'
62+
63+
# Extract deleted lines (strip leading -, normalize quotes and Object casing)
64+
local deleted
65+
deleted=$(echo "$diff_output" | grep '^-' | grep -v '^---' | sed 's/^-//' \
66+
| eval "$noise_filter" | sed "s/\"/'/g; s/\bObject\b/object/g" | sort -u || true)
67+
68+
# Extract added lines (strip leading +, normalize quotes and Object casing)
69+
local added
70+
added=$(echo "$diff_output" | grep '^+' | grep -v '^+++' | sed 's/^+//' \
71+
| eval "$noise_filter" | sed "s/\"/'/g; s/\bObject\b/object/g" | sort -u || true)
72+
73+
# Lines in deleted but NOT in added = truly removed
74+
if [ -n "$deleted" ]; then
75+
comm -23 <(echo "$deleted") <(echo "$added") || true
76+
fi
77+
}
5678
5779
# 1) Committed snapshot changes (BASE...HEAD)
58-
COMMITTED_DELETED=""
80+
COMMITTED_REMOVED=""
5981
if git diff --name-only "$BASE_REF"...HEAD | grep -q "$SNAP_FILE"; then
60-
COMMITTED_DELETED=$(git diff "$BASE_REF"...HEAD -- "$SNAP_FILE" \
61-
| grep '^-' \
62-
| grep -v '^---' \
63-
| grep -v '^-exports\[' \
64-
| grep -v '^-$' \
65-
| grep -v '^\-[[:space:]]*$' \
66-
| grep -v '^\-`;$' \
67-
|| true)
82+
DIFF_OUTPUT=$(git diff "$BASE_REF"...HEAD -- "$SNAP_FILE")
83+
COMMITTED_REMOVED=$(extract_truly_deleted "$DIFF_OUTPUT")
6884
fi
6985
7086
# 2) Uncommitted snapshot changes: the -u step regenerated the snapshot
7187
# from current code; diff HEAD vs working tree catches type changes
7288
# that were not committed as snapshot updates.
73-
UNCOMMITTED_DELETED=""
89+
UNCOMMITTED_REMOVED=""
7490
if ! git diff --quiet HEAD -- "$SNAP_FILE" 2>/dev/null; then
75-
UNCOMMITTED_DELETED=$(git diff HEAD -- "$SNAP_FILE" \
76-
| grep '^-' \
77-
| grep -v '^---' \
78-
| grep -v '^-exports\[' \
79-
| grep -v '^-$' \
80-
| grep -v '^\-[[:space:]]*$' \
81-
| grep -v '^\-`;$' \
82-
|| true)
91+
DIFF_OUTPUT=$(git diff HEAD -- "$SNAP_FILE")
92+
UNCOMMITTED_REMOVED=$(extract_truly_deleted "$DIFF_OUTPUT")
8393
fi
8494
85-
DELETED_LINES="${COMMITTED_DELETED}${UNCOMMITTED_DELETED}"
95+
# Merge and deduplicate across both sources
96+
DELETED_LINES=$(printf '%s\n%s' "$COMMITTED_REMOVED" "$UNCOMMITTED_REMOVED" | grep -v '^$' | sort -u || true)
8697
8798
if [ -z "$DELETED_LINES" ]; then
8899
echo "No DTS API breaking changes detected."

.github/workflows/pr-test.yml

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,57 @@ on:
77
types: [created]
88

99
jobs:
10-
pr-test:
11-
# 运行条件:
12-
# 1. PR 事件
13-
# 2. 评论触发 (包含 "rerun pr test",包括 "rerun pr test:debug")
10+
check-changes:
11+
# 检查是否有需要运行 pr-test 的文件变更
1412
if: |
1513
github.event_name == 'pull_request' ||
1614
(github.event_name == 'issue_comment' && github.event.issue.pull_request && contains(github.event.comment.body, 'rerun pr test'))
17-
15+
runs-on: ubuntu-latest
16+
outputs:
17+
should_run: ${{ steps.filter.outputs.should_run }}
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
ref: ${{ github.event_name == 'issue_comment' && github.event.issue.pull_request && format('refs/pull/{0}/head', github.event.issue.number) || github.ref }}
24+
25+
- name: Check changed files
26+
id: filter
27+
shell: bash
28+
run: |
29+
# 评论触发时始终运行
30+
if [ "${{ github.event_name }}" = "issue_comment" ]; then
31+
echo "should_run=true" >> "$GITHUB_OUTPUT"
32+
exit 0
33+
fi
34+
35+
BASE_REF="origin/${{ github.base_ref }}"
36+
CHANGED_FILES=$(git diff --name-only "$BASE_REF"...HEAD)
37+
38+
# 仅 dts/snapshot 相关文件变更时跳过 pr-test
39+
DTS_ONLY=true
40+
while IFS= read -r file; do
41+
case "$file" in
42+
.github/workflows/check-dts.yml|\
43+
.github/workflows/publish-dts.yml|\
44+
packages/cocos-cli-types/*|\
45+
packages/cocos-cli-types/**/*) ;;
46+
*) DTS_ONLY=false; break ;;
47+
esac
48+
done <<< "$CHANGED_FILES"
49+
50+
if [ "$DTS_ONLY" = "true" ]; then
51+
echo "Only dts-related files changed, skipping pr-test."
52+
echo "should_run=false" >> "$GITHUB_OUTPUT"
53+
else
54+
echo "should_run=true" >> "$GITHUB_OUTPUT"
55+
fi
56+
57+
pr-test:
58+
needs: check-changes
59+
if: needs.check-changes.outputs.should_run == 'true'
60+
1861
strategy:
1962
matrix:
2063
# Windows native build still uses the bundled CMake 3.24.3 and VS2022 generator.

0 commit comments

Comments
 (0)