# This workflow will install Python dependencies, run tests and lint with a variety of Python versions # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python name: build on: push: branches: [ "main" ] pull_request: branches: [ "main" ] permissions: id-token: write contents: read jobs: prepare: runs-on: ubuntu-latest outputs: package: ${{ steps.pkg.outputs.package }} pypi_url: ${{ steps.pkg.outputs.pypi_url }} steps: - name: Compute package name from the repository's id: pkg run: | name="${GITHUB_REPOSITORY##*/}" echo "package=${name#python-}" >> $GITHUB_OUTPUT echo "pypi_url=https://pypi.org/p/${name#python-}" >> $GITHUB_OUTPUT build: needs: prepare runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: os: [ubuntu-latest] python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] env: package: ${{ needs.prepare.outputs.package }} steps: - uses: actions/checkout@v5 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v6 with: python-version: ${{ matrix.python-version }} - name: Install ${{ env.package }} run: | python -m pip install --upgrade pip python -m pip install pytest pytest-cov coverage pip install -r requirements.txt pip install tinyscript>=1.31 pip install . - name: Test ${{ env.package }} with pytest run: | pytest --cov=$package coverage: needs: [prepare, build] permissions: contents: write runs-on: ubuntu-latest env: cov_badge_path: docs/coverage.svg package: ${{ needs.prepare.outputs.package }} python_version: "3.13" steps: - uses: actions/checkout@v5 with: fetch-depth: 0 ref: ${{ github.head_ref || github.ref_name }} - name: Set up Python ${{ env.python_version }} uses: actions/setup-python@v6 with: python-version: ${{ env.python_version }} - name: Install ${{ env.package }} run: | python -m pip install --upgrade pip python -m pip install pytest pytest-cov pip install -r requirements.txt pip install . - name: Make coverage badge for ${{ env.package }} run: | pip install genbadge[coverage] pytest --cov=$package --cov-report=xml genbadge coverage -i coverage.xml -o $cov_badge_path - name: Verify Changed files uses: tj-actions/verify-changed-files@v20 id: changed_files with: files: ${{ env.cov_badge_path }} - name: Push coverage badge if: steps.changed_files.outputs.files_changed == 'true' run: | git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" git fetch origin git checkout coverage-badge || git checkout -b coverage-badge git add $cov_badge_path git diff --cached --quiet && exit 0 git commit -m "Update coverage badge" git push origin coverage-badge --force deploy: environment: name: pypi url: ${{ needs.prepare.outputs.pypi_url }} runs-on: ubuntu-latest needs: [prepare, coverage] steps: - uses: actions/checkout@v5 with: fetch-depth: 0 - name: Check for version change uses: dorny/paths-filter@v4 id: filter with: filters: | version: - '**/VERSION.txt' - if: steps.filter.outputs.version == 'true' name: Cleanup README run: | sed -ri 's/^(##*)\s*:.*:\s*/\1 /g' README.md awk '{if (match($0,"## Supporters")) exit; print}' README.md > README mv -f README README.md - if: steps.filter.outputs.version == 'true' name: Build ${{ needs.prepare.outputs.package }} package run: python3 -m pip install --upgrade build && python3 -m build - if: steps.filter.outputs.version == 'true' name: Publish to PyPI uses: pypa/gh-action-pypi-publish@release/v1