Skip to content

Commit 43e988d

Browse files
fix: ci trigger on push, esbuild CJS bundle for pkg binary compilation
- ci.yml: add push trigger (was missing — CI never ran on push) - release.yml: switch to esbuild→@yao-pkg/pkg pipeline - esbuild bundles ESM source to dist/bundle.cjs (CJS) - @yao-pkg/pkg compiles CJS bundle → standalone binary - Fixes UNEXPECTED-20 / Cannot find module errors on all platforms - Add bin/pkg-launcher.cjs (pure CJS entry for pkg) - Add scripts/build.mjs (esbuild bundler) - Add src/version.mjs (avoids readFileSync in CJS context) - Remove unused fileURLToPath imports from 13 command files
1 parent 905d08c commit 43e988d

23 files changed

Lines changed: 617 additions & 200 deletions

.github/workflows/ci.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
name: CI
22

3-
# PR check — fast feedback before merging to main.
4-
# The full release pipeline (tests + build + publish) runs on push to main via release.yml.
3+
# Runs on EVERY push to main/develop AND every pull request.
4+
# Both CI (this) and Release workflows fire on push — CI is the fast gate.
55

66
on:
7+
push:
8+
branches: [ main, develop ]
79
pull_request:
810
branches: [ main ]
911
workflow_dispatch:
@@ -24,7 +26,4 @@ jobs:
2426
cache: npm
2527
cache-dependency-path: cloudsync-cli/package-lock.json
2628
- run: npm ci
27-
- run: |
28-
for f in $(find src -name '*.js'); do node --check "$f" || exit 1; done
29-
node --check bin/cloudsync.js || exit 1
3029
- run: npm test

.github/workflows/release.yml

Lines changed: 37 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
name: Release
22

3-
# FULLY AUTOMATED — every push to main triggers the complete pipeline.
4-
# No manual tags. No `npm publish`. Nothing local.
5-
#
6-
# Push to main → CalVer auto-version → Tests → Builds → Publish + Release
7-
# Version: YYYY.M.BUILD (e.g. 2026.7.1, 2026.7.2, 2026.8.1)
3+
# FULLY AUTOMATED — every push to main.
4+
# CalVer auto-version → Tests → esbuild bundle → pkg binary → Publish.
85

96
on:
107
push:
@@ -16,9 +13,6 @@ permissions:
1613
packages: write
1714

1815
jobs:
19-
# ═══════════════════════════════════════════════════════════
20-
# 1. AUTO-VERSION — CalVer: YYYY.M.BUILD, auto-increments
21-
# ═══════════════════════════════════════════════════════════
2216
version:
2317
name: Calculate Version
2418
runs-on: ubuntu-latest
@@ -27,30 +21,22 @@ jobs:
2721
tag: ${{ steps.calver.outputs.tag }}
2822
steps:
2923
- uses: actions/checkout@v4
30-
with:
31-
fetch-depth: 0
32-
fetch-tags: true
33-
34-
- name: Generate CalVer
24+
with: { fetch-depth: 0, fetch-tags: true }
25+
- name: CalVer
3526
id: calver
3627
run: |
37-
YEAR=$(date +%Y)
38-
MONTH=$(date +%-m)
28+
Y=$(date +%Y); M=$(date +%-m)
3929
git fetch --tags 2>/dev/null || true
40-
HIGHEST=0
41-
for tag in $(git tag -l "v${YEAR}.${MONTH}.*"); do
42-
B=$(echo "$tag" | sed "s/v${YEAR}.${MONTH}.//")
43-
if [ "$B" -gt "$HIGHEST" ] 2>/dev/null; then HIGHEST=$B; fi
30+
H=0
31+
for t in $(git tag -l "v${Y}.${M}.*"); do
32+
B=$(echo "$t" | sed "s/v${Y}.${M}.//")
33+
[ "$B" -gt "$H" ] 2>/dev/null && H=$B
4434
done
45-
NEXT=$((HIGHEST + 1))
46-
V="${YEAR}.${MONTH}.${NEXT}"
35+
V="${Y}.${M}.$((H+1))"
4736
echo "version=${V}" >> $GITHUB_OUTPUT
4837
echo "tag=v${V}" >> $GITHUB_OUTPUT
49-
echo "CalVer: ${V} (tag: v${V})"
38+
echo "Version: ${V}"
5039
51-
# ═══════════════════════════════════════════════════════════
52-
# 2. TEST — must pass on all Node versions
53-
# ═══════════════════════════════════════════════════════════
5440
test:
5541
name: Test (Node ${{ matrix.node }})
5642
runs-on: ubuntu-latest
@@ -69,9 +55,6 @@ jobs:
6955
- run: npm ci
7056
- run: npm test
7157

