@@ -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
0 commit comments