diff --git a/.github/workflows/cicd_tests.yml b/.github/workflows/cicd_tests.yml index ae3694f276..9ed0d51758 100644 --- a/.github/workflows/cicd_tests.yml +++ b/.github/workflows/cicd_tests.yml @@ -7,19 +7,11 @@ on: - dev - main - releasing/* - paths-ignore: # skip if only docs are modified - - '**.md' - - '**.rst' - - 'docs/**' pull_request: branches: - dev - main - releasing/* - paths-ignore: # skip if only docs are modified - - '**.md' - - '**.rst' - - 'docs/**' concurrency: # automatically cancel the previously triggered workflows when there's a newer version @@ -52,7 +44,59 @@ env: # When support is dropped for a version it is important to update these as appropriate. jobs: + changes: + runs-on: ubuntu-latest + permissions: + contents: read + outputs: + run_tests: ${{ steps.diff.outputs.run_tests }} + steps: + - uses: actions/checkout@v6 + with: + fetch-depth: 0 + persist-credentials: false + - id: diff + name: Determine if non-doc changes exist + env: + BASE_REF: ${{ github.base_ref }} + EVENT_NAME: ${{ github.event_name }} + EVENT_BEFORE: ${{ github.event.before }} + EVENT_SHA: ${{ github.sha }} + shell: bash + run: | + set -euo pipefail + + # Default to running tests on any failure (fail-open for safety) + trap 'echo "run_tests=true" >> "$GITHUB_OUTPUT"' ERR + + if [[ "$EVENT_NAME" == "pull_request" ]]; then + base_ref="origin/$BASE_REF" + git fetch origin "$BASE_REF" --depth=1 + changed_files=$(git diff --name-only "$base_ref"..."$EVENT_SHA") + else + before="$EVENT_BEFORE" + if [[ -z "$before" || "$before" == "0000000000000000000000000000000000000000" ]]; then + echo "run_tests=true" >> "$GITHUB_OUTPUT" + exit 0 + fi + changed_files=$(git diff --name-only "$before"..."$EVENT_SHA") + fi + + run_tests=false + while IFS= read -r file; do + [[ -z "$file" ]] && continue + if [[ "$file" == docs/* || "$file" == *.md || "$file" == *.rst ]]; then + continue + fi + run_tests=true + break + done <<< "$changed_files" + + echo "run_tests=$run_tests" >> "$GITHUB_OUTPUT" + static-checks: # Perform static type and other checks using runtests.sh + needs: changes + if: needs.changes.outputs.run_tests == 'true' runs-on: ubuntu-latest strategy: matrix: @@ -84,6 +128,8 @@ jobs: $(pwd)/runtests.sh --build --${{ matrix.opt }} -j $(nproc --all) min-dep: # Test with minumum dependencies installed for different OS, Python, and PyTorch combinations + needs: changes + if: needs.changes.outputs.run_tests == 'true' runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -167,6 +213,8 @@ jobs: NGC_TEAM: ${{ secrets.NGC_TEAM }} full-dep: # Test with full dependencies installed for different OS runners + needs: changes + if: needs.changes.outputs.run_tests == 'true' runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -238,6 +286,8 @@ jobs: shell: bash packaging: # Test package generation + needs: changes + if: needs.changes.outputs.run_tests == 'true' runs-on: ubuntu-latest env: QUICKTEST: True