Testing: overriding env with test env #835
Workflow file for this run
This file contains hidden or 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: AI Platform CI | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| jobs: | |
| checks: | |
| runs-on: ubuntu-latest | |
| services: | |
| postgres_main: | |
| image: postgres:16 | |
| env: | |
| POSTGRES_USER: postgres | |
| POSTGRES_PASSWORD: postgres | |
| POSTGRES_DB: ai_platform | |
| ports: | |
| - 5432:5432 | |
| options: --health-cmd "pg_isready -U postgres" --health-interval 10s --health-timeout 5s --health-retries 5 | |
| postgres_test: | |
| image: postgres:16 | |
| env: | |
| POSTGRES_USER: postgres | |
| POSTGRES_PASSWORD: postgres | |
| POSTGRES_DB: ai_platform_test | |
| ports: | |
| - 5433:5432 | |
| options: --health-cmd "pg_isready -U postgres" --health-interval 10s --health-timeout 5s --health-retries 5 | |
| strategy: | |
| matrix: | |
| python-version: ["3.11.7"] | |
| redis-version: [6] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Making test-env file | |
| run: cp .env.example .env | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v6 | |
| with: | |
| version: "0.4.15" | |
| enable-cache: true | |
| - name: Install dependencies | |
| run: uv sync | |
| working-directory: backend | |
| - name: Activate virtual environment and run Alembic migrations | |
| run: | | |
| source .venv/bin/activate | |
| alembic upgrade head | |
| working-directory: backend | |
| - name: Run pre-commit | |
| run: | | |
| source .venv/bin/activate | |
| uv run pre-commit run --all-files | |
| working-directory: backend | |
| - name: Load environment variables for testing | |
| run: cp .env.test.example .env.test # Copy the test env file | |
| working-directory: backend | |
| - name: Set environment for test DB | |
| run: | | |
| echo "SQLALCHEMY_DATABASE_URI=postgresql://postgres:postgres@localhost:5433/ai_platform_test" >> .env.test | |
| working-directory: backend | |
| - name: Activate virtual environment and run Alembic migrations for test DB | |
| run: | | |
| source .venv/bin/activate | |
| alembic upgrade head | |
| working-directory: backend | |
| - name: Run tests | |
| run: uv run bash scripts/tests-start.sh "Coverage for ${{ github.sha }}" | |
| working-directory: backend | |
| - name: Upload coverage reports to codecov | |
| uses: codecov/codecov-action@v5.4.3 | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| fail_ci_if_error: true | |
| - name: Check coverage percentage | |
| run: | | |
| source .venv/bin/activate | |
| coverage report --fail-under=70 | |
| working-directory: backend |