| 1 |
name: tests |
| 2 |
|
| 3 |
on: |
| 4 |
push: |
| 5 |
branches-ignore: |
| 6 |
- 'gh-pages' |
| 7 |
pull_request: |
| 8 |
branches-ignore: |
| 9 |
- 'gh-pages' |
| 10 |
|
| 11 |
permissions: |
| 12 |
contents: read |
| 13 |
|
| 14 |
jobs: |
| 15 |
# Label of the container job |
| 16 |
sqlite: |
| 17 |
strategy: |
| 18 |
matrix: |
| 19 |
go: ['1.24', '1.25'] |
| 20 |
platform: [ubuntu-latest] # can not run in windows OS |
| 21 |
runs-on: ${{ matrix.platform }} |
| 22 |
|
| 23 |
steps: |
| 24 |
- name: Set up Go 1.x |
| 25 |
uses: actions/setup-go@v4 |
| 26 |
with: |
| 27 |
go-version: ${{ matrix.go }} |
| 28 |
|
| 29 |
- name: Check out code into the Go module directory |
| 30 |
uses: actions/checkout@v4 |
| 31 |
|
| 32 |
- name: go mod package cache |
| 33 |
uses: actions/cache@v4 |
| 34 |
with: |
| 35 |
path: ~/go/pkg/mod |
| 36 |
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('tests/go.mod') }} |
| 37 |
|
| 38 |
- name: Tests |
| 39 |
run: GITHUB_ACTION=true GORM_DIALECT=sqlite ./tests/tests_all.sh |
| 40 |
|
| 41 |
mysql: |
| 42 |
strategy: |
| 43 |
matrix: |
| 44 |
dbversion: ['mysql:9', 'mysql:8', 'mysql:5.7'] |
| 45 |
go: ['1.24', '1.25'] |
| 46 |
platform: [ubuntu-latest] |
| 47 |
runs-on: ${{ matrix.platform }} |
| 48 |
|
| 49 |
services: |
| 50 |
mysql: |
| 51 |
image: ${{ matrix.dbversion }} |
| 52 |
env: |
| 53 |
MYSQL_DATABASE: gorm |
| 54 |
MYSQL_USER: gorm |
| 55 |
MYSQL_PASSWORD: gorm |
| 56 |
MYSQL_RANDOM_ROOT_PASSWORD: "yes" |
| 57 |
ports: |
| 58 |
- 9910:3306 |
| 59 |
options: >- |
| 60 |
--health-cmd "mysqladmin ping -ugorm -pgorm" |
| 61 |
--health-interval 10s |
| 62 |
--health-start-period 10s |
| 63 |
--health-timeout 5s |
| 64 |
--health-retries 10 |
| 65 |
|
| 66 |
steps: |
| 67 |
- name: Set up Go 1.x |
| 68 |
uses: actions/setup-go@v4 |
| 69 |
with: |
| 70 |
go-version: ${{ matrix.go }} |
| 71 |
|
| 72 |
- name: Check out code into the Go module directory |
| 73 |
uses: actions/checkout@v4 |
| 74 |
|
| 75 |
- name: go mod package cache |
| 76 |
uses: actions/cache@v4 |
| 77 |
with: |
| 78 |
path: ~/go/pkg/mod |
| 79 |
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('tests/go.mod') }} |
| 80 |
|
| 81 |
- name: Tests |
| 82 |
run: GITHUB_ACTION=true GORM_DIALECT=mysql GORM_DSN="gorm:gorm@tcp(localhost:9910)/gorm?charset=utf8&parseTime=True" ./tests/tests_all.sh |
| 83 |
|
| 84 |
mariadb: |
| 85 |
strategy: |
| 86 |
matrix: |
| 87 |
dbversion: [ 'mariadb:latest' ] |
| 88 |
go: ['1.24', '1.25'] |
| 89 |
platform: [ ubuntu-latest ] |
| 90 |
runs-on: ${{ matrix.platform }} |
| 91 |
|
| 92 |
services: |
| 93 |
mysql: |
| 94 |
image: ${{ matrix.dbversion }} |
| 95 |
env: |
| 96 |
MYSQL_DATABASE: gorm |
| 97 |
MYSQL_USER: gorm |
| 98 |
MYSQL_PASSWORD: gorm |
| 99 |
MYSQL_RANDOM_ROOT_PASSWORD: "yes" |
| 100 |
ports: |
| 101 |
- 9910:3306 |
| 102 |
options: >- |
| 103 |
--health-cmd "mariadb-admin ping -ugorm -pgorm" |
| 104 |
--health-interval 10s |
| 105 |
--health-start-period 10s |
| 106 |
--health-timeout 5s |
| 107 |
--health-retries 10 |
| 108 |
|
| 109 |
steps: |
| 110 |
- name: Set up Go 1.x |
| 111 |
uses: actions/setup-go@v4 |
| 112 |
with: |
| 113 |
go-version: ${{ matrix.go }} |
| 114 |
|
| 115 |
- name: Check out code into the Go module directory |
| 116 |
uses: actions/checkout@v4 |
| 117 |
|
| 118 |
- name: go mod package cache |
| 119 |
uses: actions/cache@v4 |
| 120 |
with: |
| 121 |
path: ~/go/pkg/mod |
| 122 |
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('tests/go.mod') }} |
| 123 |
|
| 124 |
- name: Tests |
| 125 |
run: GITHUB_ACTION=true GORM_DIALECT=mysql GORM_DSN="gorm:gorm@tcp(localhost:9910)/gorm?charset=utf8&parseTime=True" ./tests/tests_all.sh |
| 126 |
|
| 127 |
postgres: |
| 128 |
strategy: |
| 129 |
matrix: |
| 130 |
dbversion: ['postgres:latest', 'postgres:15', 'postgres:14', 'postgres:13'] |
| 131 |
go: ['1.24', '1.25'] |
| 132 |
platform: [ubuntu-latest] # can not run in macOS and Windows |
| 133 |
runs-on: ${{ matrix.platform }} |
| 134 |
|
| 135 |
services: |
| 136 |
postgres: |
| 137 |
image: ${{ matrix.dbversion }} |
| 138 |
env: |
| 139 |
POSTGRES_PASSWORD: gorm |
| 140 |
POSTGRES_USER: gorm |
| 141 |
POSTGRES_DB: gorm |
| 142 |
TZ: Asia/Shanghai |
| 143 |
ports: |
| 144 |
- 9920:5432 |
| 145 |
# Set health checks to wait until postgres has started |
| 146 |
options: >- |
| 147 |
--health-cmd pg_isready |
| 148 |
--health-interval 10s |
| 149 |
--health-timeout 5s |
| 150 |
--health-retries 5 |
| 151 |
|
| 152 |
steps: |
| 153 |
- name: Set up Go 1.x |
| 154 |
uses: actions/setup-go@v4 |
| 155 |
with: |
| 156 |
go-version: ${{ matrix.go }} |
| 157 |
|
| 158 |
- name: Check out code into the Go module directory |
| 159 |
uses: actions/checkout@v4 |
| 160 |
|
| 161 |
- name: go mod package cache |
| 162 |
uses: actions/cache@v4 |
| 163 |
with: |
| 164 |
path: ~/go/pkg/mod |
| 165 |
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('tests/go.mod') }} |
| 166 |
|
| 167 |
- name: Tests |
| 168 |
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 |
| 169 |
|
| 170 |
sqlserver: |
| 171 |
strategy: |
| 172 |
matrix: |
| 173 |
go: ['1.24', '1.25'] |
| 174 |
platform: [ubuntu-latest] # can not run test in macOS and windows |
| 175 |
runs-on: ${{ matrix.platform }} |
| 176 |
|
| 177 |
services: |
| 178 |
mssql: |
| 179 |
image: mcr.microsoft.com/mssql/server:2022-latest |
| 180 |
env: |
| 181 |
TZ: Asia/Shanghai |
| 182 |
ACCEPT_EULA: Y |
| 183 |
MSSQL_SA_PASSWORD: LoremIpsum86 |
| 184 |
ports: |
| 185 |
- 9930:1433 |
| 186 |
options: >- |
| 187 |
--health-cmd="/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P ${MSSQL_SA_PASSWORD} -N -C -l 30 -Q \"SELECT 1\" || exit 1" |
| 188 |
--health-start-period 10s |
| 189 |
--health-interval 10s |
| 190 |
--health-timeout 5s |
| 191 |
--health-retries 10 |
| 192 |
|
| 193 |
steps: |
| 194 |
- name: Set up Go 1.x |
| 195 |
uses: actions/setup-go@v4 |
| 196 |
with: |
| 197 |
go-version: ${{ matrix.go }} |
| 198 |
|
| 199 |
- name: Check out code into the Go module directory |
| 200 |
uses: actions/checkout@v4 |
| 201 |
|
| 202 |
- name: go mod package cache |
| 203 |
uses: actions/cache@v4 |
| 204 |
with: |
| 205 |
path: ~/go/pkg/mod |
| 206 |
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('tests/go.mod') }} |
| 207 |
|
| 208 |
- name: Tests |
| 209 |
run: GITHUB_ACTION=true GORM_DIALECT=sqlserver GORM_DSN="sqlserver://sa:LoremIpsum86@localhost:9930?database=master" ./tests/tests_all.sh |
| 210 |
|
| 211 |
tidb: |
| 212 |
strategy: |
| 213 |
matrix: |
| 214 |
dbversion: [ 'v6.5.0' ] |
| 215 |
go: ['1.24', '1.25'] |
| 216 |
platform: [ ubuntu-latest ] |
| 217 |
runs-on: ${{ matrix.platform }} |
| 218 |
|
| 219 |
steps: |
| 220 |
- name: Setup TiDB |
| 221 |
uses: Icemap/tidb-action@main |
| 222 |
with: |
| 223 |
port: 9940 |
| 224 |
version: ${{matrix.dbversion}} |
| 225 |
|
| 226 |
- name: Set up Go 1.x |
| 227 |
uses: actions/setup-go@v4 |
| 228 |
with: |
| 229 |
go-version: ${{ matrix.go }} |
| 230 |
|
| 231 |
- name: Check out code into the Go module directory |
| 232 |
uses: actions/checkout@v4 |
| 233 |
|
| 234 |
|
| 235 |
- name: go mod package cache |
| 236 |
uses: actions/cache@v4 |
| 237 |
with: |
| 238 |
path: ~/go/pkg/mod |
| 239 |
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('tests/go.mod') }} |
| 240 |
|
| 241 |
- name: Tests |
| 242 |
run: GITHUB_ACTION=true GORM_DIALECT=tidb GORM_DSN="root:@tcp(localhost:9940)/test?charset=utf8&parseTime=True&loc=Local" ./tests/tests_all.sh |
| 243 |
|
| 244 |
gaussdb: |
| 245 |
strategy: |
| 246 |
matrix: |
| 247 |
dbversion: ['opengauss/opengauss:7.0.0-RC1.B023'] |
| 248 |
go: ['1.24', '1.25'] |
| 249 |
platform: [ubuntu-latest] # can not run in macOS and Windows |
| 250 |
runs-on: ${{ matrix.platform }} |
| 251 |
|
| 252 |
services: |
| 253 |
gaussdb: |
| 254 |
image: ${{ matrix.dbversion }} |
| 255 |
env: |
| 256 |
# GaussDB has password limitations |
| 257 |
GS_PASSWORD: Gaussdb@123 |
| 258 |
TZ: Asia/Shanghai |
| 259 |
ports: |
| 260 |
- 9950:5432 |
| 261 |
|
| 262 |
steps: |
| 263 |
- name: Set up Go 1.x |
| 264 |
uses: actions/setup-go@v4 |
| 265 |
with: |
| 266 |
go-version: ${{ matrix.go }} |
| 267 |
|
| 268 |
- name: Check out code into the Go module directory |
| 269 |
uses: actions/checkout@v4 |
| 270 |
|
| 271 |
- name: Waiting for GaussDB to be ready |
| 272 |
run: | |
| 273 |
container_name=$(docker ps --filter "ancestor=opengauss/opengauss:7.0.0-RC1.B023" --format "{{.Names}}") |
| 274 |
if [ -z "$container_name" ]; then |
| 275 |
echo "Error: failed to find a container created from the 'opengauss/opengauss:7.0.0-RC1.B023' image." |
| 276 |
exit 1 |
| 277 |
fi |
| 278 |
max_retries=12 |
| 279 |
retry_count=0 |
| 280 |
if [ -t 0 ]; then |
| 281 |
TTY_FLAG="-t" |
| 282 |
else |
| 283 |
TTY_FLAG="" |
| 284 |
fi |
| 285 |
while [ $retry_count -lt $max_retries ]; do |
| 286 |
if docker exec -i "${container_name}" bash -c "su - omm -c 'gsql -U omm -c \"select 1;\"'" |
| 287 |
then |
| 288 |
echo "Creating database gorm..." |
| 289 |
sql_file='/tmp/create_database.sql' |
| 290 |
echo "CREATE DATABASE gorm DBCOMPATIBILITY 'PG';" > ${sql_file} |
| 291 |
docker cp "${sql_file}" "${container_name}":"${sql_file}" |
| 292 |
docker exec -i ${TTY_FLAG} "${container_name}" bash -c "su - omm -c 'gsql -U omm -f ${sql_file}'" |
| 293 |
echo "Database initialization completed." |
| 294 |
break |
| 295 |
fi |
| 296 |
|
| 297 |
echo "Waiting for database to be ready... (attempt $((retry_count + 1))/$max_retries)" |
| 298 |
sleep 10 |
| 299 |
((++retry_count)) |
| 300 |
done |
| 301 |
exit 0 |
| 302 |
|
| 303 |
- name: go mod package cache |
| 304 |
uses: actions/cache@v4 |
| 305 |
with: |
| 306 |
path: ~/go/pkg/mod |
| 307 |
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('tests/go.mod') }} |
| 308 |
|
| 309 |
- name: Tests |
| 310 |
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 |