Skip to content

Commit 4d4bfb1

Browse files
Add npm publish to release workflow
On git tag push (v*), builds Go binaries for all 4 platforms, creates GitHub release, then publishes 6 npm packages: @lightshell/{darwin-arm64,darwin-x64,linux-arm64,linux-x64}, lightshell, and create-lightshell. Version derived from tag.
1 parent 8d8edbf commit 4d4bfb1

3 files changed

Lines changed: 190 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,22 @@ jobs:
1717
goos: darwin
1818
goarch: arm64
1919
artifact: lightshell-darwin-arm64
20+
npm_pkg: darwin-arm64
2021
- os: macos-latest
2122
goos: darwin
2223
goarch: amd64
2324
artifact: lightshell-darwin-amd64
25+
npm_pkg: darwin-x64
2426
- os: ubuntu-latest
2527
goos: linux
2628
goarch: amd64
2729
artifact: lightshell-linux-amd64
30+
npm_pkg: linux-x64
2831
- os: ubuntu-latest
2932
goos: linux
3033
goarch: arm64
3134
artifact: lightshell-linux-arm64
35+
npm_pkg: linux-arm64
3236

3337
runs-on: ${{ matrix.os }}
3438

@@ -95,3 +99,110 @@ jobs:
9599
with:
96100
generate_release_notes: true
97101
files: release/*.tar.gz
102+
103+
publish-npm:
104+
needs: build
105+
runs-on: ubuntu-latest
106+
107+
steps:
108+
- uses: actions/checkout@v4
109+
110+
- uses: actions/setup-node@v4
111+
with:
112+
node-version: 20
113+
registry-url: https://registry.npmjs.org
114+
115+
- name: Download all artifacts
116+
uses: actions/download-artifact@v4
117+
with:
118+
path: artifacts
119+
120+
- name: Get version from tag
121+
id: version
122+
run: echo "VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
123+
124+
- name: Publish platform packages
125+
env:
126+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
127+
run: |
128+
VERSION=${{ steps.version.outputs.VERSION }}
129+
130+
declare -A BINARIES
131+
BINARIES[darwin-arm64]=lightshell-darwin-arm64
132+
BINARIES[darwin-x64]=lightshell-darwin-amd64
133+
BINARIES[linux-x64]=lightshell-linux-amd64
134+
BINARIES[linux-arm64]=lightshell-linux-arm64
135+
136+
declare -A OS_FIELD
137+
OS_FIELD[darwin-arm64]=darwin
138+
OS_FIELD[darwin-x64]=darwin
139+
OS_FIELD[linux-x64]=linux
140+
OS_FIELD[linux-arm64]=linux
141+
142+
declare -A CPU_FIELD
143+
CPU_FIELD[darwin-arm64]=arm64
144+
CPU_FIELD[darwin-x64]=x64
145+
CPU_FIELD[linux-x64]=x64
146+
CPU_FIELD[linux-arm64]=arm64
147+
148+
for PLATFORM in darwin-arm64 darwin-x64 linux-x64 linux-arm64; do
149+
ARTIFACT=${BINARIES[$PLATFORM]}
150+
PKG_DIR=$(mktemp -d)
151+
152+
cat > "$PKG_DIR/package.json" <<PKGJSON
153+
{
154+
"name": "@lightshell/${PLATFORM}",
155+
"version": "${VERSION}",
156+
"description": "LightShell binary for ${PLATFORM}",
157+
"license": "MIT",
158+
"repository": {
159+
"type": "git",
160+
"url": "https://github.com/meherpanguluri/lightshell"
161+
},
162+
"os": ["${OS_FIELD[$PLATFORM]}"],
163+
"cpu": ["${CPU_FIELD[$PLATFORM]}"],
164+
"files": ["lightshell"]
165+
}
166+
PKGJSON
167+
168+
cp "artifacts/${ARTIFACT}/${ARTIFACT}" "$PKG_DIR/lightshell"
169+
chmod +x "$PKG_DIR/lightshell"
170+
171+
echo "Publishing @lightshell/${PLATFORM}@${VERSION}"
172+
cd "$PKG_DIR" && npm publish --access public || true
173+
cd -
174+
done
175+
176+
- name: Publish main lightshell package
177+
env:
178+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
179+
run: |
180+
VERSION=${{ steps.version.outputs.VERSION }}
181+
cd npm/lightshell
182+
183+
# Update version and optional dependency versions
184+
node -e "
185+
const pkg = require('./package.json');
186+
pkg.version = '${VERSION}';
187+
for (const dep of Object.keys(pkg.optionalDependencies || {})) {
188+
pkg.optionalDependencies[dep] = '${VERSION}';
189+
}
190+
require('fs').writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
191+
"
192+
193+
npm publish --access public
194+
195+
- name: Publish create-lightshell package
196+
env:
197+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
198+
run: |
199+
VERSION=${{ steps.version.outputs.VERSION }}
200+
cd npm/create-lightshell
201+
202+
node -e "
203+
const pkg = require('./package.json');
204+
pkg.version = '${VERSION}';
205+
require('fs').writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
206+
"
207+
208+
npm publish --access public

npm/lightshell/install.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env node
2+
3+
// Postinstall script: copy the platform-specific binary to bin/
4+
const { platform, arch } = process;
5+
const path = require("path");
6+
const fs = require("fs");
7+
8+
const platformMap = {
9+
darwin: "darwin",
10+
linux: "linux",
11+
};
12+
13+
const archMap = {
14+
arm64: "arm64",
15+
x64: "x64",
16+
x86_64: "x64",
17+
};
18+
19+
const os = platformMap[platform];
20+
const cpu = archMap[arch];
21+
22+
if (!os || !cpu) {
23+
console.error(
24+
`lightshell: unsupported platform ${platform}-${arch}. Only macOS and Linux (arm64, x64) are supported.`
25+
);
26+
process.exit(1);
27+
}
28+
29+
const pkgName = `@lightshell/${os}-${cpu}`;
30+
31+
let binaryPath;
32+
try {
33+
binaryPath = require.resolve(`${pkgName}/lightshell`);
34+
} catch {
35+
console.error(
36+
`lightshell: could not find ${pkgName}. Make sure optional dependencies are installed.\n` +
37+
`Try: npm install --include=optional`
38+
);
39+
process.exit(1);
40+
}
41+
42+
const binDir = path.join(__dirname, "bin");
43+
const dest = path.join(binDir, "lightshell");
44+
45+
try {
46+
fs.mkdirSync(binDir, { recursive: true });
47+
fs.copyFileSync(binaryPath, dest);
48+
fs.chmodSync(dest, 0o755);
49+
} catch (err) {
50+
console.error(`lightshell: failed to install binary: ${err.message}`);
51+
process.exit(1);
52+
}

npm/lightshell/package.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "lightshell",
3+
"version": "0.1.0",
4+
"description": "Build desktop apps with JavaScript. Ship them under 5MB.",
5+
"keywords": ["desktop", "app", "framework", "webview", "native", "macos", "linux"],
6+
"license": "MIT",
7+
"repository": {
8+
"type": "git",
9+
"url": "https://github.com/meherpanguluri/lightshell"
10+
},
11+
"homepage": "https://lightshell.sh",
12+
"bin": {
13+
"lightshell": "bin/lightshell"
14+
},
15+
"scripts": {
16+
"postinstall": "node install.js"
17+
},
18+
"optionalDependencies": {
19+
"@lightshell/darwin-arm64": "0.1.0",
20+
"@lightshell/darwin-x64": "0.1.0",
21+
"@lightshell/linux-arm64": "0.1.0",
22+
"@lightshell/linux-x64": "0.1.0"
23+
},
24+
"engines": {
25+
"node": ">=16"
26+
}
27+
}

0 commit comments

Comments
 (0)