Zh new release #107
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: Main (test, releases) | |
| on: | |
| # # Indicates I want to run this workflow on all branches, PR, and tags | |
| push: | |
| branches: ["master"] | |
| tags: ["*"] | |
| pull_request: | |
| branches: [ "*" ] | |
| # TiDB versions used in tests - single source of truth | |
| # Latest version of each minor series: 6.1.x, 6.5.x, 7.1.x, 7.5.x, 8.1.x, 8.5.x | |
| env: | |
| TIDB_VERSIONS: "6.1.7 6.5.12 7.1.6 7.5.7 8.1.2 8.5.3" | |
| jobs: | |
| lint: | |
| runs-on: ubuntu-22.04 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| command: | |
| - make vet | |
| - make fmtcheck | |
| steps: | |
| - name: Checkout Git repo | |
| uses: actions/checkout@v4 | |
| - name: Running ${{ matrix.command }} | |
| run: ${{ matrix.command }} | |
| prepare-dependencies: | |
| name: Prepare Dependencies | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - name: Checkout Git repo | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 1 | |
| - name: Validate TiDB versions sync | |
| run: | | |
| # Extract TiDB versions from test matrix and compare with env.TIDB_VERSIONS | |
| EXPECTED_VERSIONS="${{ env.TIDB_VERSIONS }}" | |
| MATRIX_VERSIONS=$(grep -E "testtidb[0-9]" .github/workflows/main.yml | sed 's/.*testtidb\([0-9.]*\).*/\1/' | tr '\n' ' ' | xargs) | |
| echo "Expected versions (from env): $EXPECTED_VERSIONS" | |
| echo "Matrix versions (from test targets): $MATRIX_VERSIONS" | |
| # Check if versions match (simple check - both should contain same versions) | |
| MISSING="" | |
| for version in $EXPECTED_VERSIONS; do | |
| if ! echo "$MATRIX_VERSIONS" | grep -q "$version"; then | |
| MISSING="$MISSING $version" | |
| fi | |
| done | |
| if [ -n "$MISSING" ]; then | |
| echo "ERROR: TiDB versions in env.TIDB_VERSIONS not found in test matrix: $MISSING" | |
| echo "Please ensure test matrix includes testtidb* entries for all versions in env.TIDB_VERSIONS" | |
| exit 1 | |
| fi | |
| echo "✓ TiDB versions are in sync" | |
| - name: Set up Go | |
| uses: actions/setup-go@v4 | |
| with: | |
| go-version-file: go.mod | |
| - name: Download Terraform | |
| run: | | |
| mkdir -p bin | |
| curl -sfL https://releases.hashicorp.com/terraform/1.5.6/terraform_1.5.6_linux_amd64.zip > bin/terraform.zip | |
| cd bin && unzip terraform.zip && rm terraform.zip && chmod +x terraform | |
| - name: Vendor Go dependencies | |
| run: go mod vendor | |
| # Note: TiDB tests now use Docker images with Buildx caching instead of TiUP | |
| # Docker images are cached per version in individual test jobs | |
| - name: Pre-pull Docker images | |
| run: | | |
| # Pre-pull all Docker images used in tests | |
| # Note: Docker layer cache is ephemeral per job, but pre-pulling here documents | |
| # what images are needed and can help with local testing | |
| echo "Pre-pulling Docker images for MySQL, Percona, and MariaDB tests..." | |
| docker pull mysql:5.6 || true | |
| docker pull mysql:5.7 || true | |
| docker pull mysql:8.0 || true | |
| docker pull percona:5.7 || true | |
| docker pull percona:8.0 || true | |
| docker pull mariadb:10.3 || true | |
| docker pull mariadb:10.8 || true | |
| docker pull mariadb:10.10 || true | |
| echo "Docker images pre-pull complete (images will be pulled again in test jobs with layer caching)" | |
| - name: Upload Terraform binary | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: terraform-binary | |
| path: bin/terraform | |
| retention-days: 1 | |
| - name: Upload vendor directory | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: vendor-dir | |
| path: vendor/ | |
| retention-days: 1 | |
| compression-level: 6 | |
| tests: | |
| runs-on: ubuntu-22.04 | |
| needs: [prepare-dependencies] | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| target: | |
| - testversion5.6 | |
| - testversion5.7 | |
| - testversion8.0 | |
| - testpercona5.7 | |
| - testpercona8.0 | |
| - testmariadb10.3 | |
| - testmariadb10.8 | |
| - testmariadb10.10 | |
| # Track https://github.com/pingcap/tidb/tags | |
| # TiDB versions must match env.TIDB_VERSIONS: 6.1.7 6.5.12 7.1.6 7.5.7 8.1.2 8.5.3 | |
| # Latest version of each minor series | |
| - testtidb6.1.7 | |
| - testtidb6.5.12 | |
| - testtidb7.1.6 | |
| - testtidb7.5.7 | |
| - testtidb8.1.2 | |
| - testtidb8.5.3 | |
| steps: | |
| - name: Checkout Git repo | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 1 | |
| - name: Set up Go | |
| uses: actions/setup-go@v4 | |
| with: | |
| go-version-file: go.mod | |
| - name: Download Terraform binary | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: terraform-binary | |
| path: bin/ | |
| - name: Download vendor directory | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: vendor-dir | |
| path: vendor/ | |
| - name: Make Terraform executable | |
| run: chmod +x bin/terraform | |
| - name: Cache apt packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: /var/cache/apt | |
| key: ${{ runner.os }}-apt-${{ hashFiles('**/.github/workflows/main.yml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-apt- | |
| - name: Install mysql client | |
| run: | | |
| sudo apt-get update -qq | |
| sudo apt-get install -y --no-install-recommends mysql-client | |
| - name: Set up Docker Buildx | |
| if: contains(matrix.target, 'testversion') || contains(matrix.target, 'testpercona') || contains(matrix.target, 'testmariadb') | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Determine Docker image for this test | |
| if: contains(matrix.target, 'testversion') || contains(matrix.target, 'testpercona') || contains(matrix.target, 'testmariadb') | |
| id: docker-image | |
| run: | | |
| if [[ "${{ matrix.target }}" == testversion5.6 ]]; then | |
| echo "image=mysql:5.6" >> $GITHUB_OUTPUT | |
| elif [[ "${{ matrix.target }}" == testversion5.7 ]]; then | |
| echo "image=mysql:5.7" >> $GITHUB_OUTPUT | |
| elif [[ "${{ matrix.target }}" == testversion8.0 ]]; then | |
| echo "image=mysql:8.0" >> $GITHUB_OUTPUT | |
| elif [[ "${{ matrix.target }}" == testpercona5.7 ]]; then | |
| echo "image=percona:5.7" >> $GITHUB_OUTPUT | |
| elif [[ "${{ matrix.target }}" == testpercona8.0 ]]; then | |
| echo "image=percona:8.0" >> $GITHUB_OUTPUT | |
| elif [[ "${{ matrix.target }}" == testmariadb10.3 ]]; then | |
| echo "image=mariadb:10.3" >> $GITHUB_OUTPUT | |
| elif [[ "${{ matrix.target }}" == testmariadb10.8 ]]; then | |
| echo "image=mariadb:10.8" >> $GITHUB_OUTPUT | |
| elif [[ "${{ matrix.target }}" == testmariadb10.10 ]]; then | |
| echo "image=mariadb:10.10" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Pull and cache Docker image using Buildx | |
| if: contains(matrix.target, 'testversion') || contains(matrix.target, 'testpercona') || contains(matrix.target, 'testmariadb') | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: Dockerfile.mysql | |
| push: false | |
| tags: ${{ steps.docker-image.outputs.image }} | |
| build-args: | | |
| MYSQL_IMAGE=${{ steps.docker-image.outputs.image }} | |
| cache-from: type=gha,scope=${{ steps.docker-image.outputs.image }} | |
| cache-to: type=gha,mode=max,scope=${{ steps.docker-image.outputs.image }} | |
| - name: Extract TiDB version from test target | |
| id: extract-tidb-version | |
| if: contains(matrix.target, 'tidb') | |
| run: | | |
| # Extract version from testtidb6.1.7 -> 6.1.7 | |
| VERSION=$(echo "${{ matrix.target }}" | sed 's/testtidb//') | |
| echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
| echo "TiDB version for this test: ${VERSION}" | |
| - name: Cache TiUP binary (shared across all TiDB tests) | |
| id: cache-tiup-binary-test | |
| if: contains(matrix.target, 'tidb') | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.tiup/bin | |
| ~/.tiup/manifests | |
| # Cache TiUP binary separately (small, ~20MB) - shared by all TiDB tests | |
| key: ${{ runner.os }}-tiup-binary-${{ hashFiles('.github/workflows/main.yml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-tiup-binary- | |
| - name: Cache TiDB components for this specific version | |
| id: cache-tidb-version | |
| if: contains(matrix.target, 'tidb') | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.tiup/components | |
| # Cache components directory per version (~700-800MB per version instead of 4.5GB total) | |
| # Each test job caches only the version it needs | |
| key: ${{ runner.os }}-tidb-${{ steps.extract-tidb-version.outputs.version }}-${{ hashFiles('.github/workflows/main.yml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-tidb-${{ steps.extract-tidb-version.outputs.version }}- | |
| - name: Install TiUP (if not cached) | |
| if: contains(matrix.target, 'tidb') | |
| run: | | |
| if ! command -v tiup &> /dev/null; then | |
| curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh | |
| echo "$HOME/.tiup/bin" >> $GITHUB_PATH | |
| else | |
| echo "$HOME/.tiup/bin" >> $GITHUB_PATH | |
| fi | |
| - name: Update TiUP and playground component | |
| if: contains(matrix.target, 'tidb') | |
| run: | | |
| export PATH=$HOME/.tiup/bin:$PATH | |
| tiup update --self || true | |
| tiup update playground || true | |
| - name: Install TiDB components for this version (if not cached) | |
| if: contains(matrix.target, 'tidb') && steps.cache-tidb-version.outputs.cache-hit != 'true' | |
| run: | | |
| export PATH=$HOME/.tiup/bin:$PATH | |
| VERSION="${{ steps.extract-tidb-version.outputs.version }}" | |
| echo "Installing TiDB components for v${VERSION} (cache miss)..." | |
| tiup install tidb:v${VERSION} || true | |
| tiup install pd:v${VERSION} || true | |
| tiup install tikv:v${VERSION} || true | |
| echo "TiDB v${VERSION} components installed and will be cached for next run" | |
| - name: Run tests {{ matrix.target }} | |
| env: | |
| GOFLAGS: -mod=vendor | |
| run: make ${{ matrix.target }} | |
| # DISABLED to figure out GPG signing issue on Github Actions | |
| # possibly due to lack of TTY inside docker? | |
| # release: | |
| # name: Release | |
| # needs: [tests] | |
| # # Can't use non-semvar for the testing tag | |
| # # https://github.com/orgs/goreleaser/discussions/3708 | |
| # if: ( startsWith( github.ref, 'refs/tags/v' ) || | |
| # startsWith(github.ref, 'refs/tags/v0.0.0-rc') ) | |
| # runs-on: ubuntu-22.04 | |
| # steps: | |
| # - name: Checkout Git repo | |
| # uses: actions/checkout@v4 | |
| # # Goreleaser | |
| # - name: Set up Go | |
| # uses: actions/setup-go@v4 | |
| # - name: Run GoReleaser | |
| # uses: goreleaser/goreleaser-action@v6 | |
| # with: | |
| # distribution: goreleaser | |
| # version: '~> v2' | |
| # # Run goreleaser and ignore non-committed files (downloaded artifacts) | |
| # args: release --clean --skip=validate --verbose | |
| # env: | |
| # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # terraform-provider-release: | |
| # needs: [release] | |
| # name: 'Terraform Provider Release' | |
| # uses: hashicorp/ghaction-terraform-provider-release/.github/workflows/community.yml@v5 | |
| # secrets: | |
| # gpg-private-key: '${{ secrets.GPG_PRIVATE_KEY }}' | |
| # with: | |
| # setup-go-version-file: 'go.mod' |