CICD improvements #43
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Tests | |
on: | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build: | |
name: Build Docker image | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: server/services/manager/Dockerfile | |
target: builder | |
outputs: type=docker,dest=/tmp/app-image.tar | |
tags: tacoq-manager:latest | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Upload Docker image | |
uses: actions/upload-artifact@v4 | |
with: | |
name: app-image | |
path: /tmp/app-image.tar | |
server-tests: | |
name: Run server tests | |
needs: build | |
runs-on: ubuntu-latest | |
env: | |
DATABASE_URL: postgres://postgres:postgres@localhost:5432/test_db | |
services: | |
postgres: | |
image: postgres:latest | |
env: | |
POSTGRES_PASSWORD: postgres | |
POSTGRES_USER: postgres | |
POSTGRES_DB: test_db | |
ports: | |
- 5432:5432 | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Download Docker image | |
uses: actions/download-artifact@v4 | |
with: | |
name: app-image | |
path: /tmp | |
- name: Load Docker image | |
run: docker load --input /tmp/app-image.tar | |
- name: Run tests in container | |
run: | | |
docker run --network host \ | |
-e DATABASE_URL=${DATABASE_URL} \ | |
tacoq-manager cargo test --release --all-features | |
client-tests: | |
name: Client Tests | |
needs: [build, server-tests] | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
sdk: [python] # Add other SDKs here like [python, nodejs, java] | |
steps: | |
- uses: actions/checkout@v4 | |
# =================================== | |
# Common setup steps | |
# =================================== | |
- name: Download Docker image | |
uses: actions/download-artifact@v4 | |
with: | |
name: app-image | |
path: /tmp | |
- name: Load Docker image | |
run: docker load --input /tmp/app-image.tar | |
- name: Start test environment | |
run: | | |
cd client_sdks | |
docker compose -f docker-compose.test.yml up -d --wait | |
- name: Migrate database | |
run: | | |
cd client_sdks | |
docker compose -f docker-compose.test.yml exec tacoq /bin/bash -c " | |
cargo install sqlx-cli --no-default-features --features postgres && | |
cargo sqlx database create && | |
cargo sqlx migrate run --source ./server/libs/db-common/migrations | |
" | |
# =================================== | |
# SDK-specific tests | |
# Each matrix step will run the tests | |
# for the corresponding SDK. | |
# =================================== | |
# Python | |
- name: Run Python tests | |
if: matrix.sdk == 'python' | |
uses: ./.github/actions/sdk-tests | |
with: | |
sdk: python | |
# ================================ | |
# Cleanup | |
# ================================ | |
- name: Cleanup test environment | |
if: always() | |
run: | | |
cd client_sdks | |
docker compose -f docker-compose.test.yml down |