|
| 1 | +name: Test Suite |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, develop ] |
| 6 | + pull_request: |
| 7 | + branches: [ main ] |
| 8 | + |
| 9 | +jobs: |
| 10 | + test: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + strategy: |
| 13 | + matrix: |
| 14 | + python-version: ['3.11', '3.12'] |
| 15 | + environment: [dev, stage] |
| 16 | + |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v3 |
| 19 | + |
| 20 | + - name: Set up Python ${{ matrix.python-version }} |
| 21 | + uses: actions/setup-python@v4 |
| 22 | + with: |
| 23 | + python-version: ${{ matrix.python-version }} |
| 24 | + |
| 25 | + - name: Install dependencies |
| 26 | + run: | |
| 27 | + python -m pip install --upgrade pip |
| 28 | + pip install -r requirements.txt |
| 29 | +
|
| 30 | + - name: Run tests with pytest |
| 31 | + env: |
| 32 | + API_ENV: ${{ matrix.environment }} |
| 33 | + JWT_SECRET: test_secret_for_ci |
| 34 | + run: | |
| 35 | + pytest -v \ |
| 36 | + --cov=app \ |
| 37 | + --cov-report=term-missing \ |
| 38 | + --cov-report=xml \ |
| 39 | + --junitxml=junit.xml \ |
| 40 | + -n auto |
| 41 | +
|
| 42 | + - name: Upload coverage reports |
| 43 | + uses: codecov/codecov-action@v3 |
| 44 | + with: |
| 45 | + file: ./coverage.xml |
| 46 | + flags: unittests |
| 47 | + name: codecov-${{ matrix.python-version }}-${{ matrix.environment }} |
| 48 | + |
| 49 | + - name: Upload test results |
| 50 | + if: always() |
| 51 | + uses: actions/upload-artifact@v3 |
| 52 | + with: |
| 53 | + name: test-results-${{ matrix.python-version }}-${{ matrix.environment }} |
| 54 | + path: junit.xml |
| 55 | + |
| 56 | + rust-tests: |
| 57 | + runs-on: ubuntu-latest |
| 58 | + needs: test |
| 59 | + steps: |
| 60 | + - uses: actions/checkout@v3 |
| 61 | + |
| 62 | + - name: Setup Rust |
| 63 | + uses: actions-rs/toolchain@v1 |
| 64 | + with: |
| 65 | + toolchain: stable |
| 66 | + override: true |
| 67 | + |
| 68 | + - name: Cache cargo registry |
| 69 | + uses: actions/cache@v3 |
| 70 | + with: |
| 71 | + path: ~/.cargo/registry |
| 72 | + key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} |
| 73 | + |
| 74 | + - name: Cache cargo build |
| 75 | + uses: actions/cache@v3 |
| 76 | + with: |
| 77 | + path: rust_tests/target |
| 78 | + key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }} |
| 79 | + |
| 80 | + - name: Setup Python and start API |
| 81 | + uses: actions/setup-python@v4 |
| 82 | + with: |
| 83 | + python-version: '3.11' |
| 84 | + |
| 85 | + - name: Install Python dependencies and start API |
| 86 | + run: | |
| 87 | + python -m pip install --upgrade pip |
| 88 | + pip install -r requirements.txt |
| 89 | + export API_ENV=dev |
| 90 | + export JWT_SECRET=test_secret_for_rust_tests |
| 91 | + uvicorn app.main:app --host 0.0.0.0 --port 8000 & |
| 92 | + sleep 5 # Wait for API to start |
| 93 | +
|
| 94 | + - name: Run Rust integration tests |
| 95 | + working-directory: rust_tests |
| 96 | + run: cargo test --verbose |
| 97 | + |
| 98 | + - name: Upload Rust test results |
| 99 | + if: always() |
| 100 | + uses: actions/upload-artifact@v3 |
| 101 | + with: |
| 102 | + name: rust-test-results |
| 103 | + path: rust_tests/target/debug/deps/*.xml |
0 commit comments