Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: Coverage

permissions:
contents: write

concurrency:
group: coverage-gh-pages
cancel-in-progress: false

on:
push:
branches: [master]
workflow_dispatch:

env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
IRYS_CUSTOM_TMP_DIR: RUNNER_TEMP
CARGO_INCREMENTAL: 0

jobs:
coverage:
name: coverage
runs-on: [self-hosted, test-runner]
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup repo
uses: ./.github/actions/setup-repo

- name: Install cargo-llvm-cov
run: cargo install --locked --version 0.6.16 cargo-llvm-cov

- name: Fetch previous coverage history
run: |
mkdir -p previous-coverage
git fetch origin gh-pages --depth=1 2>/dev/null || true
git show origin/gh-pages:coverage/history.json > previous-coverage/history.json 2>/dev/null || echo '[]' > previous-coverage/history.json

- name: Run tests with coverage
run: cargo xtask test --coverage

- name: Build coverage summary
run: |
python3 << 'PYEOF'
import json, datetime

total_lines = 0
hit_lines = 0
with open("target/llvm-cov/lcov.info") as f:
for line in f:
line = line.strip()
if line.startswith("LF:"):
total_lines += int(line.split(":")[1])
elif line.startswith("LH:"):
hit_lines += int(line.split(":")[1])

percentage = (hit_lines / total_lines * 100) if total_lines > 0 else 0

with open("previous-coverage/history.json") as f:
history = json.load(f)

history.append({
"date": datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ"),
"commit": "${{ github.sha }}"[:12],
"total_lines": total_lines,
"covered_lines": hit_lines,
"percentage": round(percentage, 2),
})

history = history[-100:]

with open("target/llvm-cov/history.json", "w") as f:
json.dump(history, f, indent=2)

print(f"Coverage: {hit_lines}/{total_lines} lines ({percentage:.2f}%)")
if len(history) > 1:
prev = history[-2]["percentage"]
delta = percentage - prev
sign = "+" if delta >= 0 else ""
print(f"Delta: {sign}{delta:.2f}% (previous: {prev:.2f}%)")
PYEOF

- name: Checkout gh-pages
uses: actions/checkout@v4
with:
ref: gh-pages
path: gh-pages-deploy
fetch-depth: 1

- name: Update coverage data
run: |
mkdir -p gh-pages-deploy/coverage
rm -rf gh-pages-deploy/coverage/html
cp -r target/llvm-cov/html gh-pages-deploy/coverage/html
cp target/llvm-cov/lcov.info gh-pages-deploy/coverage/
cp target/llvm-cov/history.json gh-pages-deploy/coverage/

- name: Push to gh-pages
run: |
cd gh-pages-deploy
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add coverage/
if git diff --staged --quiet; then
echo "No coverage changes to commit"
else
git commit -m "coverage: update for ${GITHUB_SHA::12}"
git pull --rebase origin gh-pages
git push origin gh-pages
fi
46 changes: 46 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading