Skip to content

Commit caf312e

Browse files
fix: Moving to custom github action for checking skip tests
Signed-off-by: Francisco Javier Arceo <[email protected]>
1 parent c46fea3 commit caf312e

File tree

2 files changed

+70
-4
lines changed

2 files changed

+70
-4
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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

.github/workflows/unit_tests.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ on:
55

66
jobs:
77
check_skip_tests:
8-
uses: ./.github/workflows/check_skip_tests.yml
9-
with:
10-
head-sha: ${{ github.event.pull_request.head.sha }}
11-
excluded-dirs: 'docs/**,tests/**,examples/**'
8+
runs-on: ubuntu-latest
9+
outputs:
10+
skip_tests: ${{ steps.check.outputs.skip_tests }}
11+
steps:
12+
- uses: actions/checkout@v4
13+
- id: check
14+
uses: ./.github/actions/check-skip-tests
15+
with:
16+
head-sha: ${{ github.event.pull_request.head.sha || github.sha }}
1217

1318
unit-test-python:
1419
needs: [check_skip_tests]

0 commit comments

Comments
 (0)