Skip to content

Commit 6d03616

Browse files
ci: workflow and build script improvements for macOS and Yarn 4.12.0 support
- Set up robust GitHub Actions workflow with XDG_CACHE_HOME for consistent caching - Clean electron-output before builds to prevent corruption - Use yarn exec for proper Yarn workspace binary resolution - Fix workflow conditional syntax for secrets checks - Update packageManager to yarn@4.12.0 in package.json - Add prep-build-binary.cjs wrapper script with fallback logic (npx → yarn exec → local)
1 parent eaeb0ac commit 6d03616

4 files changed

Lines changed: 132 additions & 1 deletion

File tree

.github/workflows/node.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ jobs:
3535
run: |
3636
corepack enable
3737
38+
# set isolated electron-builder cache early so downloads use it
39+
echo "XDG_CACHE_HOME=${{ runner.temp }}/electron-builder-cache-${{ github.run_id }}"
40+
export XDG_CACHE_HOME=${{ runner.temp }}/electron-builder-cache-${{ github.run_id }}
41+
rm -rf "$XDG_CACHE_HOME/electron-builder" || true
42+
mkdir -p "$XDG_CACHE_HOME"
43+
3844
# try and avoid timeout errors
3945
yarn config set httpTimeout 100000
4046
@@ -69,14 +75,37 @@ jobs:
6975
run: |
7076
corepack enable
7177
78+
# set isolated electron-builder cache early so downloads use it
79+
echo "XDG_CACHE_HOME=${{ runner.temp }}/electron-builder-cache-${{ github.run_id }}" >> $GITHUB_ENV
80+
export XDG_CACHE_HOME=${{ runner.temp }}/electron-builder-cache-${{ github.run_id }}
81+
rm -rf "$XDG_CACHE_HOME/electron-builder" || true
82+
mkdir -p "$XDG_CACHE_HOME"
83+
7284
# try and avoid timeout errors
7385
yarn config set httpTimeout 100000
7486
7587
yarn --immutable
7688
- name: Build
7789
run: |
7890
yarn build
91+
- name: macOS pre-build diagnostics
92+
run: |
93+
echo "XDG_CACHE_HOME=${{ runner.temp }}/electron-builder-cache-${{ github.run_id }}"
94+
export XDG_CACHE_HOME=${{ runner.temp }}/electron-builder-cache-${{ github.run_id }}
95+
# ensure isolated cache and remove any partially-downloaded files
96+
rm -rf "$XDG_CACHE_HOME/electron-builder" || true
97+
mkdir -p "$XDG_CACHE_HOME"
98+
echo 'Listing workspace paths for tsr-bridge'
99+
ls -la apps/tsr-bridge || true
100+
ls -la apps/tsr-bridge/dist || true
101+
ls -la apps/tsr-bridge/resources || true
102+
ls -la apps/tsr-bridge/electron-output || true
103+
echo 'package.json for tsr-bridge:'
104+
sed -n '1,200p' apps/tsr-bridge/package.json || true
105+
- name: Set signing secret
106+
run: echo "HAS_MAC_CSC_LINK=${{ secrets.MAC_CSC_LINK != '' }}" >> $GITHUB_ENV
79107
- name: Build binaries
108+
if: env.HAS_MAC_CSC_LINK == 'true'
80109
run: |
81110
yarn build:binary -- --publish=never
82111
env:
@@ -85,6 +114,25 @@ jobs:
85114
APPLEID: ${{ secrets.APPLEID }}
86115
APPLEIDTEAM: ${{ secrets.APPLEIDTEAM }}
87116
APPLEIDPASS: ${{ secrets.APPLEIDPASS }}
117+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
118+
XDG_CACHE_HOME: ${{ runner.temp }}/electron-builder-cache-${{ github.run_id }}
119+
- name: Collect builder configs
120+
run: |
121+
mkdir -p macos-diagnostics
122+
# collect any builder effective config files and directory listings
123+
if [ -f apps/tsr-bridge/builder-effective-config.yaml ]; then cp apps/tsr-bridge/builder-effective-config.yaml macos-diagnostics/ || true; fi
124+
if [ -f apps/app/builder-effective-config.yaml ]; then cp apps/app/builder-effective-config.yaml macos-diagnostics/ || true; fi
125+
if compgen -G "apps/tsr-bridge/electron-output/*" > /dev/null; then ls -la apps/tsr-bridge/electron-output > macos-diagnostics/tsr-bridge-electron-output.txt || true; fi
126+
if compgen -G "apps/app/electron-output/*" > /dev/null; then ls -la apps/app/electron-output > macos-diagnostics/app-electron-output.txt || true; fi
127+
ls -la apps/tsr-bridge >> macos-diagnostics/tsr-bridge-root-listing.txt || true
128+
ls -la apps/app >> macos-diagnostics/app-root-listing.txt || true
129+
- name: Upload macOS diagnostics
130+
uses: actions/upload-artifact@v4
131+
with:
132+
name: macos-diagnostics
133+
path: macos-diagnostics
134+
retention-days: 1
135+
>>>>>>> 2d3a53f3 (ci: workflow and build script improvements for macOS and Yarn 4.12.0 support)
88136
- name: Collect binaries
89137
run: |
90138
mkdir macos-dist
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# CI test trigger

