Skip to content

ci: get list of tests to run and skip from codecov ats #86

ci: get list of tests to run and skip from codecov ats

ci: get list of tests to run and skip from codecov ats #86

Workflow file for this run

name: IGNORE ME codecov-ats
on:
pull_request:
env:
CLI_VERSION: v0.1.5
# Cancel in progress workflows on pull_requests.
# https://docs.github.com/en/actions/using-jobs/using-concurrency#example-using-a-fallback-value
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
files-changed:
name: detect what files changed
runs-on: ubuntu-20.04
timeout-minutes: 3
# Map a step output to a job output
outputs:
api_docs: ${{ steps.changes.outputs.api_docs }}
backend: ${{ steps.changes.outputs.backend_all }}
backend_dependencies: ${{ steps.changes.outputs.backend_dependencies }}
backend_any_type: ${{ steps.changes.outputs.backend_any_type }}
migration_lockfile: ${{ steps.changes.outputs.migration_lockfile }}
steps:
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
- name: Check for backend file changes
uses: getsentry/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1
id: changes
with:
token: ${{ github.token }}
filters: .github/file-filters.yml
coverage-ats:
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.label_analysis.outputs.ATS_TESTS_TO_RUN }}
ATS_TESTS_TO_SKIP: ${{ steps.label_analysis.outputs.ATS_TESTS_TO_SKIP }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Set up Python 3.10.10
uses: actions/setup-python@v4
with:
python-version: "3.10.10"
# We need the setup to collect the list of tests properly
- name: Setup sentry env
uses: ./.github/actions/setup-sentry
id: setup
with:
snuba: true
# Right now, we run so few bigtable related tests that the
# overhead of running bigtable in all backend tests
# is way smaller than the time it would take to run in its own job.
bigtable: true
pg-version: 14
- name: Download Codecov CLI
run: |
pip install --extra-index-url https://pypi.org/simple --no-cache-dir codecov-cli
# Creates the commit and report objects in codecov
- name: Codecov startup
run: |
codecovcli create-commit
codecovcli create-report
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
# Sends static analysis information to codecov
- name: Static Analysis
run: |
codecovcli static-analysis --token=${CODECOV_STATIC_TOKEN} \
--folders-to-exclude .artifacts \
--folders-to-exclude .github \
--folders-to-exclude .venv \
--folders-to-exclude static \
--folders-to-exclude bin
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
CODECOV_STATIC_TOKEN: ${{ secrets.CODECOV_STATIC_TOKEN }}
# Run label analysis in dry mode to get the list of tests to run
# The base commit will be the parent commit (apparently commits on master don't exist in codecov)
- name: Label Analysis
id: label_analysis
continue-on-error: true
run: |
set +e
BASE_COMMIT=$(git rev-parse ${{ github.sha }}^)
echo $BASE_COMMIT
output=$(codecovcli --codecov-yml-path=codecov.yml label-analysis --dry-run --token=${CODECOV_STATIC_TOKEN} --base-sha=${BASE_COMMIT})
json_output=$(echo $output | grep -o -e "{.*}")
if [ $? -eq 0 ]
then
tests_to_run=$(echo $json_output | jq -r '.ats_tests_to_run[]' | tr '\n' ' ')
tests_to_skip=$(echo $json_output | jq -r '.ats_tests_to_skip[]' | tr '\n' ' ')
runner_options=$(echo $json_output | jq -r '.runner_options[]' | tr '\n' ' ')
echo $ATS_TESTS_TO_RUN
echo $ATS_TESTS_TO_SKIP
echo "ATS_TESTS_TO_RUN=$(echo $runner_options $tests_to_run)" >> "$GITHUB_OUTPUT"
echo "ATS_TESTS_TO_SKIP=$(echo $runner_options $tests_to_skip)" >> "$GITHUB_OUTPUT"
test_to_run_count=$(echo $json_output | jq '.ats_tests_to_run | length')
test_to_skip_count=$(echo $json_output | jq '.ats_tests_to_skip | length')
total_tests_count=$(($test_to_run_count + $test_to_skip_count))
echo "Selected $test_to_run_count / $total_tests_count tests to run" >> $GITHUB_STEP_SUMMARY
else
echo "ATS failed. Can't get list of tests to run. Fallback to all tests"
echo "ATS failed. Can't get list of tests to run. Fallback to all tests" >> $GITHUB_STEP_SUMMARY
echo "ATS_TESTS_TO_RUN=--cov-context=test" >> "$GITHUB_OUTPUT"
echo "ATS_TESTS_TO_SKIP=" >> "$GITHUB_OUTPUT"
fi
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
CODECOV_STATIC_TOKEN: ${{ secrets.CODECOV_STATIC_TOKEN }}
# 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
steps:
- name: Debug ATS_TESTS_TO_RUN
run: |
echo ${{ needs.coverage-ats.outputs.ATS_TESTS_TO_RUN }}
- name: Debug ATS_TESTS_TO_SKIP
run: |
echo ${{ needs.coverage-ats.outputs.ATS_TESTS_TO_SKIP }}