Skip to content

Code Coverage

Code Coverage #23671

Workflow file for this run

name: Code Coverage
on:
schedule:
- cron: '0 0 * * 6' # Saturday midnight UTC
push:
branches:
- "main"
- "release-[0-9]+.[0-9]"
tags: '**'
pull_request:
branches: '**'
concurrency:
group: format('{0}-{1}-{2}', ${{ github.ref }}, ${{ github.event_name }}, 'Code Coverage')
cancel-in-progress: true
permissions: read-all
jobs:
test:
if: github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'Backport')
name: Code Coverage
runs-on: ${{ github.repository == 'vitessio/vitess' && 'oracle-vm-8cpu-32gb-x86-64' || 'ubuntu-24.04' }}
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@b09bb98e06d4d774595224525879c09bc6e98c40 # v2.20.1
with:
egress-policy: audit
- name: Check out code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: 'false'
- name: Determine run mode
id: mode
run: |
if [ "${{ github.event_name }}" = "schedule" ]; then
echo "is_full_run=true" >> "$GITHUB_OUTPUT"
else
echo "is_full_run=false" >> "$GITHUB_OUTPUT"
fi
- name: Check for changes in files relevant to code coverage
if: steps.mode.outputs.is_full_run != 'true'
uses: dorny/paths-filter@7b450fff21473bca461d4b92ce414b9d0420d706 # v4.0.2
id: changes
with:
token: ''
# With 'every', a file is relevant only if it matches all patterns: any
# path from the brace-list, and not a test file in one of the endtoend
# test packages, which the coverage run never tests and which cannot
# be imported by unit tests. The endtoend trees are enumerated explicitly
# so that testdata fixtures whose paths merely contain an endtoend
# directory (e.g. under go/tools/ci-config) still count as relevant.
predicate-quantifier: 'every'
filters: |
changed_files:
- '{.github/workflows/codecov.yml,.github/actions/setup-mysql/action.yml,go/**,go.mod,go.sum,Makefile}'
- '!{go/test/endtoend,go/flags/endtoend,go/mysql/endtoend,go/vt/vtctl/endtoend,go/vt/vtctl/grpcvtctldserver/endtoend,go/vt/vtgate/endtoend,go/vt/vttablet/endtoend}/**/*_test.go'
- name: Set up Go
if: steps.mode.outputs.is_full_run == 'true' || steps.changes.outputs.changed_files == 'true'
uses: ./.github/actions/setup-go
- name: Detect changed Go packages
if: steps.mode.outputs.is_full_run != 'true' && steps.changes.outputs.changed_files == 'true'
id: packages
run: |
BASE_SHA="${{ github.event.pull_request.base.sha }}"
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
CHANGED_GO_FILES=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" -- '*.go')
if [ -z "$CHANGED_GO_FILES" ]; then
echo "BASE_SHA=$BASE_SHA"
echo "HEAD_SHA=$HEAD_SHA"
echo "packages=$PACKAGES"
echo "packages=" >> "$GITHUB_OUTPUT"
exit 0
fi
PACKAGE_DIRS=$(echo "$CHANGED_GO_FILES" | xargs -n1 dirname | sort -u)
# Validate as Go packages and exclude endtoend tests. Only consider
# paths under go/; anything else (e.g. ".", "changelog", ".github")
# would expand to ./.../... and pull in the full endtoend suite.
PACKAGES=""
for dir in $PACKAGE_DIRS; do
case "$dir" in
go/*) ;;
*) continue ;;
esac
case "$dir" in
*/endtoend*|go/cmd/vttestserver*) continue ;;
esac
if go list "./$dir" >/dev/null 2>&1; then
PACKAGES="${PACKAGES:+$PACKAGES }$dir"
fi
done
echo "BASE_SHA=$BASE_SHA"
echo "HEAD_SHA=$HEAD_SHA"
echo "packages=$PACKAGES"
echo "packages=$PACKAGES" >> "$GITHUB_OUTPUT"
- name: Set up python
if: steps.mode.outputs.is_full_run == 'true' || (steps.changes.outputs.changed_files == 'true' && steps.packages.outputs.packages != '')
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
- name: Tune the OS
if: steps.mode.outputs.is_full_run == 'true' || (steps.changes.outputs.changed_files == 'true' && steps.packages.outputs.packages != '')
timeout-minutes: 5
uses: ./.github/actions/tune-os
- name: Setup MySQL
if: steps.mode.outputs.is_full_run == 'true' || (steps.changes.outputs.changed_files == 'true' && steps.packages.outputs.packages != '')
timeout-minutes: 8
uses: ./.github/actions/setup-mysql
with:
flavor: mysql-8.4
- name: Get dependencies
if: steps.mode.outputs.is_full_run == 'true' || (steps.changes.outputs.changed_files == 'true' && steps.packages.outputs.packages != '')
timeout-minutes: 5
run: |
export DEBIAN_FRONTEND="noninteractive"
sudo apt-get update
sudo apt-get install -y make unzip g++ curl git wget
go mod download
- name: Run make tools
if: steps.mode.outputs.is_full_run == 'true' || (steps.changes.outputs.changed_files == 'true' && steps.packages.outputs.packages != '')
timeout-minutes: 10
run: |
make BUILD_JAVA=0 BUILD_PROTOC=0 tools
- name: Run coverage tests
if: steps.mode.outputs.is_full_run == 'true' || (steps.changes.outputs.changed_files == 'true' && steps.packages.outputs.packages != '')
timeout-minutes: 60
env:
IS_FULL_RUN: ${{ steps.mode.outputs.is_full_run }}
COVERAGE_PACKAGES: ${{ steps.packages.outputs.packages }}
run: |
set -exo pipefail
export VTDATAROOT="/tmp/"
export NOVTADMINBUILD=1
source build.env
if [ "$IS_FULL_RUN" = "true" ]; then
make unit_test_cover
else
make COVERAGE_PACKAGES="$COVERAGE_PACKAGES" unit_test_cover
fi
- name: Upload coverage reports
if: steps.mode.outputs.is_full_run == 'true' || (steps.changes.outputs.changed_files == 'true' && steps.packages.outputs.packages != '')
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v6.0.2
with:
files: coverage.out
fail_ci_if_error: true
verbose: true
flags: ${{ steps.mode.outputs.is_full_run != 'true' && 'partial' || '' }}
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}