Skip to content

Commit c869174

Browse files
committed
add check-backend-changed action
1 parent 1466c99 commit c869174

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: 'Check if backend-relevant files changed'
2+
description: 'Determine whether the CI for a given backend should run or be skipped'
3+
inputs:
4+
backend:
5+
description: 'Backend name matching its third_party/ subdirectory (e.g. xpu, nvidia, hcu)'
6+
required: true
7+
outputs:
8+
should_skip:
9+
description: 'true if no backend-relevant files changed and CI can be safely skipped'
10+
value: ${{ steps.check.outputs.should_skip }}
11+
12+
runs:
13+
using: 'composite'
14+
steps:
15+
- name: Check if backend-relevant files changed
16+
id: check
17+
shell: bash
18+
run: |
19+
BACKEND="${{ inputs.backend }}"
20+
# Extract current workflow file path from github.workflow_ref
21+
# Format: owner/repo/.github/workflows/file.yml@ref
22+
WORKFLOW_REF="${{ github.workflow_ref }}"
23+
CURRENT_WORKFLOW=$(echo "$WORKFLOW_REF" | sed 's/.*\/\(\.github\/workflows\/[^@]*\)@.*/\1/')
24+
echo "Current workflow file: $CURRENT_WORKFLOW"
25+
echo "Backend: $BACKEND"
26+
if [ "${{ github.event_name }}" == "pull_request" ]; then
27+
FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }})
28+
else
29+
FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }})
30+
fi
31+
SHOULD_SKIP=true
32+
# If no changes were made, we need to run the CI process to avoid any misjudgments.
33+
if [ -z "$FILES" ]; then
34+
echo "No files changed, running CI by default"
35+
SHOULD_SKIP=false
36+
else
37+
while IFS= read -r file; do
38+
# Skip empty lines
39+
if [ -z "$file" ]; then
40+
continue
41+
fi
42+
# Current workflow file changed → always run
43+
if [[ "$file" == "$CURRENT_WORKFLOW" ]]; then
44+
echo "'$file' -> This workflow file changed, need to run"
45+
SHOULD_SKIP=false
46+
break
47+
fi
48+
# Check if the file is a documentation file (same logic as check-docs-only)
49+
if [[ ! "$file" =~ CMakeLists\.txt$ ]] && [[ "$file" =~ (\.(md|yml|txt)$|CODEOWNERS$) ]]; then
50+
echo "'$file' -> Doc file, not relevant to CI decision"
51+
continue
52+
fi
53+
# It is a code file. Check whether it lives inside third_party/
54+
if [[ "$file" == third_party/* ]]; then
55+
if [[ "$file" == third_party/${BACKEND}/* ]]; then
56+
echo "'$file' -> Backend '$BACKEND' file changed, need to run"
57+
SHOULD_SKIP=false
58+
break
59+
else
60+
echo "'$file' -> Other backend file, not relevant to '$BACKEND'"
61+
continue
62+
fi
63+
else
64+
# Core code file (outside third_party/) — affects all backends
65+
echo "'$file' -> Core code file changed, need to run"
66+
SHOULD_SKIP=false
67+
break
68+
fi
69+
done <<< "$FILES"
70+
fi
71+
echo "should_skip=$SHOULD_SKIP" >> $GITHUB_OUTPUT
72+
if [ "$SHOULD_SKIP" == "true" ]; then
73+
echo "✅ No relevant files changed for backend '$BACKEND'. Will skip CI."
74+
else
75+
echo "🚀 Relevant files changed for backend '$BACKEND'. Will run CI."
76+
fi

0 commit comments

Comments
 (0)