Skip to content

Commit 9baeb21

Browse files
committed
fix: test coverage summary output and dry run publish fixes
1 parent 5bb1802 commit 9baeb21

File tree

4 files changed

+287
-32
lines changed

4 files changed

+287
-32
lines changed

.github/scripts/example.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import {
2-
createStickyComment,
3-
findCommentByIdentifier,
4-
addLabelsToPullRequest,
52
pullRequestHasLabels,
63
getCurrentPullRequestNumber,
74
getRepoInfo,
85
sanitizeInput,
96
escapeMarkdown,
107
formatDate,
118
checkBranchExists,
12-
listDeployments,
139
} from "github-typescript-utils";
1410

1511
type Ctx = {
@@ -30,13 +26,9 @@ type Ctx = {
3026
export default async function run({ core, github, context, args }: Ctx) {
3127
core.info("🚀 Starting E2E test of github-typescript-utils");
3228

33-
// Debug: Log the context structure
34-
core.info(`🔍 Debug - context keys: ${Object.keys(context).join(', ')}`);
35-
core.info(`🔍 Debug - context.repo: ${JSON.stringify(context.repo)}`);
36-
core.info(`🔍 Debug - context.eventName: ${context.eventName}`);
37-
core.info(`🔍 Debug - context ${JSON.stringify(context)}`);
38-
3929
try {
30+
const ctx = { core, github, context };
31+
4032
// Test 1: Input sanitization
4133
const sanitizedMessage = sanitizeInput(args.testMessage);
4234
core.info(
@@ -51,17 +43,17 @@ export default async function run({ core, github, context, args }: Ctx) {
5143
);
5244

5345
// Test 3: Context utilities
54-
const repoInfo = getRepoInfo({ core, github, context });
46+
const repoInfo = getRepoInfo(ctx);
5547
core.info(`✅ Repo info: ${repoInfo.owner}/${repoInfo.repo}`);
5648

5749
// Test 4: PR context (if available)
58-
const prNumber = getCurrentPullRequestNumber({ core, github, context });
50+
const prNumber = getCurrentPullRequestNumber(ctx);
5951
if (prNumber) {
6052
core.info(`✅ PR context: Found PR #${prNumber}`);
6153

6254
// Test PR utilities
6355
const hasLabels = await pullRequestHasLabels({
64-
ctx: { core, github, context },
56+
ctx,
6557
repo: repoInfo,
6658
pullNumber: prNumber,
6759
labels: args.testLabels,
@@ -77,7 +69,7 @@ export default async function run({ core, github, context, args }: Ctx) {
7769

7870
// Test 5: Branch utilities
7971
const branchExists = await checkBranchExists({
80-
ctx: { core, github, context },
72+
ctx,
8173
repo: repoInfo,
8274
branchName: args.testBranch,
8375
});

.github/scripts/pnpm-lock.yaml

Lines changed: 223 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/scripts/tsconfig.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2022",
4+
"module": "ESNext",
5+
"moduleResolution": "node",
6+
"esModuleInterop": true,
7+
"allowSyntheticDefaultImports": true,
8+
"strict": true,
9+
"skipLibCheck": true,
10+
"forceConsistentCasingInFileNames": true,
11+
"resolveJsonModule": true,
12+
"baseUrl": ".",
13+
"paths": {
14+
"github-typescript-utils": ["../../dist/index.d.ts"]
15+
}
16+
},
17+
"include": ["*.ts"],
18+
"exclude": ["node_modules"]
19+
}

.github/workflows/ci.yml

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,28 +61,49 @@ jobs:
6161
- name: Coverage Summary
6262
run: |
6363
# Run tests with coverage and capture output
64-
TEST_OUTPUT=$(pnpm run test:coverage 2>&1)
64+
pnpm run test:coverage > coverage_output.txt 2>&1
6565
6666
echo "## 📊 Test Coverage Report" >> $GITHUB_STEP_SUMMARY
6767
echo "" >> $GITHUB_STEP_SUMMARY
6868
6969
# Extract test results
70-
TEST_COUNT=$(echo "$TEST_OUTPUT" | grep -o '[0-9]\+ passed' | head -1 | grep -o '[0-9]\+')
71-
OVERALL_COVERAGE=$(echo "$TEST_OUTPUT" | grep "All files" | awk '{print $3}')
72-
73-
# Add coverage table
74-
echo "| File | Statements | Branches | Functions | Lines |" >> $GITHUB_STEP_SUMMARY
75-
echo "|------|------------|----------|-----------|-------|" >> $GITHUB_STEP_SUMMARY
76-
77-
# Parse coverage and add to summary
78-
echo "$TEST_OUTPUT" | grep -E "^\s*(All files|[a-z-]+\.ts)" | while read line; do
79-
if [[ $line == *"All files"* ]]; then
80-
echo "| **Overall** | $(echo $line | awk '{print $3}') | $(echo $line | awk '{print $4}') | $(echo $line | awk '{print $5}') | $(echo $line | awk '{print $6}') |" >> $GITHUB_STEP_SUMMARY
81-
elif [[ $line == *.ts* ]]; then
82-
filename=$(echo $line | awk '{print $1}')
83-
echo "| $filename | $(echo $line | awk '{print $3}') | $(echo $line | awk '{print $4}') | $(echo $line | awk '{print $5}') | $(echo $line | awk '{print $6}') |" >> $GITHUB_STEP_SUMMARY
84-
fi
85-
done
70+
TEST_COUNT=$(grep -o '[0-9]\+ passed' coverage_output.txt | head -1 | grep -o '[0-9]\+' || echo "0")
71+
72+
# Check if coverage file exists and extract coverage
73+
if [ -f coverage/coverage-summary.json ]; then
74+
OVERALL_COVERAGE=$(node -e "
75+
const fs = require('fs');
76+
const coverage = JSON.parse(fs.readFileSync('coverage/coverage-summary.json', 'utf8'));
77+
console.log(coverage.total.statements.pct + '%');
78+
")
79+
80+
echo "| File | Statements | Branches | Functions | Lines |" >> $GITHUB_STEP_SUMMARY
81+
echo "|------|------------|----------|-----------|-------|" >> $GITHUB_STEP_SUMMARY
82+
83+
# Add overall coverage
84+
node -e "
85+
const fs = require('fs');
86+
const coverage = JSON.parse(fs.readFileSync('coverage/coverage-summary.json', 'utf8'));
87+
const total = coverage.total;
88+
console.log(\`| **Overall** | \${total.statements.pct}% | \${total.branches.pct}% | \${total.functions.pct}% | \${total.lines.pct}% |\`);
89+
" >> $GITHUB_STEP_SUMMARY
90+
91+
# Add individual file coverage
92+
node -e "
93+
const fs = require('fs');
94+
const coverage = JSON.parse(fs.readFileSync('coverage/coverage-summary.json', 'utf8'));
95+
Object.keys(coverage).forEach(file => {
96+
if (file !== 'total' && file.includes('src/') && !file.includes('__tests__')) {
97+
const filename = file.split('/').pop();
98+
const fileCov = coverage[file];
99+
console.log(\`| \${filename} | \${fileCov.statements.pct}% | \${fileCov.branches.pct}% | \${fileCov.functions.pct}% | \${fileCov.lines.pct}% |\`);
100+
}
101+
});
102+
" >> $GITHUB_STEP_SUMMARY
103+
else
104+
OVERALL_COVERAGE="N/A"
105+
echo "Coverage data not available" >> $GITHUB_STEP_SUMMARY
106+
fi
86107
87108
echo "" >> $GITHUB_STEP_SUMMARY
88109
echo "✅ **${TEST_COUNT} tests passed** with **${OVERALL_COVERAGE} overall coverage**" >> $GITHUB_STEP_SUMMARY
@@ -198,4 +219,4 @@ jobs:
198219
run: pnpm run build
199220

200221
- name: Publish dry run
201-
run: pnpm publish --dry-run
222+
run: pnpm publish --dry-run --no-git-checks

0 commit comments

Comments
 (0)