apps/tsr-bridge/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
},
1111
"scripts": {
1212
"build": "vite build",
13-
"build:binary": "electron-builder",
13+
"clean:electron-output": "rm -rf electron-output",
14+
"build:binary": "yarn clean:electron-output && node ./scripts/prep-build-binary.cjs",
1415
"start": "yarn build && electron dist/main.mjs",
1516
"react:dev": "vite",
1617
"electron:dev": "nodemon",
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/* eslint-disable @typescript-eslint/no-require-imports */
2+
/* eslint-disable no-console */
3+
const { spawnSync } = require('child_process')
4+
const fs = require('fs')
5+
const path = require('path')
6+
7+
function exists(p) {
8+
try {
9+
return fs.existsSync(p)
10+
} catch {
11+
return false
12+
}
13+
}
14+
15+
const cwd = process.cwd()
16+
const distDir = path.join(cwd, 'dist')
17+
const buildResources = path.join(cwd, 'resources')
18+
const electronOutput = path.join(cwd, 'electron-output')
19+
20+
console.log('prep-build-binary: cwd=', cwd)
21+
console.log('prep-build-binary: checking paths:')
22+
console.log(' - dist exists:', exists(distDir), distDir)
23+
console.log(' - resources exists:', exists(buildResources), buildResources)
24+
console.log(' - electron-output exists:', exists(electronOutput), electronOutput)
25+
26+
if (!exists(distDir)) {
27+
console.warn('prep-build-binary: WARNING: dist/ directory missing. Run `yarn workspace tsr-bridge build` first.')
28+
}
29+
30+
// Print a short listing to help CI debug
31+
function list(dir) {
32+
if (!exists(dir)) return
33+
console.log('\nListing ' + dir)
34+
try {
35+
const items = fs.readdirSync(dir)
36+
for (const it of items.slice(0, 200)) {
37+
const p = path.join(dir, it)
38+
const st = fs.statSync(p)
39+
console.log(`${st.isDirectory() ? 'd' : '-'} ${st.size.toString().padStart(8)} ${it}`)
40+
}
41+
} catch (err) {
42+
console.error('Error listing', dir, err && err.stack ? err.stack : err)
43+
}
44+
}
45+
46+
list(cwd)
47+
list(distDir)
48+
list(buildResources)
49+
50+
// Forward args to electron-builder
51+
const args = process.argv.slice(2)
52+
console.log('\nRunning electron-builder with args:', args.join(' '))
53+
54+
// Try running electron-builder via available runner: prefer npx, fall back to yarn
55+
// Run electron-builder via a shell fallback chain so missing binaries don't
56+
// cause spawnSync to throw ENOENT on Windows/CI. Try `npx`, then `yarn exec`, then
57+
// the local `node_modules/.bin/electron-builder`.
58+
const cmdParts = []
59+
const quotedArgs = args.map((a) => {
60+
if (/\s/.test(a)) return '"' + a.replace(/"/g, '\\"') + '"'
61+
return a
62+
})
63+
const argString = quotedArgs.join(' ')
64+
cmdParts.push(`npx electron-builder ${argString}`)
65+
cmdParts.push(`yarn exec electron-builder ${argString}`)
66+
cmdParts.push(`node ./node_modules/.bin/electron-builder ${argString}`)
67+
const shellCmd = cmdParts.join(' || ')
68+
69+
const shellRes = spawnSync(shellCmd, { stdio: 'inherit', shell: true })
70+
if (shellRes && shellRes.error) {
71+
console.error('prep-build-binary: spawn error', shellRes.error)
72+
// eslint-disable-next-line n/no-process-exit
73+
process.exit(1)
74+
}
75+
if (typeof shellRes.status === 'number' && shellRes.status !== 0) {
76+
console.error('prep-build-binary: electron-builder exited with code', shellRes.status)
77+
// eslint-disable-next-line n/no-process-exit
78+
process.exit(shellRes.status)
79+
}
80+
// eslint-disable-next-line n/no-process-exit
81+
process.exit(0)

0 commit comments

Comments
 (0)