+ isolate-tests:
+ name: Isolate relevant tests
+ runs-on: ubuntu-22.04
+ outputs:
+ test_names: ${{ steps.fetch_changed_files.outputs.args }}
+ steps:
+ - uses: actions/checkout@v3
+ with:
+ fetch-depth: 0
+ - id: fetch_changed_files
+ name: Getting changed test names
+ run: |
+ case '${{ github.event_name }}' in
+ pull_request)
+ firstCommit=${{ github.event.pull_request.base.sha }}
+ lastCommit=${{ github.event.pull_request.head.sha }}
+ # Get names of all dirs changed in a PR
+ dirnames=$(git diff --name-only "${firstCommit}" "${lastCommit}" | xargs dirname | sort -u)
+ echo "Dirnames: $dirnames"
+
+ # check iff tests/ dir has changed
+ only_tests=1
+ for dir in $dirnames; do
+ if [[ $dir != tests/* ]]; then
+ echo "$dir is not tests/"
+ only_tests=0
+ break
+ fi
+ done
+
+ if [ $only_tests == 1 ]; then
+ # Get the names of the innermost test dir
+ testnames=$(echo "$dirnames" | xargs -I {} basename "{}" | tr '\n' ' ')
+ echo "PR diff shows a change was done in test dirs. Running $testnames"
+ final_tests=$(echo "--exact $testnames")
+ fi
+ ;;
+ esac
+ echo "args=$final_tests" >> "$GITHUB_OUTPUT"
+