fix: test with ruff #4
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: Tests with pytest in dev | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - "**/*.py" | |
| pull_request: | |
| branches: | |
| - main | |
| paths: | |
| - "**/*.py" | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| environment: dev | |
| services: | |
| mongodb: | |
| image: mongo:8.2.5-noble | |
| env: | |
| MONGO_INITDB_ROOT_USERNAME: ${{ secrets.MONGO_INITDB_ROOT_USERNAME }} | |
| MONGO_INITDB_ROOT_PASSWORD: ${{ secrets.MONGO_INITDB_ROOT_PASSWORD }} | |
| MONGO_INITDB_DATABASE: ${{ secrets.MONGO_INITDB_DATABASE }} | |
| ports: | |
| - 27017:27017 | |
| options: >- | |
| --health-cmd "mongosh --eval 'db.runCommand({ ping: 1 })'" | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 1 | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version-file: "pyproject.toml" | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v7 | |
| - name: Install the project | |
| run: uv sync --frozen --group dev | |
| - name: Run pytest with coverage | |
| env: | |
| ME_CONFIG_MONGODB_URL: mongodb://${{ secrets.MONGO_INITDB_ROOT_USERNAME }}:${{ secrets.MONGO_INITDB_ROOT_PASSWORD }}@localhost:27017/${{ secrets.MONGO_INITDB_DATABASE }}?authSource=admin | |
| MONGO_INITDB_DATABASE: ${{ secrets.MONGO_INITDB_DATABASE }} | |
| SECRET_KEY: ${{ secrets.SECRET_KEY }} | |
| JWT_ALGORITHM: ${{ secrets.JWT_ALGORITHM }} | |
| run: uv run pytest | |
| - name: Extract coverage percentage | |
| run: | | |
| COVERAGE=$(uv run coverage report | grep TOTAL | awk '{print $4}' | sed 's/%//') | |
| echo "COVERAGE=$COVERAGE" >> $GITHUB_ENV | |
| echo "Coverage: $COVERAGE%" | |
| - name: Create coverage json for badge | |
| run: | | |
| cat > coverage.json << EOF | |
| { | |
| "schemaVersion": 1, | |
| "label": "coverage", | |
| "message": "${{ env.COVERAGE }}%", | |
| "color": "$(if [ ${{ env.COVERAGE }} -ge 90 ]; then echo 'brightgreen'; elif [ ${{ env.COVERAGE }} -ge 80 ]; then echo 'green'; elif [ ${{ env.COVERAGE }} -ge 70 ]; then echo 'yellow'; else echo 'red'; fi)" | |
| } | |
| EOF | |
| cat coverage.json | |
| - name: Upload coverage to gist | |
| uses: exuanbo/actions-deploy-gist@v1 | |
| with: | |
| token: ${{ secrets.GIST_TOKEN }} | |
| gist_id: ${{ secrets.GIST_ID }} | |
| file_path: coverage.json | |
| file_type: text |