Skip to content

chore(refactor): moved skipcomments and filter ignored #263

chore(refactor): moved skipcomments and filter ignored

chore(refactor): moved skipcomments and filter ignored #263

Workflow file for this run

name: Tests & Coverage
on:
pull_request:
branches: [main]
jobs:
test:
if: github.actor != 'dotenv-diff-release-bot'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- uses: pnpm/action-setup@0e279bb959325dab635dd2c09392533439d90093
with:
version: 10.33.0
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e
with:
node-version: 20
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- name: Install diff-cover
run: pip install diff-cover
- name: Run coverage
run: pnpm --filter dotenv-diff run coverage
- name: Locate and normalize coverage files
id: coverage_files
run: |
LCOV_FILE="coverage/lcov.info"
SUMMARY_FILE="coverage/coverage-summary.json"
if [ -f "packages/cli/coverage/lcov.info" ]; then
LCOV_FILE="packages/cli/coverage/lcov.info"
fi
if [ -f "packages/cli/coverage/coverage-summary.json" ]; then
SUMMARY_FILE="packages/cli/coverage/coverage-summary.json"
fi
if [ ! -f "$LCOV_FILE" ]; then
echo "Missing lcov file at $LCOV_FILE"
exit 1
fi
if [ ! -f "$SUMMARY_FILE" ]; then
echo "Missing coverage summary at $SUMMARY_FILE"
exit 1
fi
# Normalize source-file paths for monolith layout so diff-cover can
# map coverage entries to changed files under packages/cli.
sed -i -E 's|^SF:src/|SF:packages/cli/src/|; s|^SF:src\\|SF:packages/cli/src/|; s|^SF:packages\\cli\\src\\|SF:packages/cli/src/|' "$LCOV_FILE"
echo "lcov_file=$LCOV_FILE" >> $GITHUB_OUTPUT
echo "summary_file=$SUMMARY_FILE" >> $GITHUB_OUTPUT
- name: Run diff-cover analysis
id: diff_cover
run: |
echo "## πŸ“Š Unit Test Coverage" > comment.md
echo "" >> comment.md
COVERAGE_THRESHOLD=80
all_passed=true
overall_coverage="N/A"
if [ -f "${{ steps.coverage_files.outputs.summary_file }}" ]; then
overall_coverage=$(jq -r '.total.lines.pct' "${{ steps.coverage_files.outputs.summary_file }}")
fi
diff-cover "${{ steps.coverage_files.outputs.lcov_file }}" \
--compare-branch=origin/${{ github.event.pull_request.base.ref }} \
--diff-range-notation=... \
--json-report diff-coverage.json \
--fail-under=0 || true
echo "**Overall coverage**: ${overall_coverage}%" >> comment.md
echo "" >> comment.md
if [ -f "diff-coverage.json" ]; then
total_lines=$(jq -r '.total_num_lines' diff-coverage.json)
if [ "$total_lines" != "0" ] && [ "$total_lines" != "null" ]; then
percent=$(jq -r '.total_percent_covered' diff-coverage.json)
violations=$(jq -r '.total_num_violations' diff-coverage.json)
covered=$((total_lines - violations))
if [ "$percent" -lt "$COVERAGE_THRESHOLD" ]; then
all_passed=false
fi
if [ "$percent" = "100" ]; then
emoji="βœ…"
status="PASS"
elif [ "$percent" -ge "$COVERAGE_THRESHOLD" ]; then
emoji="⚠️"
status="PASS"
else
emoji="❌"
status="FAIL"
fi
echo "**Diff coverage**: $emoji ${percent}% (${covered}/${total_lines} lines) - $status" >> comment.md
echo "" >> comment.md
if [ "$violations" != "0" ]; then
echo "<details>" >> comment.md
echo "<summary>πŸ” Uncovered lines in diff</summary>" >> comment.md
echo "" >> comment.md
echo '```' >> comment.md
jq -r '.src_stats | to_entries[] | .key as $file | .value.violation_lines[] | "\($file):\(.)"' diff-coverage.json >> comment.md
echo '```' >> comment.md
echo "" >> comment.md
echo "</details>" >> comment.md
fi
else
echo "✨ No new testable lines in this PR" >> comment.md
fi
fi
echo "---" >> comment.md
echo "" >> comment.md
if [ "$all_passed" = true ]; then
echo "βœ… **Coverage threshold met** (β‰₯${COVERAGE_THRESHOLD}%)" >> comment.md
else
echo "❌ **Coverage threshold not met** (required: β‰₯${COVERAGE_THRESHOLD}%)" >> comment.md
fi
echo "all_passed=$all_passed" >> $GITHUB_OUTPUT
- name: Comment PR with coverage
if: github.event.pull_request.head.repo.fork == false
uses: marocchino/sticky-pull-request-comment@0ea0beb66eb9baf113663a64ec522f60e49231c0
with:
path: comment.md
- name: Fail if coverage is below threshold
if: steps.diff_cover.outputs.all_passed == 'false'
run: |
echo "❌ Coverage check failed: Coverage below 80%"
exit 1