72-
# ═══════════════════════════════════════════════════════════
73-
# 3. BUILD — platform binaries (parallel)
74-
# ═══════════════════════════════════════════════════════════
7558
build-windows:
7659
name: Windows EXE
7760
runs-on: windows-latest
@@ -81,12 +64,13 @@ jobs:
8164
- uses: actions/checkout@v4
8265
- uses: actions/setup-node@v4
8366
with:
84-
node-version: '20'
67+
node-version: '22'
8568
cache: npm
8669
cache-dependency-path: cloudsync-cli/package-lock.json
8770
- run: npm ci
88-
- run: npm install -g pkg@5.8.1
89-
- run: pkg bin/cloudsync.js -t node18-win-x64 -o cloudsync.exe
71+
- run: npm run build
72+
- run: npm install -g @yao-pkg/pkg
73+
- run: pkg dist/bundle.cjs -t node22-win-x64 -o cloudsync.exe
9074
- run: .\cloudsync.exe --version
9175
- run: |
9276
mkdir release-assets
@@ -115,12 +99,13 @@ jobs:
11599
- uses: actions/checkout@v4
116100
- uses: actions/setup-node@v4
117101
with:
118-
node-version: '20'
102+
node-version: '22'
119103
cache: npm
120104
cache-dependency-path: cloudsync-cli/package-lock.json
121105
- run: npm ci
122-
- run: npm install -g pkg@5.8.1
123-
- run: pkg bin/cloudsync.js -t node18-linux-x64 -o cloudsync
106+
- run: npm run build
107+
- run: npm install -g @yao-pkg/pkg
108+
- run: pkg dist/bundle.cjs -t node22-linux-x64 -o cloudsync
124109
- run: chmod +x cloudsync && ./cloudsync --version
125110
- uses: actions/upload-artifact@v4
126111
with:
@@ -137,32 +122,28 @@ jobs:
137122
- uses: actions/checkout@v4
138123
- uses: actions/setup-node@v4
139124
with:
140-
node-version: '20'
125+
node-version: '22'
141126
cache: npm
142127
cache-dependency-path: cloudsync-cli/package-lock.json
143128
- run: npm ci
144-
- run: npm install -g pkg@5.8.1
145-
- run: pkg bin/cloudsync.js -t node18-macos-x64 -o cloudsync
129+
- run: npm run build
130+
- run: npm install -g @yao-pkg/pkg
131+
- run: pkg dist/bundle.cjs -t node22-macos-x64 -o cloudsync
146132
- run: chmod +x cloudsync && ./cloudsync --version
147133
- uses: actions/upload-artifact@v4
148134
with:
149135
name: macos-build
150136
path: cloudsync-cli/cloudsync
151137
retention-days: 7
152138

153-
# ═══════════════════════════════════════════════════════════
154-
# 4. PUBLISH EVERYTHING (npm + GPR + Git tag + GitHub Release)
155-
# ═══════════════════════════════════════════════════════════
156139
publish:
157140
name: Publish & Release
158141
runs-on: ubuntu-latest
159142
needs: [ version, build-windows, build-linux, build-macos ]
160143
defaults: { run: { working-directory: ./cloudsync-cli } }
161144
steps:
162145
- uses: actions/checkout@v4
163-
with:
164-
fetch-depth: 0
165-
fetch-tags: true
146+
with: { fetch-depth: 0, fetch-tags: true }
166147

167148
- uses: actions/download-artifact@v4
168149
with: { name: windows-build, path: assets/windows }
@@ -171,19 +152,24 @@ jobs:
171152
- uses: actions/download-artifact@v4
172153
with: { name: macos-build, path: assets/macos }
173154

