-
Notifications
You must be signed in to change notification settings - Fork 0
158 lines (139 loc) · 4.29 KB
/
Copy pathci.yml
File metadata and controls
158 lines (139 loc) · 4.29 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Bun
uses: oven-sh/setup-bun@v1
- name: Install coreutils (gtimeout) on macOS
if: runner.os == 'macOS'
run: brew install coreutils
- name: Install dependencies
run: bun install
- name: Run tests
run: bun test
- name: Typecheck
run: |
if [ -f tsconfig.json ]; then
bunx tsc --noEmit
else
echo "No tsconfig.json found, skipping typecheck"
fi
- name: ShellCheck
shell: bash
run: |
if [ "$RUNNER_OS" = "macOS" ]; then
brew install shellcheck
else
sudo apt-get update && sudo apt-get install -y shellcheck
fi
files=$(find . -type f -name '*.sh' -not -path './node_modules/*' -not -path './.git/*')
if [ -n "$files" ]; then
echo "$files" | xargs shellcheck
else
echo "No .sh files found"
fi
coverage:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
permissions:
pull-requests: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Bun
uses: oven-sh/setup-bun@v1
- name: Install dependencies
run: bun install
- name: Run coverage
id: cov
run: |
set -o pipefail
bun test --coverage 2>&1 | tee coverage.txt
- name: Comment PR with coverage
if: always()
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const raw = fs.readFileSync('coverage.txt', 'utf8');
const body = [
'## Coverage report',
'',
'Thresholds: `line >= 70%`, `function >= 60%` (see `bunfig.toml`).',
'',
'```',
raw.trim(),
'```',
].join('\n');
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const marker = '## Coverage report';
const existing = comments.find(c => c.body && c.body.startsWith(marker));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}
coverage-badge:
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Bun
uses: oven-sh/setup-bun@v1
- name: Install dependencies
run: bun install
- name: Run coverage
run: |
set -o pipefail
bun test --coverage 2>&1 | tee coverage.txt
- name: Regenerate badge
run: |
line_pct=$(awk -F'|' '/^All files/ { gsub(/ /,"",$3); print $3 }' coverage.txt)
if [ -z "$line_pct" ]; then
echo "could not extract line %, leaving badge as-is"
exit 0
fi
bun scripts/gen-coverage-badge.ts "$line_pct"
- name: Commit badge if changed
run: |
if git diff --quiet docs/coverage.svg README.md; then
echo "no badge change"
exit 0
fi
git config user.name "batonq-ci"
git config user.email "ci@batonq.local"
git add docs/coverage.svg README.md
git commit -m "ci(coverage): refresh badge [skip ci]"
git push