|
@@ -44,10 +44,6 @@ jobs:
|
|
|
if: needs.files-changed.outputs.backend == 'true'
|
|
|
needs: files-changed
|
|
|
runs-on: ubuntu-latest
|
|
|
- # Map a step output to a job output
|
|
|
- outputs:
|
|
|
- ATS_TESTS_TO_RUN: ${{ steps.codecov_automated_test_selection.outputs.ATS_TESTS_TO_RUN }}
|
|
|
- ATS_TESTS_TO_SKIP: ${{ steps.codecov_automated_test_selection.outputs.ATS_TESTS_TO_SKIP }}
|
|
|
steps:
|
|
|
- uses: actions/checkout@v3
|
|
|
with:
|
|
@@ -73,7 +69,7 @@ jobs:
|
|
|
pg-version: 14
|
|
|
- name: Download Codecov CLI
|
|
|
run: |
|
|
|
- pip install --extra-index-url https://pypi.org/simple --no-cache-dir codecov-cli>=0.4.0
|
|
|
+ pip install --extra-index-url https://pypi.org/simple --no-cache-dir codecov-cli>=0.4.1
|
|
|
# Creates the commit and report objects in codecov
|
|
|
- name: Codecov startup
|
|
|
run: |
|
|
@@ -98,25 +94,38 @@ jobs:
|
|
|
- name: Codecov Automated Test Selection
|
|
|
id: codecov_automated_test_selection
|
|
|
run: |
|
|
|
+ # Directory for the artifacts from this step
|
|
|
+ mkdir .artifacts/codecov_ats
|
|
|
+ # This is the base for the git diff BASE..HEAD
|
|
|
BASE_COMMIT=$(git merge-base ${{ github.sha }}^ origin/master)
|
|
|
- echo $BASE_COMMIT
|
|
|
+ # Get list of tests to run from Codecov
|
|
|
output=$(codecovcli --codecov-yml-path=codecov.yml label-analysis --dry-run --token=${CODECOV_STATIC_TOKEN} --base-sha=${BASE_COMMIT}) || true
|
|
|
+ # Post processing and validation
|
|
|
if [ -n "${output}" ];
|
|
|
then
|
|
|
|
|
|
- echo ATS_TESTS_TO_RUN=$(jq <<< $output '.runner_options + .ats_tests_to_run | @json | @sh' --raw-output) >> "$GITHUB_OUTPUT"
|
|
|
- echo ATS_TESTS_TO_SKIP=$(jq <<< $output '.runner_options + .ats_tests_to_skip | @json | @sh' --raw-output) >> "$GITHUB_OUTPUT"
|
|
|
+ jq <<< $output '.runner_options + .ats_tests_to_run | @json' --raw-output > .artifacts/codecov_ats/tests_to_run.json
|
|
|
+ jq <<< $output '.runner_options + .ats_tests_to_skip | @json' --raw-output > .artifacts/codecov_ats/tests_to_skip.json
|
|
|
|
|
|
testcount() { jq <<< $output ".$1 | length"; }
|
|
|
run_count=$(testcount ats_tests_to_run)
|
|
|
skip_count=$(testcount ats_tests_to_skip)
|
|
|
- tee <<< "Selected $run_count / $(($run_count + $skip_count)) tests to run" "$GITHUB_STEP_SUMMARY"
|
|
|
+ # Parse any potential errors that made ATS fallback to running all tests
|
|
|
+ # And surface them
|
|
|
+ ats_fallback_reason=$(jq <<< "$output" '.ats_fallback_reason')
|
|
|
+ if [ "$ats_fallback_reason" == "null" ]; then
|
|
|
+ ats_success=true
|
|
|
+ else
|
|
|
+ ats_success=false
|
|
|
+ fi
|
|
|
+ tee <<< \
|
|
|
+ "{\"ats_success\": $ats_success, \"error\": $ats_fallback_reason, \"tests_to_run\": $run_count, \"tests_analyzed\": $((run_count+skip_count))}" \
|
|
|
+ "$GITHUB_STEP_SUMMARY" \
|
|
|
+ ".artifacts/codecov_ats/result.json"
|
|
|
else
|
|
|
- tee <<< "ATS failed. Can't get list of tests to run. Fallback to all tests" "$GITHUB_STEP_SUMMARY"
|
|
|
# We need not forget to add the search options in the fallback command, otherwise pytest might run more tests than expected
|
|
|
# These search options match what's defined in codecov.yml:105
|
|
|
- echo 'ATS_TESTS_TO_RUN<<EOF' >> $GITHUB_OUTPUT
|
|
|
- jq -c @json <<< '[
|
|
|
+ jq '@json' --raw-output <<< '[
|
|
|
"--cov-context=test",
|
|
|
"tests/sentry",
|
|
|
"tests/integration",
|
|
@@ -126,44 +135,53 @@ jobs:
|
|
|
"--ignore=tests/sentry/search/events",
|
|
|
"--ignore=tests/sentry/ingest/ingest_consumer/test_ingest_consumer_kafka.py",
|
|
|
"--ignore=tests/sentry/region_to_control/test_region_to_control_kafka.py"
|
|
|
- ]' >> $GITHUB_OUTPUT
|
|
|
- echo 'EOF' >> $GITHUB_OUTPUT
|
|
|
- echo ATS_TESTS_TO_SKIP="'[]'" >> "$GITHUB_OUTPUT"
|
|
|
- echo "::error ATS failed"
|
|
|
- exit 1
|
|
|
+ ]' > .artifacts/codecov_ats/tests_to_skip.json
|
|
|
+ echo '[]' > .artifacts/codecov_ats/tests_to_run.json
|
|
|
+ # If we reached this point it means that ATS failed with some error
|
|
|
+ tee <<< '{"ats_success": false, "error": "exception_raised"}' "$GITHUB_STEP_SUMMARY" ".artifacts/codecov_ats/result.json"
|
|
|
fi
|
|
|
env:
|
|
|
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
|
|
CODECOV_STATIC_TOKEN: ${{ secrets.CODECOV_STATIC_TOKEN }}
|
|
|
+ - uses: actions/upload-artifact@v3
|
|
|
+ with:
|
|
|
+ name: codecov_ats
|
|
|
+ path: .artifacts/codecov_ats
|
|
|
+ if-no-files-found: error
|
|
|
# The actual running of tests would come here, after the labels are available
|
|
|
# Something like pytest <options> $ATS_TESTS_TO_RUN
|
|
|
debug:
|
|
|
runs-on: ubuntu-latest
|
|
|
- needs: coverage-ats
|
|
|
- if: ${{ always() }}
|
|
|
+ needs:
|
|
|
+ - coverage-ats
|
|
|
+ - files-changed
|
|
|
+ # Avoids running this job if it's a frontend change
|
|
|
+ # It would fail if the coverage-ats step didn't run
|
|
|
+ if: needs.files-changed.outputs.backend == 'true'
|
|
|
steps:
|
|
|
+ - uses: actions/download-artifact@v3
|
|
|
+ with:
|
|
|
+ name: codecov_ats
|
|
|
+ path: .artifacts
|
|
|
- name: Debug ATS_TESTS_TO_RUN
|
|
|
run: |
|
|
|
- : ${{ needs.coverage-ats.outputs.ATS_TESTS_TO_RUN }}
|
|
|
- length_of_tests=$(jq <<< ${{ needs.coverage-ats.outputs.ATS_TESTS_TO_RUN }} 'length')
|
|
|
+ length_of_tests=$(cat .artifacts/tests_to_run.json | jq 'length')
|
|
|
# The 1st value doesn't count, it's '--cov-context=test' (hence -gt 1)
|
|
|
if [ $length_of_tests -gt 1 ]; then
|
|
|
echo "Running $length_of_tests tests"
|
|
|
# --raw-output0 doesn't work.
|
|
|
- jq <<< ${{ needs.coverage-ats.outputs.ATS_TESTS_TO_RUN }} 'join("\u0000")' --raw-output | tr -d '\n' | xargs -r0 echo
|
|
|
+ cat .artifacts/tests_to_run.json | jq 'join("\u0000")' --raw-output | tr -d '\n' | xargs -r0 echo 'pytest'
|
|
|
else
|
|
|
echo "No tests to run"
|
|
|
fi
|
|
|
- name: Debug ATS_TESTS_TO_SKIP
|
|
|
run: |
|
|
|
- : ${{ needs.coverage-ats.outputs.ATS_TESTS_TO_SKIP }}
|
|
|
- ATS_TESTS_TO_SKIP='${{ needs.coverage-ats.outputs.ATS_TESTS_TO_SKIP }}'
|
|
|
- length_of_tests=$(jq <<< ${{ needs.coverage-ats.outputs.ATS_TESTS_TO_SKIP }} 'length')
|
|
|
+ length_of_tests=$(cat .artifacts/tests_to_skip.json | jq 'length')
|
|
|
# The 1st value doesn't count, it's '--cov-context=test'
|
|
|
if [ $length_of_tests -gt 1 ]; then
|
|
|
echo "Running $length_of_tests tests"
|
|
|
# --raw-output0 doesn't work.
|
|
|
- jq <<< ${{ needs.coverage-ats.outputs.ATS_TESTS_TO_SKIP }} 'join("\u0000")' --raw-output | tr -d '\n' | xargs -r0 echo
|
|
|
+ cat .artifacts/tests_to_skip.json | jq 'join("\u0000")' --raw-output | tr -d '\n' | xargs -r0 echo 'pytest'
|
|
|
else
|
|
|
echo "No tests to run"
|
|
|
fi
|