docs: update and add content from wiki #20
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@v6 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v8.1.0 | |
| with: | |
| enable-cache: true | |
| - name: Install dependencies | |
| # we use --locked instead of --frozen to elicit an error if pyproject.toml and uv.lock are not synced | |
| run: uv sync --dev --locked | |
| - 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@v7 | |
| with: | |
| name: pytest | |
| path: pytest.svg | |
| overwrite: true | |
| - name: Upload coverage badge | |
| if: always() | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: coverage | |
| path: coverage.svg | |
| overwrite: true | |
| ty: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v8.1.0 | |
| with: | |
| enable-cache: true | |
| - name: Install dependencies | |
| run: uv sync --dev --frozen | |
| - name: Run ty | |
| run: uv run ty check | |
| - name: Generate badge | |
| if: always() | |
| run: | | |
| if [ "${{ job.status }}" = "success" ]; then | |
| uv run anybadge --label=ty --value=passing --color=green --file=ty.svg | |
| else | |
| uv run anybadge --label=ty --value=failing --color=red --file=ty.svg | |
| fi | |
| - name: Upload ty badge | |
| if: always() | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: ty | |
| path: ty.svg | |
| overwrite: true | |
| ruff: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v8.1.0 | |
| 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@v7 | |
| with: | |
| name: ruff | |
| path: ruff.svg | |
| overwrite: true | |
| badges: | |
| needs: [pytest, ty, ruff] | |
| if: always() && github.ref == 'refs/heads/main' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| ref: badges | |
| path: badges-branch | |
| - uses: actions/download-artifact@v7 | |
| with: | |
| name: pytest | |
| path: badges-branch | |
| - uses: actions/download-artifact@v7 | |
| with: | |
| name: coverage | |
| path: badges-branch | |
| - uses: actions/download-artifact@v7 | |
| with: | |
| name: ty | |
| path: badges-branch | |
| - uses: actions/download-artifact@v7 | |
| with: | |
| name: ruff | |
| path: badges-branch | |
| - name: Commit and push badges | |
| working-directory: badges-branch | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add pytest.svg coverage.svg ty.svg ruff.svg | |
| git diff --staged --quiet || git commit -m "ci: update badges" | |
| git push | |
| 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@v6 | |
| - 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@v4 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v4 | |
| 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 }} |