Skip to content

Zh new release

Zh new release #105

Workflow file for this run

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
- name: Cache TiUP binary
id: cache-tiup-binary
uses: actions/cache@v4
with:
path: |
~/.tiup/bin
~/.tiup/manifests
# Cache TiUP binary separately (small, ~20MB)
key: ${{ runner.os }}-tiup-binary-${{ hashFiles('.github/workflows/main.yml') }}
restore-keys: |
${{ runner.os }}-tiup-binary-
- name: Install TiUP
run: |
if ! command -v tiup &> /dev/null; then
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
fi
echo "$HOME/.tiup/bin" >> $GITHUB_PATH
- name: Update TiUP and playground component
run: |
export PATH=$HOME/.tiup/bin:$PATH
tiup update --self || true
tiup update playground || true
# Note: TiDB components are NOT pre-downloaded here to avoid huge cache timeout
# Each test job will download and cache only the version it needs (~700-800MB per version)
- 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: Cache Docker images (save/load approach)
if: contains(matrix.target, 'testversion') || contains(matrix.target, 'testpercona') || contains(matrix.target, 'testmariadb')
id: cache-docker-images
uses: actions/cache@v4
with:
path: /tmp/docker-images
key: ${{ runner.os }}-docker-${{ matrix.target }}-v1
restore-keys: |
${{ runner.os }}-docker-${{ matrix.target }}-
${{ runner.os }}-docker-
- name: Load Docker image from cache (if available)
if: (contains(matrix.target, 'testversion') || contains(matrix.target, 'testpercona') || contains(matrix.target, 'testmariadb')) && steps.cache-docker-images.outputs.cache-hit == 'true'
run: |
# Load cached image if available
if [[ "${{ matrix.target }}" == testversion5.6 ]] && [ -f /tmp/docker-images/mysql-5.6.tar ]; then
docker load -i /tmp/docker-images/mysql-5.6.tar
elif [[ "${{ matrix.target }}" == testversion5.7 ]] && [ -f /tmp/docker-images/mysql-5.7.tar ]; then
docker load -i /tmp/docker-images/mysql-5.7.tar
elif [[ "${{ matrix.target }}" == testversion8.0 ]] && [ -f /tmp/docker-images/mysql-8.0.tar ]; then
docker load -i /tmp/docker-images/mysql-8.0.tar
elif [[ "${{ matrix.target }}" == testpercona5.7 ]] && [ -f /tmp/docker-images/percona-5.7.tar ]; then
docker load -i /tmp/docker-images/percona-5.7.tar
elif [[ "${{ matrix.target }}" == testpercona8.0 ]] && [ -f /tmp/docker-images/percona-8.0.tar ]; then
docker load -i /tmp/docker-images/percona-8.0.tar
elif [[ "${{ matrix.target }}" == testmariadb10.3 ]] && [ -f /tmp/docker-images/mariadb-10.3.tar ]; then
docker load -i /tmp/docker-images/mariadb-10.3.tar
elif [[ "${{ matrix.target }}" == testmariadb10.8 ]] && [ -f /tmp/docker-images/mariadb-10.8.tar ]; then
docker load -i /tmp/docker-images/mariadb-10.8.tar
elif [[ "${{ matrix.target }}" == testmariadb10.10 ]] && [ -f /tmp/docker-images/mariadb-10.10.tar ]; then
docker load -i /tmp/docker-images/mariadb-10.10.tar
fi
- name: Pre-pull Docker image for this test
if: contains(matrix.target, 'testversion') || contains(matrix.target, 'testpercona') || contains(matrix.target, 'testmariadb')
run: |
# Pre-pull the Docker image needed for this test
# If cache hit, docker pull will be fast (only missing layers)
# If cache miss, full pull happens and we'll save it for next run
mkdir -p /tmp/docker-images
if [[ "${{ matrix.target }}" == testversion5.6 ]]; then
docker pull mysql:5.6
docker save mysql:5.6 -o /tmp/docker-images/mysql-5.6.tar || true
elif [[ "${{ matrix.target }}" == testversion5.7 ]]; then
docker pull mysql:5.7
docker save mysql:5.7 -o /tmp/docker-images/mysql-5.7.tar || true
elif [[ "${{ matrix.target }}" == testversion8.0 ]]; then
docker pull mysql:8.0
docker save mysql:8.0 -o /tmp/docker-images/mysql-8.0.tar || true
elif [[ "${{ matrix.target }}" == testpercona5.7 ]]; then
docker pull percona:5.7
docker save percona:5.7 -o /tmp/docker-images/percona-5.7.tar || true
elif [[ "${{ matrix.target }}" == testpercona8.0 ]]; then
docker pull percona:8.0
docker save percona:8.0 -o /tmp/docker-images/percona-8.0.tar || true
elif [[ "${{ matrix.target }}" == testmariadb10.3 ]]; then
docker pull mariadb:10.3
docker save mariadb:10.3 -o /tmp/docker-images/mariadb-10.3.tar || true
elif [[ "${{ matrix.target }}" == testmariadb10.8 ]]; then
docker pull mariadb:10.8
docker save mariadb:10.8 -o /tmp/docker-images/mariadb-10.8.tar || true
elif [[ "${{ matrix.target }}" == testmariadb10.10 ]]; then
docker pull mariadb:10.10
docker save mariadb:10.10 -o /tmp/docker-images/mariadb-10.10.tar || true
fi
- 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'