-
-
Notifications
You must be signed in to change notification settings - Fork 334
175 lines (166 loc) · 5.82 KB
/
Copy pathci.yml
File metadata and controls
175 lines (166 loc) · 5.82 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
name: CI
on:
push:
branches: [main]
tags: ['v*']
pull_request:
branches: [main]
workflow_dispatch:
jobs:
typecheck:
name: Typecheck (Node ${{ matrix.node }}, ${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
node: 20
- os: ubuntu-latest
node: 22
- os: windows-latest
node: 22
- os: macos-latest
node: 22
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: npm
- run: npm ci
- run: npm run typecheck
test:
name: Test (Node ${{ matrix.node }}, ${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
node: 20
- os: ubuntu-latest
node: 22
- os: windows-latest
node: 22
- os: macos-latest
node: 22
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: npm
- run: npm ci
- run: npm run build
- run: npm test
pack-verify:
name: Pack & Verify (Node ${{ matrix.node }}, ${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
node: 22
- os: windows-latest
node: 22
- os: macos-latest
node: 22
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: npm
- run: npm ci
- run: npm run build
- name: Verify package integrity
run: node scripts/verify-package.cjs
termux:
name: Termux (Android, x86_64)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run CI in Termux container
shell: bash
run: |
cat > /tmp/termux-ci.sh <<'CI_SCRIPT'
#!/bin/sh
set -ex
export PATH=/data/data/com.termux/files/usr/bin:$PATH
export HOME=/home/builder
export npm_config_cache=/home/builder/project/.npm-cache
export TERMUX_VERSION=u0
# Pin a known-reliable mirror to avoid transient 520s on community mirrors
sed -i 's|^\(deb .*\)|deb https://packages-cf.termux.dev/apt/termux-main stable main|' /data/data/com.termux/files/usr/etc/apt/sources.list 2>/dev/null || true
pkg update -y || {
echo 'pkg update failed, retrying...'
pkg update -y
}
# Retry package install up to 3 times — Termux mirrors are flaky
for attempt in 1 2 3; do
pkg install -y git nodejs-lts python build-essential && break
echo "pkg install attempt $attempt failed, retrying..."
pkg update -y || true
done
cd /home/builder/project
npm install --no-audit --no-fund
npm install --no-save --no-audit --no-fund @rollup/wasm-node@4
rm -rf node_modules/rollup
ln -s @rollup/wasm-node node_modules/rollup
# .bin symlinks aren't in PATH in Termux's ash — add them explicitly
export PATH="$PWD/node_modules/.bin:$PATH"
node node_modules/tsup/dist/cli-default.js
node scripts/post-build.cjs
node -e "try { const Database = require('better-sqlite3'); const db = new Database(':memory:'); db.prepare('select 1').get(); db.close(); console.log('better-sqlite3 OK'); } catch (e) { console.log('better-sqlite3 unavailable (optional on Termux):', e.message); }"
node -e "const { spawnSync } = require('node:child_process'); const r = spawnSync(process.execPath, ['dist/index.js', '--help'], { encoding: 'utf8' }); if (r.status !== 0 || !r.stdout.includes('Usage:')) process.exit(1)"
node node_modules/vitest/vitest.mjs run
CI_SCRIPT
chmod +x /tmp/termux-ci.sh
docker run --rm \
--privileged \
--entrypoint /entrypoint_root.sh \
-v "${{ github.workspace }}:/home/builder/project" \
-v /tmp/termux-ci.sh:/tmp/termux-ci.sh:ro \
-e "HOME=/home/builder" \
termux/termux-docker:x86_64 \
bash -c "
set -e
chown -R system:system /home/builder
mkdir -p /home/builder/.npm
chown -R system:system /home/builder/.npm
cp /tmp/termux-ci.sh /home/builder/termux-ci.sh
chown system:system /home/builder/termux-ci.sh
chmod +x /home/builder/termux-ci.sh
su system /home/builder/termux-ci.sh
"
# TEMPORARILY DISABLED: npm publish fails in CI and marks the whole pipeline red.
# Code kept for reference — re-enable (uncomment) once publishing is fixed.
#
# publish:
# name: Publish to npm
# needs: [typecheck, test, pack-verify, termux]
# runs-on: ubuntu-latest
# if: startsWith(github.ref, 'refs/tags/v')
# permissions:
# contents: read
# id-token: write
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-node@v4
# with:
# node-version: 22
# registry-url: https://registry.npmjs.org
# - run: npm ci
# - run: npm run build
# - name: Check if version already published
# run: |
# PKG_VERSION=$(node -p "require('./package.json').version")
# if npm view "@cosmicstack/mercury-agent@$PKG_VERSION" version 2>/dev/null; then
# echo "Version $PKG_VERSION already published — skipping."
# exit 0
# fi
# - run: npm publish --access public --provenance
# env:
# NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}