[release-23.0] ci: fall back to GitHub-hosted runners on forks (#20165) #21151
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: Check out code | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
| 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@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 | |
| id: changes | |
| with: | |
| token: '' | |
| filters: | | |
| changed_files: | |
| - .github/workflows/codecov.yml | |
| - 'go/**' | |
| - go.mod | |
| - go.sum | |
| - Makefile | |
| - name: Set up Go | |
| if: steps.mode.outputs.is_full_run == 'true' || steps.changes.outputs.changed_files == 'true' | |
| uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0 | |
| with: | |
| go-version-file: go.mod | |
| cache: ${{ (github.base_ref == 'main' || (github.base_ref == '' && github.ref_name == 'main')) && 'true' || 'false' }} | |
| - 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 | |
| PACKAGES="" | |
| for dir in $PACKAGE_DIRS; do | |
| 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@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 | |
| - name: Tune the OS | |
| if: steps.mode.outputs.is_full_run == 'true' || (steps.changes.outputs.changed_files == 'true' && steps.packages.outputs.packages != '') | |
| 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 != '') | |
| 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 != '') | |
| run: | | |
| export DEBIAN_FRONTEND="noninteractive" | |
| sudo apt-get update | |
| sudo apt-get install -y make unzip g++ curl git wget ant openjdk-11-jdk | |
| mkdir -p dist bin | |
| curl --max-time 10 --retry 3 --retry-max-time 45 -s -L https://github.com/coreos/etcd/releases/download/v3.5.25/etcd-v3.5.25-linux-amd64.tar.gz | tar -zxC dist | |
| mv dist/etcd-v3.5.25-linux-amd64/{etcd,etcdctl} bin/ | |
| go mod download | |
| go install golang.org/x/tools/cmd/goimports@latest | |
| - name: Run make tools | |
| if: steps.mode.outputs.is_full_run == 'true' || (steps.changes.outputs.changed_files == 'true' && steps.packages.outputs.packages != '') | |
| run: | | |
| make 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 | |
| run: | | |
| set -exo pipefail | |
| export VTDATAROOT="/tmp/" | |
| export NOVTADMINBUILD=1 | |
| source build.env | |
| if [ "${{ steps.mode.outputs.is_full_run }}" = "true" ]; then | |
| make unit_test_cover | |
| else | |
| make COVERAGE_PACKAGES="${{ steps.packages.outputs.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@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.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 }} |