-
Notifications
You must be signed in to change notification settings - Fork 0
157 lines (136 loc) · 4.5 KB
/
ci.yml
File metadata and controls
157 lines (136 loc) · 4.5 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
name: CI
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
permissions:
contents: read
jobs:
quality:
name: Quality (Node ${{ matrix.node-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: [18, 20, 22]
steps:
- uses: actions/checkout@v6
- uses: pnpm/action-setup@v5
- uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
cache: pnpm
- run: pnpm install --frozen-lockfile
- name: Type check
run: pnpm typecheck
- name: Lint
if: matrix.node-version == 22
run: pnpm lint
- name: Format check
if: matrix.node-version == 22
run: pnpm format:check
- name: Test with coverage
run: |
# coverage-v8 uses node:inspector/promises (Node 19+), so run coverage only on Node 20+
if [ "${{ matrix.node-version }}" = "18" ]; then
pnpm test
else
pnpm test:coverage
fi
- name: Upload coverage
if: matrix.node-version == 22
uses: actions/upload-artifact@v7
with:
name: coverage-report
path: coverage/
retention-days: 14
- name: Build
run: pnpm build
- name: Check package size
run: |
SIZE=$(du -sk dist/ | cut -f1)
echo "📦 Package size: ${SIZE}KB"
if [ "$SIZE" -gt 512 ]; then
echo "::warning::Package size (${SIZE}KB) exceeds 512KB"
fi
publish-dry-run:
name: Publish dry run
runs-on: ubuntu-latest
needs: quality
if: github.event_name == 'pull_request'
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v6
- uses: pnpm/action-setup@v5
- uses: actions/setup-node@v6
with:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm build
- name: Pack and report
id: pack
run: |
OUTPUT=$(npm pack --dry-run 2>&1)
echo "$OUTPUT"
PKG_SIZE=$(echo "$OUTPUT" | grep 'package size' | sed 's/npm notice //')
UNPACKED=$(echo "$OUTPUT" | grep 'unpacked size' | sed 's/npm notice //')
TOTAL=$(echo "$OUTPUT" | grep 'total files' | sed 's/npm notice //')
echo "pkg_size=${PKG_SIZE}" >> "$GITHUB_OUTPUT"
echo "unpacked=${UNPACKED}" >> "$GITHUB_OUTPUT"
echo "total=${TOTAL}" >> "$GITHUB_OUTPUT"
- name: Comment on PR
uses: actions/github-script@v8
env:
PKG_SIZE: ${{ steps.pack.outputs.pkg_size }}
UNPACKED: ${{ steps.pack.outputs.unpacked }}
TOTAL: ${{ steps.pack.outputs.total }}
with:
script: |
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const marker = '<!-- sdk-publish-dry-run -->';
const existing = comments.find(c => c.body?.includes(marker));
const split = (s) => {
const [k, ...v] = (s || '').split(':');
return [k.trim(), v.join(':').trim()];
};
const [sizeK, sizeV] = split(process.env.PKG_SIZE);
const [unpackK, unpackV] = split(process.env.UNPACKED);
const [totalK, totalV] = split(process.env.TOTAL);
const body = [
marker,
'### 📦 Publish dry run',
'',
'| Metric | Value |',
'|--------|-------|',
`| ${sizeK} | ${sizeV} |`,
`| ${unpackK} | ${unpackV} |`,
`| ${totalK} | ${totalV} |`,
'',
`Commit: \`${context.sha.slice(0, 7)}\``,
].join('\n');
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,
});
}