-
Notifications
You must be signed in to change notification settings - Fork 1.2k
58 lines (50 loc) · 1.81 KB
/
check_skip_tests.yml
File metadata and controls
58 lines (50 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
name: Check if Tests should be Skipped
on:
workflow_call:
inputs:
head-sha:
required: true
type: string
excluded-dirs:
required: false
type: string
default: 'docs/**,community/**,examples/**'
jobs:
check-changes:
runs-on: ubuntu-latest
outputs:
skip_tests: ${{ steps.check_skip_tests.outputs.skip_tests }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ inputs.head-sha }}
- name: Fetch base branch
run: |
git fetch origin ${{ github.base_ref }}:$GITHUB_REF_BASE
env:
GITHUB_REF_BASE: refs/remotes/origin/${{ github.base_ref }}
- name: Set excluded dirs
id: set_excluded_dirs
run: |
EXCLUDED_DIRS="${{ inputs.excluded-dirs }}"
IFS=',' read -r -a EXCLUDED_DIRS_ARRAY <<< "$EXCLUDED_DIRS"
echo "Excluded directories: ${EXCLUDED_DIRS_ARRAY[@]}"
echo "EXCLUDED_DIRS_ARRAY=${EXCLUDED_DIRS_ARRAY[@]}" >> $GITHUB_ENV
- name: Check for excluded directory changes
id: check_skip_tests
run: |
CHANGED_FILES=$(git diff --name-only $GITHUB_REF_BASE ${{ inputs.head-sha }})
echo "Changed files:"
echo "$CHANGED_FILES"
# Build a regex pattern from the excluded directories
EXCLUDE_PATTERN=$(IFS='|'; echo "${EXCLUDED_DIRS_ARRAY[*]}")
NON_EXCLUDED_CHANGED=$(echo "$CHANGED_FILES" | grep -Ev "^($EXCLUDE_PATTERN)" || true)
if [[ -z "$NON_EXCLUDED_CHANGED" ]]; then
echo "skip_tests=true" >> "$GITHUB_ENV"
echo "::set-output name=skip_tests::true"
else
echo "skip_tests=false" >> "$GITHUB_ENV"
echo "::set-output name=skip_tests::false"
fi