1+ name : Check if Tests should be Skipped
2+ description : Determines if tests can be skipped based on changed files
3+
4+ inputs :
5+ head-sha :
6+ description : ' The SHA of the head commit'
7+ required : true
8+ excluded-dirs :
9+ description : ' Comma-separated list of directories to exclude'
10+ required : false
11+ default : ' docs/**,community/**,examples/**'
12+
13+ outputs :
14+ skip_tests :
15+ description : ' Whether tests should be skipped'
16+ value : ${{ steps.check_skip_tests.outputs.skip_tests }}
17+
18+ runs :
19+ using : composite
20+ steps :
21+ - name : Checkout code
22+ uses : actions/checkout@v4
23+ with :
24+ fetch-depth : 0
25+ ref : ${{ inputs.head-sha }}
26+
27+ - name : Fetch base branch
28+ shell : bash
29+ run : |
30+ git fetch origin ${{ github.base_ref }}:$GITHUB_REF_BASE
31+ env :
32+ GITHUB_REF_BASE : refs/remotes/origin/${{ github.base_ref }}
33+
34+ - name : Set excluded dirs
35+ id : set_excluded_dirs
36+ shell : bash
37+ run : |
38+ EXCLUDED_DIRS="${{ inputs.excluded-dirs }}"
39+ IFS=',' read -r -a EXCLUDED_DIRS_ARRAY <<< "$EXCLUDED_DIRS"
40+ echo "Excluded directories: ${EXCLUDED_DIRS_ARRAY[@]}"
41+ echo "EXCLUDED_DIRS_ARRAY=${EXCLUDED_DIRS_ARRAY[@]}" >> $GITHUB_ENV
42+
43+ - name : Check for excluded directory changes
44+ id : check_skip_tests
45+ shell : bash
46+ run : |
47+ CHANGED_FILES=$(git diff --name-only $GITHUB_REF_BASE ${{ inputs.head-sha }})
48+ echo "Changed files:"
49+ echo "$CHANGED_FILES"
50+
51+ # Build a regex pattern from the excluded directories
52+ EXCLUDE_PATTERN=$(IFS='|'; echo "${EXCLUDED_DIRS_ARRAY[*]}")
53+ NON_EXCLUDED_CHANGED=$(echo "$CHANGED_FILES" | grep -Ev "^($EXCLUDE_PATTERN)" || true)
54+
55+ if [[ -z "$NON_EXCLUDED_CHANGED" ]]; then
56+ echo "skip_tests=true" >> $GITHUB_ENV
57+ echo "skip_tests=true" >> $GITHUB_OUTPUT
58+ else
59+ echo "skip_tests=false" >> $GITHUB_ENV
60+ echo "skip_tests=false" >> $GITHUB_OUTPUT
61+ fi
0 commit comments