diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml new file mode 100644 index 0000000..6ab2f63 --- /dev/null +++ b/.github/workflows/pr-checks.yml @@ -0,0 +1,41 @@ +name: PR Tests & Coverage + +on: + pull_request: + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + cache: "pip" + + - name: Install Dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install -r requirements-test.txt + + - name: Run Tests with Coverage + run: | + pytest tests/ -v --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=minichain | tee pytest-coverage.txt + + - name: Pytest coverage comment + uses: MishaKav/pytest-coverage-comment@v1 + with: + pytest-coverage-path: ./pytest-coverage.txt + junitxml-path: ./pytest.xml diff --git a/.github/workflows/update-badge.yml b/.github/workflows/update-badge.yml new file mode 100644 index 0000000..d032db6 --- /dev/null +++ b/.github/workflows/update-badge.yml @@ -0,0 +1,50 @@ +name: Update Coverage Badge +on: + push: + branches: [main] + +permissions: + contents: write + +jobs: + update-badge: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + fetch-depth: 0 + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + cache: "pip" + + - name: Install Dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install -r requirements-test.txt + + - name: Run tests + run: | + pytest tests/ -v --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=minichain | tee pytest-coverage.txt + + - name: Coverage comment + id: coverage + uses: MishaKav/pytest-coverage-comment@v1 + with: + pytest-coverage-path: ./pytest-coverage.txt + junitxml-path: ./pytest.xml + hide-comment: true + + - name: Update README + run: | + sed -i '//,//c\\n\${{ steps.coverage.outputs.coverageHtml }}\n' ./README.md + + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: 'docs: update coverage badge' + file_pattern: README.md diff --git a/README.md b/README.md index 8e078a9..f39fa19 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,8 @@ [![Static Badge](https://img.shields.io/badge/Stability_Nexus-MiniChain-228B22?style=for-the-badge&labelColor=FFC517)](https://stability.nexus/) - + + diff --git a/requirements-test.txt b/requirements-test.txt new file mode 100644 index 0000000..1900428 --- /dev/null +++ b/requirements-test.txt @@ -0,0 +1,3 @@ +pytest>=7.0.0 +pytest-asyncio>=0.21.0 +pytest-cov>=4.0.0