Develop port #196
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: build | |
| on: | |
| push: | |
| branches: [ master ] | |
| pull_request: | |
| branches: [ master ] | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| issues: write | |
| pull-requests: write | |
| contents: write | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| python-version: [ "3.10", "3.11", "3.12" ] | |
| steps: | |
| - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 | |
| with: | |
| fetch-depth: 0 # Fetch all history for all branches and tags | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Cache pip packages | |
| uses: actions/cache@6f8efc29b200d32929f49075959781ed54ec270c | |
| with: | |
| path: ~/.cache/pip | |
| key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pip- | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -e .[test,dev] | |
| - name: Run linting | |
| run: | | |
| echo "Running black..." | |
| black --check bsv/ tests/ | |
| echo "Running ruff..." | |
| ruff check bsv/ tests/ | |
| - name: Run tests with coverage | |
| run: | | |
| pytest tests/ -v --cov=bsv --cov-report=term-missing --cov-report=html --cov-report=json | |
| - name: Extract coverage percentage | |
| id: coverage | |
| run: | | |
| # Extract coverage percentage from coverage.json and format to one decimal place | |
| COVERAGE=$(python -c "import json; data=json.load(open('coverage.json')); print(f\"{data['totals']['percent_covered']:.1f}\")") | |
| echo "coverage=$COVERAGE" >> $GITHUB_OUTPUT | |
| echo "Coverage: $COVERAGE%" | |
| - name: Update coverage badge | |
| if: matrix.python-version == '3.11' | |
| run: | | |
| python update_coverage.py ${{ steps.coverage.outputs.coverage }} | |
| - name: Commit and push updated coverage badge (push to master only) | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/master' && matrix.python-version == '3.11' | |
| run: | | |
| # Only proceed if README.md has changes | |
| if git diff --quiet README.md; then | |
| echo "No coverage badge changes to commit." | |
| exit 0 | |
| fi | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add README.md | |
| git commit -m "chore: update coverage badge to ${{ steps.coverage.outputs.coverage }}% [skip ci]" || echo "No changes to commit." | |
| git push | |
| - name: Upload coverage reports | |
| if: matrix.python-version == '3.11' | |
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 | |
| with: | |
| name: coverage-report | |
| path: htmlcov/ | |
| - name: Comment PR with coverage | |
| if: github.event_name == 'pull_request' && matrix.python-version == '3.11' | |
| uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b | |
| with: | |
| script: | | |
| const coverage = '${{ steps.coverage.outputs.coverage }}'; | |
| const comment = `## Test Coverage Report\n\n📊 **Coverage: ${coverage}%**\n\nView the full coverage report in the build artifacts.`; | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: comment | |
| }); |