Update ci.yml #8
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: CI/CD with Keploy API Testing | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Run unit tests | |
| env: | |
| CI: true | |
| run: | | |
| python -m pytest test_unit.py -v | |
| - name: Run coverage | |
| env: | |
| CI: true | |
| run: | | |
| coverage run --source=main,db,models -m unittest test_unit.py | |
| coverage report -m | |
| coverage xml | |
| - name: Start FastAPI server | |
| env: | |
| CI: true | |
| run: | | |
| uvicorn main:app --host 0.0.0.0 --port 8000 & | |
| sleep 10 | |
| - name: Test server is running | |
| run: | | |
| curl -f http://localhost:8000/docs || exit 1 | |
| - name: Generate OpenAPI Schema | |
| run: | | |
| python generate_openapi.py | |
| - name: Upload OpenAPI Schema | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: openapi-schema | |
| path: openapi.json | |
| keploy-api-testing: | |
| needs: test | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Start FastAPI server | |
| env: | |
| CI: true | |
| run: | | |
| uvicorn main:app --host 0.0.0.0 --port 8000 & | |
| sleep 10 | |
| - name: Download OpenAPI Schema | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: openapi-schema | |
| - name: Install Keploy CLI | |
| run: | | |
| curl --silent -L https://keploy.io/ent/install.sh | bash | |
| - name: Run Keploy Test Suite | |
| env: | |
| CI: true | |
| KEPLOY_API_KEY: ${{ secrets.KEPLOY_API_KEY }} | |
| run: | | |
| - name: Upload Keploy Test Reports | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: keploy-reports | |
| path: | | |
| keploy/ | |
| test-reports/ |