fs-safe/.github/workflows/coverage.yml
2026-05-06 03:16:25 +01:00

74 lines
2.0 KiB
YAML

name: coverage
on:
pull_request:
push:
branches:
- main
schedule:
- cron: "43 3 * * *"
workflow_dispatch:
permissions:
contents: read
jobs:
coverage:
name: Node 22 coverage
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Check out
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Set up pnpm
uses: pnpm/action-setup@8912a9102ac27614460f54aedde9e1e7f9aec20d # v6.0.5
with:
version: 10.33.2
run_install: false
- name: Set up Node
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: "22"
cache: pnpm
cache-dependency-path: pnpm-lock.yaml
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Coverage
run: pnpm test:coverage
- name: Summarize coverage
if: always()
run: |
node <<'NODE'
const fs = require("node:fs");
const summaryPath = "coverage/coverage-summary.json";
if (!fs.existsSync(summaryPath)) process.exit(0);
const total = JSON.parse(fs.readFileSync(summaryPath, "utf8")).total;
const pct = (key) => total[key].pct.toFixed(2);
fs.appendFileSync(
process.env.GITHUB_STEP_SUMMARY,
[
"# fs-safe coverage",
"",
"| Metric | Percent |",
"|---|---:|",
`| Lines | ${pct("lines")}% |`,
`| Statements | ${pct("statements")}% |`,
`| Functions | ${pct("functions")}% |`,
`| Branches | ${pct("branches")}% |`,
"",
].join("\n"),
);
NODE
- name: Upload coverage results
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: fs-safe-coverage-${{ github.run_id }}
path: coverage/