ci: fix error when ruff finds no issues #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: CI | |
| on: [push] | |
| jobs: | |
| pytest: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v6 | |
| with: | |
| enable-cache: true | |
| - name: Install dependencies | |
| run: uv sync --dev --frozen | |
| - name: Run pytest | |
| run: uv run pytest --ignore=test/availability | |
| - name: Generate badges | |
| if: always() | |
| run: | | |
| PASSED=$(python -c "import xml.etree.ElementTree as ET; r=ET.parse('junit.xml').getroot(); ts=r.findall('testsuite'); print(sum(int(t.get('tests',0))-int(t.get('failures',0))-int(t.get('errors',0)) for t in ts))") | |
| FAILED=$(python -c "import xml.etree.ElementTree as ET; r=ET.parse('junit.xml').getroot(); ts=r.findall('testsuite'); print(sum(int(t.get('failures',0))+int(t.get('errors',0)) for t in ts))") | |
| if [ "$FAILED" -eq 0 ]; then | |
| uv run anybadge --label=pytest --value="${PASSED} passed" --color=green --file=pytest.svg | |
| else | |
| uv run anybadge --label=pytest --value="${PASSED} passed, ${FAILED} failed" --color=red --file=pytest.svg | |
| fi | |
| COVERAGE=$(python -c "import xml.etree.ElementTree as ET; t=ET.parse('coverage.xml').getroot(); print(round(float(t.get('line-rate',0))*100))") | |
| uv run anybadge --value=$COVERAGE --file=coverage.svg coverage | |
| - name: Upload pytest badge | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: pytest | |
| path: pytest.svg | |
| overwrite: true | |
| - name: Upload coverage badge | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage | |
| path: coverage.svg | |
| overwrite: true | |
| ty: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v6 | |
| with: | |
| enable-cache: true | |
| - name: Install dependencies | |
| run: uv sync --dev --frozen | |
| - name: Run ty | |
| run: uv run ty check | |
| ruff: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v6 | |
| with: | |
| enable-cache: true | |
| - name: Install dependencies | |
| run: uv sync --dev --frozen | |
| - name: Lint with ruff | |
| run: uv run ruff check --output-format=concise > ruff.txt | |
| - name: Generate badge | |
| if: always() | |
| run: | | |
| VIOLATIONS=$(tail -1 ruff.txt | grep -oP '\d+' || echo 0) | |
| if [ "$VIOLATIONS" -eq 0 ]; then | |
| uv run anybadge --label=ruff --value=passing --color=green --file=ruff.svg | |
| else | |
| uv run anybadge --label=ruff --value="$VIOLATIONS violations" --color=orange --file=ruff.svg | |
| fi | |
| - name: Upload ruff badge | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ruff | |
| path: ruff.svg | |
| overwrite: true | |
| build: | |
| needs: [pytest, ty, ruff] | |
| if: github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/beta' || startsWith(github.ref, 'refs/tags/v') | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| - name: Resolve build metadata | |
| id: meta | |
| run: | | |
| if [[ "$GITHUB_REF" == refs/tags/* ]]; then | |
| echo "version=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT | |
| echo "additional_tag=latest" >> $GITHUB_OUTPUT | |
| elif [[ "$GITHUB_REF_NAME" == "beta" ]]; then | |
| echo "version=beta" >> $GITHUB_OUTPUT | |
| echo "additional_tag=" >> $GITHUB_OUTPUT | |
| else | |
| echo "version=dev" >> $GITHUB_OUTPUT | |
| echo "additional_tag=" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
| password: ${{ secrets.DOCKER_HUB_TOKEN }} | |
| - name: Build and push | |
| run: | | |
| docker buildx bake all --push \ | |
| --set "*.cache-from=type=gha" \ | |
| --set "*.cache-to=type=gha,mode=max" | |
| env: | |
| BUGHOG_VERSION: ${{ steps.meta.outputs.version }} | |
| ADDITIONAL_TAG: ${{ steps.meta.outputs.additional_tag }} |