Skip to content

Commit ccca35f

Browse files
ci: add PR CI workflow for basic checks
1 parent c4ac328 commit ccca35f

1 file changed

Lines changed: 134 additions & 0 deletions

File tree

.github/workflows/pr-ci.yml

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
# Cancel previous runs for the same PR / branch
8+
concurrency:
9+
group: ci-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
# ── 1. Install dependencies ────────────────────────────────
14+
install:
15+
name: Install
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- uses: actions/setup-node@v4
21+
with:
22+
node-version: "22"
23+
24+
- name: Cache node_modules
25+
uses: actions/cache@v4
26+
id: cache-deps
27+
with:
28+
path: node_modules
29+
key: deps-${{ runner.os }}-${{ hashFiles('package.json') }}
30+
31+
- name: npm install
32+
if: steps.cache-deps.outputs.cache-hit != 'true'
33+
run: npm install --ignore-scripts
34+
35+
# ── 2. Pack validation ─────────────────────────────────────
36+
pack:
37+
name: Pack
38+
needs: install
39+
runs-on: ubuntu-latest
40+
steps:
41+
- uses: actions/checkout@v4
42+
43+
- uses: actions/setup-node@v4
44+
with:
45+
node-version: "22"
46+
47+
- name: Restore node_modules
48+
uses: actions/cache@v4
49+
with:
50+
path: node_modules
51+
key: deps-${{ runner.os }}-${{ hashFiles('package.json') }}
52+
53+
- name: npm pack (dry-run)
54+
run: npm pack --dry-run
55+
56+
- name: npm pack
57+
run: npm pack
58+
59+
- name: Upload .tgz artifact
60+
uses: actions/upload-artifact@v4
61+
with:
62+
name: package-tarball
63+
path: "*.tgz"
64+
retention-days: 7
65+
66+
# ── 5. Plugin manifest validation ──────────────────────────
67+
manifest:
68+
name: Manifest
69+
runs-on: ubuntu-latest
70+
steps:
71+
- uses: actions/checkout@v4
72+
73+
- name: Validate openclaw.plugin.json
74+
run: |
75+
echo "── Checking openclaw.plugin.json exists ──"
76+
test -f openclaw.plugin.json || { echo "❌ openclaw.plugin.json not found"; exit 1; }
77+
78+
echo "── Checking valid JSON ──"
79+
node -e "JSON.parse(require('fs').readFileSync('openclaw.plugin.json','utf8'))" || { echo "❌ Invalid JSON"; exit 1; }
80+
81+
echo "── Checking required fields ──"
82+
node -e "
83+
const m = JSON.parse(require('fs').readFileSync('openclaw.plugin.json','utf8'));
84+
const errors = [];
85+
if (!m.id || typeof m.id !== 'string') errors.push('missing or invalid \"id\"');
86+
if (m.configSchema && typeof m.configSchema !== 'object') errors.push('\"configSchema\" must be an object');
87+
if (errors.length) { console.error('❌ Manifest errors:', errors.join(', ')); process.exit(1); }
88+
console.log('✅ id:', m.id);
89+
if (m.name) console.log(' name:', m.name);
90+
if (m.configSchema) console.log(' configSchema: present (' + Object.keys(m.configSchema.properties || {}).length + ' top-level props)');
91+
"
92+
93+
echo "── Checking package.json openclaw metadata ──"
94+
node -e "
95+
const pkg = JSON.parse(require('fs').readFileSync('package.json','utf8'));
96+
const oc = pkg.openclaw || {};
97+
const errors = [];
98+
if (!oc.extensions || !oc.extensions.length) errors.push('missing openclaw.extensions');
99+
if (!oc.compat?.pluginApi) errors.push('missing openclaw.compat.pluginApi');
100+
if (!oc.build?.openclawVersion) errors.push('missing openclaw.build.openclawVersion');
101+
if (errors.length) { console.error('❌ Package metadata errors:', errors.join(', ')); process.exit(1); }
102+
console.log('✅ openclaw metadata OK');
103+
console.log(' pluginApi:', oc.compat.pluginApi);
104+
console.log(' openclawVersion:', oc.build.openclawVersion);
105+
"
106+
107+
# ── 6. Package size guard ──────────────────────────────────
108+
size:
109+
name: Size Guard
110+
needs: pack
111+
runs-on: ubuntu-latest
112+
steps:
113+
- name: Download tarball
114+
uses: actions/download-artifact@v4
115+
with:
116+
name: package-tarball
117+
118+
- name: Check package size
119+
run: |
120+
TGZ=$(ls *.tgz | head -1)
121+
SIZE=$(stat -c%s "$TGZ" 2>/dev/null || stat -f%z "$TGZ")
122+
SIZE_KB=$((SIZE / 1024))
123+
MAX_KB=512
124+
125+
echo "📦 Package: $TGZ"
126+
echo " Size: ${SIZE_KB} KB (limit: ${MAX_KB} KB)"
127+
128+
if [ "$SIZE_KB" -gt "$MAX_KB" ]; then
129+
echo "❌ Package exceeds ${MAX_KB} KB size limit!"
130+
echo " Consider checking if large files were accidentally included."
131+
exit 1
132+
else
133+
echo "✅ Size OK"
134+
fi

0 commit comments

Comments
 (0)