Update README #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: Run Tests and Update Coverage Badge | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| - name: Install UV | |
| uses: astral-sh/setup-uv@v7 | |
| with: | |
| enable-cache: true | |
| save-cache: true | |
| - name: Run Pytest with Coverage | |
| run: | | |
| uv sync --locked --dev | |
| uv run pytest --cov=src --cov-report=term --cov-report=xml | |
| - name: Extract branch name | |
| shell: bash | |
| run: | | |
| BRANCH=${GITHUB_HEAD_REF:-$GITHUB_REF_NAME} | |
| echo "BRANCH=$BRANCH" >> $GITHUB_ENV | |
| echo "BADGE_SOURCE=/tmp/$BRANCH-coverage.svg" >> $GITHUB_ENV | |
| echo "BADGE_DEST=badges/$BRANCH/coverage.svg" >> $GITHUB_ENV | |
| - name: Generate badge | |
| run: | | |
| uv run genbadge coverage -i coverage.xml -o $BADGE_SOURCE | |
| - uses: actions/checkout@v1 | |
| with: | |
| ref: badges | |
| path: badges | |
| - name: Commit badge | |
| run: | | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| git checkout -- | |
| mkdir -p "badges/${BRANCH}" | |
| cp "$BADGE_SOURCE" "$BADGE_DEST" | |
| git add "$BADGE_DEST" && git commit -m "Add/Update badge" || true | |
| - name: Push badge commit | |
| uses: ad-m/github-push-action@master | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| branch: badges | |
| directory: badges |