clear get_user example #56
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: Build | |
| # Trigger the workflow on push or pull requests to the main branch | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| permissions: | |
| contents: write # Required for git push | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| if: github.event_name != 'push' || github.event.head_commit.message != 'Update coverage badge in README' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' # Match your Poetry project's Python version | |
| - name: Install Poetry | |
| run: | | |
| curl -sSL https://install.python-poetry.org | python3 - | |
| echo "$HOME/.local/bin" >> $GITHUB_PATH # Add Poetry to PATH | |
| - name: Install project dependencies | |
| run: | | |
| poetry install --with dev | |
| - name: Spin Redis | |
| run: | | |
| docker compose up -d redis | |
| # Wait for Redis to be ready | |
| echo "Waiting for Redis to be ready..." | |
| until docker compose exec -T redis redis-cli ping | grep -q PONG | |
| do | |
| echo "Redis not ready yet, retrying..." | |
| sleep 1 | |
| done | |
| - name: Run pytest with coverage | |
| run: | | |
| poetry run pytest tests/ --cov=./ --cov-report=xml --cov-report=term-missing -v | |
| env: | |
| COVERAGE_FILE: .coverage | |
| - name: Upload coverage report | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-report | |
| path: coverage.xml | |
| - name: Extract coverage percentage | |
| id: coverage | |
| run: | | |
| poetry run coverage report --format=markdown > coverage.md | |
| TOTAL_COVERAGE=$(poetry run coverage report | grep TOTAL | awk '{print $4}' | sed 's/%//') | |
| echo "TOTAL_COVERAGE=$TOTAL_COVERAGE" >> $GITHUB_ENV | |
| echo "Generated coverage percentage: $TOTAL_COVERAGE%" | |
| - name: Update README with coverage badge | |
| run: | | |
| BADGE_URL="https://img.shields.io/badge/coverage-${{ env.TOTAL_COVERAGE }}%25-brightgreen" | |
| sed -i '/<!-- COVERAGE_BADGE -->/{n;d;}' README.md # Delete the line after the placeholder | |
| sed -i '/<!-- COVERAGE_BADGE -->/a\[](https://github.com/${{ github.repository }})' README.md | |
| if: github.event_name == 'push' | |
| - name: Commit README changes | |
| run: | | |
| git config --global user.name "GitHub Action" | |
| git config --global user.email "[email protected]" | |
| git add README.md | |
| git diff --quiet && git diff --staged --quiet || git commit -m "Update coverage badge in README" | |
| git push | |
| if: github.event_name == 'push' |