-
Notifications
You must be signed in to change notification settings - Fork 21
127 lines (111 loc) · 5.3 KB
/
Copy pathseed-build-cache.yml
File metadata and controls
127 lines (111 loc) · 5.3 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
name: Build Size Cache
# Manual workflow to seed the build-sizes cache for a branch,
# or to verify that a cache entry already exists.
#
# Usage:
# - "seed": Build the selected branch and save its VSIX + webview sizes to the cache.
# - "verify": Check whether a cache entry exists for the selected branch (no build needed).
on:
workflow_dispatch:
inputs:
mode:
description: 'Action to perform'
required: true
type: choice
options:
- seed
- verify
default: seed
jobs:
seed:
name: Seed build size cache
runs-on: ubuntu-latest
if: inputs.mode == 'seed'
permissions:
contents: read
actions: write
steps:
- name: ✅ Checkout Repository
uses: actions/checkout@v6
- name: 🛠 Setup Node.js Environment (with cache)
uses: actions/setup-node@v5
with:
node-version-file: .nvmrc
cache: npm
cache-dependency-path: '**/package-lock.json'
- name: 📦 Install Dependencies
run: npm ci --prefer-offline --no-audit --no-fund --progress=false
- name: 🏗 Build Project
run: npm run build
- name: 📦 Package Distributables
run: npm run package
- name: 📐 Collect build sizes
id: sizes
run: |
VSIX_FILE=$(find . -maxdepth 1 -name '*.vsix' | head -1)
VSIX_SIZE=$(stat --format=%s "$VSIX_FILE")
WEBVIEW_SIZE=$(stat --format=%s dist/views.js 2>/dev/null || echo 0)
CACHE_KEY="build-sizes-${{ github.ref_name }}-${{ github.sha }}"
echo "{\"vsixSize\": $VSIX_SIZE, \"webviewSize\": $WEBVIEW_SIZE}" > build-sizes.json
echo "### 📐 Build Sizes for \`${{ github.ref_name }}\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Metric | Size |" >> $GITHUB_STEP_SUMMARY
echo "|--------|------|" >> $GITHUB_STEP_SUMMARY
echo "| VSIX (\`$(basename "$VSIX_FILE")\`) | $(numfmt --to=iec --suffix=B $VSIX_SIZE) |" >> $GITHUB_STEP_SUMMARY
echo "| Webview bundle (\`views.js\`) | $(numfmt --to=iec --suffix=B $WEBVIEW_SIZE) |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Cache key: \`$CACHE_KEY\`" >> $GITHUB_STEP_SUMMARY
- name: 💾 Save to cache
uses: actions/cache/save@v5
with:
path: build-sizes.json
key: build-sizes-${{ github.ref_name }}-${{ github.sha }}
- name: ✅ Done
run: echo "Cache seeded for ${{ github.ref_name }} @ ${{ github.sha }}"
verify:
name: Verify build size cache
runs-on: ubuntu-latest
if: inputs.mode == 'verify'
permissions:
actions: read
steps:
- name: 📥 Attempt exact cache restore
id: exact
uses: actions/cache/restore@v5
with:
path: build-sizes.json
key: build-sizes-${{ github.ref_name }}-${{ github.sha }}
lookup-only: true
- name: 📥 Attempt prefix cache restore
id: prefix
uses: actions/cache/restore@v5
with:
path: build-sizes-prefix.json
key: build-sizes-${{ github.ref_name }}-${{ github.sha }}-impossible
restore-keys: |
build-sizes-${{ github.ref_name }}-
lookup-only: true
- name: 📋 Report results
uses: actions/github-script@v8
with:
script: |
const branch = '${{ github.ref_name }}';
const sha = '${{ github.sha }}';
const exactHit = '${{ steps.exact.outputs.cache-matched-key }}';
const prefixHit = '${{ steps.prefix.outputs.cache-matched-key }}';
const lines = [
`### 🔍 Cache Verification for \`${branch}\``,
'',
`| Check | Result |`,
`|-------|--------|`,
`| Exact match (\`build-sizes-${branch}-${sha.slice(0,8)}…\`) | ${exactHit ? '✅ Hit: `' + exactHit + '`' : '❌ Miss'} |`,
`| Prefix match (\`build-sizes-${branch}-*\`) | ${prefixHit ? '✅ Hit: `' + prefixHit + '`' : '❌ Miss'} |`,
];
if (!exactHit && !prefixHit) {
lines.push('', '> ⚠️ No cache exists for this branch. Run this workflow again with **seed** mode.');
} else if (!exactHit && prefixHit) {
lines.push('', `> ℹ️ No exact SHA match, but a previous cache entry exists. PRs will use this as the baseline.`);
} else {
lines.push('', '> ✅ Cache is up to date for the current HEAD.');
}
await core.summary.addRaw(lines.join('\n')).write();