name: Go Build & Test
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
name: Build & Test
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22'
check-latest: true
- name: Check out code
uses: actions/checkout@v3
- name: Update go.mod
run: |
go mod edit -go=1.22
go mod tidy
- name: Get dependencies
run: go mod download
- name: Build
run: go build -v ./...
- name: Test (Unit Tests)
run: go test -v -short ./...
integration-test:
name: Integration Tests
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: db1
MYSQL_USER: user1
MYSQL_PASSWORD: password1
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping -h localhost -u root -ppassword"
--health-interval=10s
--health-timeout=5s
--health-retries=5
postgres:
image: postgres:15
env:
POSTGRES_USER: user1
POSTGRES_PASSWORD: password1
POSTGRES_DB: db1
ports:
- 5432:5432
options: >-
--health-cmd="pg_isready -U user1 -d db1"
--health-interval=10s
--health-timeout=5s
--health-retries=5
oracle:
image: gvenzl/oracle-xe:21-slim
env:
ORACLE_PASSWORD: oracle
ORACLE_DATABASE: TESTDB
APP_USER: testuser
APP_USER_PASSWORD: testpass
ports:
- 1521:1521
options: >-
--health-cmd="healthcheck.sh"
--health-interval=20s
--health-timeout=10s
--health-retries=10
--health-start-period=60s
steps:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22'
check-latest: true
- name: Check out code
uses: actions/checkout@v3
- name: Update go.mod
run: |
go mod edit -go=1.22
go mod tidy
- name: Get dependencies
run: go mod download
- name: Wait for Oracle to be ready
run: |
echo "Waiting for Oracle to initialize..."
ORACLE_CONTAINER=$(docker ps -q --filter ancestor=gvenzl/oracle-xe:21-slim)
if [ -z "$ORACLE_CONTAINER" ]; then
echo "Error: Oracle container not found"
exit 1
fi
for i in {1..60}; do
if docker exec $ORACLE_CONTAINER healthcheck.sh 2>/dev/null; then
echo "Oracle is ready!"
break
fi
echo "Waiting for Oracle... ($i/60)"
sleep 2
done
- name: Initialize Oracle test schema
run: |
echo "Initializing Oracle test schema..."
ORACLE_CONTAINER=$(docker ps -q --filter ancestor=gvenzl/oracle-xe:21-slim)
if [ -z "$ORACLE_CONTAINER" ]; then
echo "Error: Oracle container not found"
exit 1
fi
docker exec $ORACLE_CONTAINER sqlplus -s testuser/testpass@TESTDB <<EOF
CREATE TABLE test_users (
id NUMBER(10) PRIMARY KEY,
username VARCHAR2(50) NOT NULL,
email VARCHAR2(100) UNIQUE,
created_date DATE DEFAULT SYSDATE
);
INSERT INTO test_users (id, username, email) VALUES (1, 'alice', 'alice@example.com');
INSERT INTO test_users (id, username, email) VALUES (2, 'bob', 'bob@example.com');
INSERT INTO test_users (id, username, email) VALUES (3, 'charlie', 'charlie@example.com');
COMMIT;
CREATE SEQUENCE test_users_seq START WITH 4 INCREMENT BY 1;
EXIT;
EOF
- name: Run Integration Tests
env:
MYSQL_TEST_HOST: localhost
POSTGRES_TEST_HOST: localhost
ORACLE_TEST_HOST: localhost
NLS_LANG: AMERICAN_AMERICA.UTF8
run: |
echo "Running database integration tests..."
go test -v -race -coverprofile=coverage.txt -covermode=atomic ./pkg/db -run TestOracle
go test -v -race ./pkg/dbtools -run TestOracleIntegration
go test -v -race ./pkg/db -run TestRegressionAllDatabases
- name: Run Connection Pooling Tests
env:
MYSQL_TEST_HOST: localhost
POSTGRES_TEST_HOST: localhost
ORACLE_TEST_HOST: localhost
NLS_LANG: AMERICAN_AMERICA.UTF8
run: |
echo "Running connection pooling tests..."
go test -v ./pkg/db -run TestConnectionPooling
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: ./coverage.txt
flags: integration
name: integration-tests
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22'
check-latest: true
- name: Check out code
uses: actions/checkout@v3
- name: Update go.mod
run: |
go mod edit -go=1.22
go mod tidy
- name: Install golangci-lint
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.0.0
- name: Run golangci-lint
run: golangci-lint run --timeout=5m