-
Notifications
You must be signed in to change notification settings - Fork 9
101 lines (88 loc) · 3.41 KB
/
build.yml
File metadata and controls
101 lines (88 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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
});