
* support gaussdb * use github CI * change function name * use gorm.io/driver/gaussdb --------- Co-authored-by: bing.ma <bing.ma@daocloud.io>
310 lines
8.9 KiB
YAML
310 lines
8.9 KiB
YAML
name: tests
|
|
|
|
on:
|
|
push:
|
|
branches-ignore:
|
|
- 'gh-pages'
|
|
pull_request:
|
|
branches-ignore:
|
|
- 'gh-pages'
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
# Label of the container job
|
|
sqlite:
|
|
strategy:
|
|
matrix:
|
|
go: ['1.23', '1.24']
|
|
platform: [ubuntu-latest] # can not run in windows OS
|
|
runs-on: ${{ matrix.platform }}
|
|
|
|
steps:
|
|
- name: Set up Go 1.x
|
|
uses: actions/setup-go@v4
|
|
with:
|
|
go-version: ${{ matrix.go }}
|
|
|
|
- name: Check out code into the Go module directory
|
|
uses: actions/checkout@v4
|
|
|
|
- name: go mod package cache
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ~/go/pkg/mod
|
|
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('tests/go.mod') }}
|
|
|
|
- name: Tests
|
|
run: GITHUB_ACTION=true GORM_DIALECT=sqlite ./tests/tests_all.sh
|
|
|
|
mysql:
|
|
strategy:
|
|
matrix:
|
|
dbversion: ['mysql:9', 'mysql:8', 'mysql:5.7']
|
|
go: ['1.23', '1.24']
|
|
platform: [ubuntu-latest]
|
|
runs-on: ${{ matrix.platform }}
|
|
|
|
services:
|
|
mysql:
|
|
image: ${{ matrix.dbversion }}
|
|
env:
|
|
MYSQL_DATABASE: gorm
|
|
MYSQL_USER: gorm
|
|
MYSQL_PASSWORD: gorm
|
|
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
|
|
ports:
|
|
- 9910:3306
|
|
options: >-
|
|
--health-cmd "mysqladmin ping -ugorm -pgorm"
|
|
--health-interval 10s
|
|
--health-start-period 10s
|
|
--health-timeout 5s
|
|
--health-retries 10
|
|
|
|
steps:
|
|
- name: Set up Go 1.x
|
|
uses: actions/setup-go@v4
|
|
with:
|
|
go-version: ${{ matrix.go }}
|
|
|
|
- name: Check out code into the Go module directory
|
|
uses: actions/checkout@v4
|
|
|
|
- name: go mod package cache
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ~/go/pkg/mod
|
|
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('tests/go.mod') }}
|
|
|
|
- name: Tests
|
|
run: GITHUB_ACTION=true GORM_DIALECT=mysql GORM_DSN="gorm:gorm@tcp(localhost:9910)/gorm?charset=utf8&parseTime=True" ./tests/tests_all.sh
|
|
|
|
mariadb:
|
|
strategy:
|
|
matrix:
|
|
dbversion: [ 'mariadb:latest' ]
|
|
go: ['1.23', '1.24']
|
|
platform: [ ubuntu-latest ]
|
|
runs-on: ${{ matrix.platform }}
|
|
|
|
services:
|
|
mysql:
|
|
image: ${{ matrix.dbversion }}
|
|
env:
|
|
MYSQL_DATABASE: gorm
|
|
MYSQL_USER: gorm
|
|
MYSQL_PASSWORD: gorm
|
|
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
|
|
ports:
|
|
- 9910:3306
|
|
options: >-
|
|
--health-cmd "mariadb-admin ping -ugorm -pgorm"
|
|
--health-interval 10s
|
|
--health-start-period 10s
|
|
--health-timeout 5s
|
|
--health-retries 10
|
|
|
|
steps:
|
|
- name: Set up Go 1.x
|
|
uses: actions/setup-go@v4
|
|
with:
|
|
go-version: ${{ matrix.go }}
|
|
|
|
- name: Check out code into the Go module directory
|
|
uses: actions/checkout@v4
|
|
|
|
- name: go mod package cache
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ~/go/pkg/mod
|
|
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('tests/go.mod') }}
|
|
|
|
- name: Tests
|
|
run: GITHUB_ACTION=true GORM_DIALECT=mysql GORM_DSN="gorm:gorm@tcp(localhost:9910)/gorm?charset=utf8&parseTime=True" ./tests/tests_all.sh
|
|
|
|
postgres:
|
|
strategy:
|
|
matrix:
|
|
dbversion: ['postgres:latest', 'postgres:15', 'postgres:14', 'postgres:13']
|
|
go: ['1.23', '1.24']
|
|
platform: [ubuntu-latest] # can not run in macOS and Windows
|
|
runs-on: ${{ matrix.platform }}
|
|
|
|
services:
|
|
postgres:
|
|
image: ${{ matrix.dbversion }}
|
|
env:
|
|
POSTGRES_PASSWORD: gorm
|
|
POSTGRES_USER: gorm
|
|
POSTGRES_DB: gorm
|
|
TZ: Asia/Shanghai
|
|
ports:
|
|
- 9920:5432
|
|
# Set health checks to wait until postgres has started
|
|
options: >-
|
|
--health-cmd pg_isready
|
|
--health-interval 10s
|
|
--health-timeout 5s
|
|
--health-retries 5
|
|
|
|
steps:
|
|
- name: Set up Go 1.x
|
|
uses: actions/setup-go@v4
|
|
with:
|
|
go-version: ${{ matrix.go }}
|
|
|
|
- name: Check out code into the Go module directory
|
|
uses: actions/checkout@v4
|
|
|
|
- name: go mod package cache
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ~/go/pkg/mod
|
|
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('tests/go.mod') }}
|
|
|
|
- name: Tests
|
|
run: GITHUB_ACTION=true GORM_DIALECT=postgres GORM_DSN="user=gorm password=gorm dbname=gorm host=localhost port=9920 sslmode=disable TimeZone=Asia/Shanghai" ./tests/tests_all.sh
|
|
|
|
sqlserver:
|
|
strategy:
|
|
matrix:
|
|
go: ['1.23', '1.24']
|
|
platform: [ubuntu-latest] # can not run test in macOS and windows
|
|
runs-on: ${{ matrix.platform }}
|
|
|
|
services:
|
|
mssql:
|
|
image: mcr.microsoft.com/mssql/server:2022-latest
|
|
env:
|
|
TZ: Asia/Shanghai
|
|
ACCEPT_EULA: Y
|
|
MSSQL_SA_PASSWORD: LoremIpsum86
|
|
ports:
|
|
- 9930:1433
|
|
options: >-
|
|
--health-cmd="/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P ${MSSQL_SA_PASSWORD} -N -C -l 30 -Q \"SELECT 1\" || exit 1"
|
|
--health-start-period 10s
|
|
--health-interval 10s
|
|
--health-timeout 5s
|
|
--health-retries 10
|
|
|
|
steps:
|
|
- name: Set up Go 1.x
|
|
uses: actions/setup-go@v4
|
|
with:
|
|
go-version: ${{ matrix.go }}
|
|
|
|
- name: Check out code into the Go module directory
|
|
uses: actions/checkout@v4
|
|
|
|
- name: go mod package cache
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ~/go/pkg/mod
|
|
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('tests/go.mod') }}
|
|
|
|
- name: Tests
|
|
run: GITHUB_ACTION=true GORM_DIALECT=sqlserver GORM_DSN="sqlserver://sa:LoremIpsum86@localhost:9930?database=master" ./tests/tests_all.sh
|
|
|
|
tidb:
|
|
strategy:
|
|
matrix:
|
|
dbversion: [ 'v6.5.0' ]
|
|
go: ['1.23', '1.24']
|
|
platform: [ ubuntu-latest ]
|
|
runs-on: ${{ matrix.platform }}
|
|
|
|
steps:
|
|
- name: Setup TiDB
|
|
uses: Icemap/tidb-action@main
|
|
with:
|
|
port: 9940
|
|
version: ${{matrix.dbversion}}
|
|
|
|
- name: Set up Go 1.x
|
|
uses: actions/setup-go@v4
|
|
with:
|
|
go-version: ${{ matrix.go }}
|
|
|
|
- name: Check out code into the Go module directory
|
|
uses: actions/checkout@v4
|
|
|
|
|
|
- name: go mod package cache
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ~/go/pkg/mod
|
|
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('tests/go.mod') }}
|
|
|
|
- name: Tests
|
|
run: GITHUB_ACTION=true GORM_DIALECT=tidb GORM_DSN="root:@tcp(localhost:9940)/test?charset=utf8&parseTime=True&loc=Local" ./tests/tests_all.sh
|
|
|
|
gaussdb:
|
|
strategy:
|
|
matrix:
|
|
dbversion: ['opengauss/opengauss:7.0.0-RC1.B023']
|
|
go: ['1.23', '1.24']
|
|
platform: [ubuntu-latest] # can not run in macOS and Windows
|
|
runs-on: ${{ matrix.platform }}
|
|
|
|
services:
|
|
gaussdb:
|
|
image: ${{ matrix.dbversion }}
|
|
env:
|
|
# GaussDB has password limitations
|
|
GS_PASSWORD: Gaussdb@123
|
|
TZ: Asia/Shanghai
|
|
ports:
|
|
- 9950:5432
|
|
|
|
steps:
|
|
- name: Set up Go 1.x
|
|
uses: actions/setup-go@v4
|
|
with:
|
|
go-version: ${{ matrix.go }}
|
|
|
|
- name: Check out code into the Go module directory
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Waiting for GaussDB to be ready
|
|
run: |
|
|
container_name=$(docker ps --filter "ancestor=opengauss/opengauss:7.0.0-RC1.B023" --format "{{.Names}}")
|
|
if [ -z "$container_name" ]; then
|
|
echo "Error: failed to find a container created from the 'opengauss/opengauss:7.0.0-RC1.B023' image."
|
|
exit 1
|
|
fi
|
|
max_retries=12
|
|
retry_count=0
|
|
if [ -t 0 ]; then
|
|
TTY_FLAG="-t"
|
|
else
|
|
TTY_FLAG=""
|
|
fi
|
|
while [ $retry_count -lt $max_retries ]; do
|
|
if docker exec -i "${container_name}" bash -c "su - omm -c 'gsql -U omm -c \"select 1;\"'"
|
|
then
|
|
echo "Creating database gorm..."
|
|
sql_file='/tmp/create_database.sql'
|
|
echo "CREATE DATABASE gorm DBCOMPATIBILITY 'PG';" > ${sql_file}
|
|
docker cp "${sql_file}" "${container_name}":"${sql_file}"
|
|
docker exec -i ${TTY_FLAG} "${container_name}" bash -c "su - omm -c 'gsql -U omm -f ${sql_file}'"
|
|
echo "Database initialization completed."
|
|
break
|
|
fi
|
|
|
|
echo "Waiting for database to be ready... (attempt $((retry_count + 1))/$max_retries)"
|
|
sleep 10
|
|
((++retry_count))
|
|
done
|
|
exit 0
|
|
|
|
- name: go mod package cache
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ~/go/pkg/mod
|
|
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('tests/go.mod') }}
|
|
|
|
- name: Tests
|
|
run: GITHUB_ACTION=true GORM_DIALECT=gaussdb GORM_DSN="user=gaussdb password=Gaussdb@123 dbname=gorm host=localhost port=9950 sslmode=disable TimeZone=Asia/Shanghai" ./tests/tests_all.sh |