@@ -80,9 +80,101 @@ jobs:
8080 cd frontend
8181 npm run lint
8282
83+ test-backend :
84+ runs-on : ubuntu-latest
85+ needs : [lint-backend]
86+ steps :
87+ - name : Check out code
88+ uses : actions/checkout@v4
89+
90+ - name : Set up Go
91+ uses : actions/setup-go@v5
92+ with :
93+ go-version : " 1.23.3"
94+
95+ - name : Cache Go modules
96+ uses : actions/cache@v4
97+ with :
98+ path : |
99+ ~/go/pkg/mod
100+ ~/.cache/go-build
101+ key : ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
102+ restore-keys : |
103+ ${{ runner.os }}-go-
104+
105+ - name : Create .env file for testing
106+ run : |
107+ cd backend
108+ cat > .env << EOF
109+ # docker-compose.yml
110+ DEV_DB_NAME=postgresus
111+ DEV_DB_USERNAME=postgres
112+ DEV_DB_PASSWORD=Q1234567
113+ #app
114+ ENV_MODE=development
115+ # db
116+ DATABASE_DSN=host=localhost user=postgres password=Q1234567 dbname=postgresus port=5437 sslmode=disable
117+ DATABASE_URL=postgres://postgres:Q1234567@localhost:5437/postgresus?sslmode=disable
118+ # migrations
119+ GOOSE_DRIVER=postgres
120+ GOOSE_DBSTRING=postgres://postgres:Q1234567@localhost:5437/postgresus?sslmode=disable
121+ GOOSE_MIGRATION_DIR=./migrations
122+ # testing
123+ # to get Google Drive env variables: add storage in UI and copy data from added storage here
124+ TEST_GOOGLE_DRIVE_CLIENT_ID=${{ secrets.TEST_GOOGLE_DRIVE_CLIENT_ID }}
125+ TEST_GOOGLE_DRIVE_CLIENT_SECRET=${{ secrets.TEST_GOOGLE_DRIVE_CLIENT_SECRET }}
126+ TEST_GOOGLE_DRIVE_TOKEN_JSON=${{ secrets.TEST_GOOGLE_DRIVE_TOKEN_JSON }}
127+ # testing DBs
128+ TEST_POSTGRES_13_PORT=5001
129+ TEST_POSTGRES_14_PORT=5002
130+ TEST_POSTGRES_15_PORT=5003
131+ TEST_POSTGRES_16_PORT=5004
132+ TEST_POSTGRES_17_PORT=5005
133+ # testing S3
134+ TEST_MINIO_PORT=9000
135+ TEST_MINIO_CONSOLE_PORT=9001
136+ EOF
137+
138+ - name : Start test containers
139+ run : |
140+ cd backend
141+ docker-compose -f docker-compose.yml.example up -d
142+
143+ - name : Wait for containers to be ready
144+ run : |
145+ # Wait for main dev database
146+ timeout 60 bash -c 'until docker exec dev-db pg_isready -h localhost -p 5437 -U postgres; do sleep 2; done'
147+
148+ # Wait for test databases
149+ timeout 60 bash -c 'until nc -z localhost 5001; do sleep 2; done'
150+ timeout 60 bash -c 'until nc -z localhost 5002; do sleep 2; done'
151+ timeout 60 bash -c 'until nc -z localhost 5003; do sleep 2; done'
152+ timeout 60 bash -c 'until nc -z localhost 5004; do sleep 2; done'
153+ timeout 60 bash -c 'until nc -z localhost 5005; do sleep 2; done'
154+
155+ # Wait for MinIO
156+ timeout 60 bash -c 'until nc -z localhost 9000; do sleep 2; done'
157+
158+ - name : Run database migrations
159+ run : |
160+ cd backend
161+ go install github.com/pressly/goose/v3/cmd/goose@latest
162+ goose -dir migrations postgres "postgres://postgres:Q1234567@localhost:5437/postgresus?sslmode=disable" up
163+
164+ - name : Run Go tests
165+ run : |
166+ cd backend
167+ go test ./internal/...
168+
169+ - name : Stop test containers
170+ if : always()
171+ run : |
172+ cd backend
173+ docker-compose -f docker-compose.yml.example down -v
174+
83175 determine-version :
84176 runs-on : ubuntu-latest
85- needs : [lint -backend, lint-frontend]
177+ needs : [test -backend, lint-frontend]
86178 if : ${{ !contains(github.event.head_commit.message, '[skip-release]') }}
87179 outputs :
88180 should_release : ${{ steps.version_bump.outputs.should_release }}
@@ -175,7 +267,7 @@ jobs:
175267
176268 build-only :
177269 runs-on : ubuntu-latest
178- needs : [lint -backend, lint-frontend]
270+ needs : [test -backend, lint-frontend]
179271 if : ${{ contains(github.event.head_commit.message, '[skip-release]') }}
180272 steps :
181273 - name : Check out code
0 commit comments