174-
- name: Set version in package.json
175-
run: npm pkg set version=${{ needs.version.outputs.version }}
155+
- name: Set version
156+
run: |
157+
V=${{ needs.version.outputs.version }}
158+
npm pkg set version=$V
159+
echo "export const VERSION = '$V';" > src/version.mjs
176160
177-
- name: Create and push git tag
161+
- name: Create git tag
178162
run: |
179163
git config user.name "github-actions"
180164
git config user.email "actions@github.com"
165+
git add package.json src/version.mjs
166+
git commit -m "release: ${{ needs.version.outputs.version }}" || true
181167
git tag ${{ needs.version.outputs.tag }}
182-
git push origin ${{ needs.version.outputs.tag }}
168+
git push origin HEAD:main ${{ needs.version.outputs.tag }}
183169
184170
- uses: actions/setup-node@v4
185171
with:
186-
node-version: '20'
172+
node-version: '22'
187173
registry-url: 'https://registry.npmjs.org'
188174
cache: npm
189175
cache-dependency-path: cloudsync-cli/package-lock.json
@@ -192,22 +178,20 @@ jobs:
192178
env:
193179
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
194180

195-
- name: Publish to GitHub Packages
181+
- name: Publish to GPR
196182
run: |
197183
npm pkg set name="@tech4file/cloudsync-cli"
198184
npm publish --access public
199185
env:
200186
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
201187

202-
- name: Generate checksums
188+
- name: Checksums
203189
run: |
204190
cd assets
205191
find . -type f ! -name '*.zip' ! -name '*.bat' ! -name '*.iss' ! -name '*.md' ! -name 'LICENSE' \
206192
-exec sha256sum {} \; > checksums.txt
207-
cat checksums.txt
208193
209-
- name: Create GitHub Release
210-
uses: softprops/action-gh-release@v1
194+
- uses: softprops/action-gh-release@v1
211195
with:
212196
tag_name: ${{ needs.version.outputs.tag }}
213197
name: ${{ needs.version.outputs.version }}

cloudsync-cli/.npmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ clone-test/
2222
npm-debug.log*
2323
tmp/
2424
temp/
25+
bin/pkg-launcher.cjs
26+
bin/pkg-entry.mjs
27+
scripts/
28+
dist/

cloudsync-cli/bin/pkg-entry.mjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env node
2+
/**
3+
* pkg build entry point — uses only static imports so pkg can trace all files.
4+
*/
5+
import { mkdirSync, existsSync } from 'fs';
6+
import { join } from 'path';
7+
8+
const csyncDir = join(process.cwd(), '.cloudsync');
9+
[csyncDir, join(csyncDir,'staging'), join(csyncDir,'history','commits'),
10+
join(csyncDir,'history','diffs'), join(csyncDir,'cache'), join(csyncDir,'logs')
11+
].forEach(d => { if (!existsSync(d)) mkdirSync(d, {recursive:true}); });
12+
13+
process.on('uncaughtException', (e) => { console.error('\n❌', e.message); process.exit(1); });
14+
process.on('unhandledRejection', (r) => { console.error('\n❌', r); process.exit(1); });
15+
16+
// STATIC import — pkg traces this at bundle time
17+
import '../src/cli/index.js';

cloudsync-cli/bin/pkg-launcher.cjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// pkg build launcher — pure CJS, no import.meta, no dynamic imports
2+
const { mkdirSync, existsSync } = require('fs');
3+
const { join } = require('path');
4+
5+
const csyncDir = join(process.cwd(), '.cloudsync');
6+
[csyncDir, join(csyncDir,'staging'), join(csyncDir,'history','commits'),
7+
join(csyncDir,'history','diffs'), join(csyncDir,'cache'), join(csyncDir,'logs')
8+
].forEach(d => { if (!existsSync(d)) mkdirSync(d, {recursive:true}); });
9+
10+
process.on('uncaughtException', (e) => { console.error('\n❌', e.message); process.exit(1); });
11+
process.on('unhandledRejection', (r) => { console.error('\n❌', r); process.exit(1); });
12+
13+
// esbuild inlines this during bundle — all ESM converted to CJS
14+
require('../src/cli/index.js');

0 commit comments

Comments
 (0)