-
Notifications
You must be signed in to change notification settings - Fork 0
181 lines (146 loc) · 5.29 KB
/
ci.yml
File metadata and controls
181 lines (146 loc) · 5.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
name: CI
on:
push:
branches: [main]
tags:
- "v*"
pull_request:
branches: [main]
permissions:
contents: write
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Install pnpm
uses: pnpm/action-setup@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: pnpm
- name: Install dependencies
run: pnpm install
- name: Build
run: pnpm run build
- name: Lint
run: pnpm run lint
- name: Typecheck
run: pnpm run typecheck
- name: Test
run: pnpm run test
e2e:
name: E2E Tests
uses: ./.github/workflows/e2e.yml
publish:
needs: [build-and-test, e2e]
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Install pnpm
uses: pnpm/action-setup@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: pnpm
registry-url: "https://registry.npmjs.org"
- name: Install dependencies
run: pnpm install
- name: Build
run: pnpm run build
- name: Generate bundle size report
id: bundle-size
run: |
# Helper function to format bytes
format_bytes() {
local bytes=$1
if [ $bytes -ge 1024 ]; then
printf "%.2f KB" $(echo "scale=2; $bytes/1024" | bc)
else
printf "%d B" $bytes
fi
}
# Start markdown report
{
echo "## Bundle Sizes"
echo ""
echo "| Package | Format | Size | Gzipped |"
echo "|---------|--------|------|----------|"
} > bundle-size-report.md
# Auto-discover and report all packages
for pkg_dir in packages/*/; do
pkg_name=$(basename "$pkg_dir")
dist_dir="${pkg_dir}dist"
# Skip if no dist directory
[ -d "$dist_dir" ] || continue
# Get package name from package.json
if [ -f "${pkg_dir}package.json" ]; then
npm_name=$(jq -r '.name' "${pkg_dir}package.json")
else
npm_name="@replanejs/${pkg_name}"
fi
# Special handling for Svelte (unbundled, multiple JS files)
if [ "$pkg_name" = "svelte" ]; then
esm_size=$(cat "${dist_dir}"/*.js 2>/dev/null | wc -c | tr -d ' ')
esm_gz=$(cat "${dist_dir}"/*.js 2>/dev/null | gzip -c | wc -c | tr -d ' ')
if [ "$esm_size" -gt 0 ]; then
echo "| ${npm_name} | ESM | $(format_bytes $esm_size) | $(format_bytes $esm_gz) |" >> bundle-size-report.md
fi
continue
fi
# Check for ESM bundle (index.js)
if [ -f "${dist_dir}/index.js" ]; then
esm_size=$(stat -c%s "${dist_dir}/index.js")
esm_gz=$(gzip -c "${dist_dir}/index.js" | wc -c | tr -d ' ')
echo "| ${npm_name} | ESM | $(format_bytes $esm_size) | $(format_bytes $esm_gz) |" >> bundle-size-report.md
fi
# Check for CJS bundle (index.cjs)
if [ -f "${dist_dir}/index.cjs" ]; then
cjs_size=$(stat -c%s "${dist_dir}/index.cjs")
cjs_gz=$(gzip -c "${dist_dir}/index.cjs" | wc -c | tr -d ' ')
echo "| ${npm_name} | CJS | $(format_bytes $cjs_size) | $(format_bytes $cjs_gz) |" >> bundle-size-report.md
fi
done
cat bundle-size-report.md
- name: Extract version from tag
id: version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Sync package versions
run: |
VERSION=${{ steps.version.outputs.VERSION }}
echo "Setting all packages to version $VERSION"
# Update version in all package.json files
for pkg in packages/*/package.json; do
jq --arg v "$VERSION" '.version = $v' "$pkg" > tmp.json && mv tmp.json "$pkg"
echo "$pkg: $VERSION"
done
# Note: pnpm automatically replaces workspace:^ with ^VERSION during publish
- name: Publish all packages
run: pnpm -r publish --access public --no-git-checks
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create GitHub Release
run: npx changelogithub
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Append bundle size to release
run: |
# Get current release body
CURRENT_BODY=$(gh release view "${{ github.ref_name }}" --json body -q '.body')
# Append bundle size report (with blank line separator)
BUNDLE_REPORT=$(cat bundle-size-report.md)
# Combine with newline separator
printf -v NEW_BODY '%s\n\n%s' "$CURRENT_BODY" "$BUNDLE_REPORT"
# Update release with new body
gh release edit "${{ github.ref_name }}" --notes "$NEW_BODY"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}