@@ -2,28 +2,179 @@ name: Publish NPM packages
22
33on :
44 workflow_call :
5+ secrets :
6+ NPM_TOKEN :
7+ required : true
58 workflow_dispatch :
69
710jobs :
811 publish :
912 runs-on : ubuntu-latest
10-
1113 steps :
1214 - uses : actions/checkout@v4
1315
14- - name : Download binaries
16+ - name : Set version
17+ run : |
18+ VERSION="${GITHUB_REF#refs/tags/v}"
19+ if [[ "$VERSION" == "$GITHUB_REF" ]]; then
20+ VERSION="0.0.0-dev" # for non-tag runs
21+ fi
22+ echo "VERSION=$VERSION" >> $GITHUB_ENV
23+
24+ - name : Download all binary artifacts
1525 uses : actions/download-artifact@v4
1626 with :
1727 pattern : binary-*
18- merge-multiple : false
28+ path : binaries
29+
30+ - name : Setup Node.js
31+ uses : actions/setup-node@v4
32+ with :
33+ node-version : ' 18'
34+ registry-url : ' https://registry.npmjs.org'
1935
20- - name : Build platform packages
21- run : ./scripts/build-platform-npm.sh
36+ - name : Publish platform-specific packages
37+ run : |
38+ cd binaries
39+ for artifact in binary-*; do
40+ if [ ! -d "$artifact" ]; then continue; fi
2241
23- - name : Build unified package
24- run : ./scripts/build-unified-npm.sh
42+ # Map artifact name to npm pkg name & metadata
43+ case "$artifact" in
44+ binary-linux-x64-glibc)
45+ PKG_NAME="gitcraft-linux-x64"
46+ OS="linux"; CPU="x64"
47+ BINARY="gitcraft"
48+ ;;
49+ binary-linux-arm64-glibc)
50+ PKG_NAME="gitcraft-linux-arm64"
51+ OS="linux"; CPU="arm64"
52+ BINARY="gitcraft"
53+ ;;
54+ binary-darwin-x64)
55+ PKG_NAME="gitcraft-darwin-x64"
56+ OS="darwin"; CPU="x64"
57+ BINARY="gitcraft"
58+ ;;
59+ binary-darwin-arm64)
60+ PKG_NAME="gitcraft-darwin-arm64"
61+ OS="darwin"; CPU="arm64"
62+ BINARY="gitcraft"
63+ ;;
64+ binary-windows-x64-msvc)
65+ PKG_NAME="gitcraft-windows-x64"
66+ OS="win32"; CPU="x64"
67+ BINARY="gitcraft.exe"
68+ ;;
69+ *)
70+ echo "Skipping unsupported artifact: $artifact"
71+ continue
72+ ;;
73+ esac
2574
26- - name : Publish
27- run : ./scripts/publish-npm.sh
75+ # Create npm package dir
76+ mkdir -p "../npm-pkgs/$PKG_NAME/bin"
77+ cp "$artifact/$BINARY" "../npm-pkgs/$PKG_NAME/bin/"
78+
79+ # Make binary executable (non-Windows)
80+ if [[ "$OS" != "win32" ]]; then
81+ chmod +x "../npm-pkgs/$PKG_NAME/bin/$BINARY"
82+ fi
83+
84+ # Write package.json
85+ cat > "../npm-pkgs/$PKG_NAME/package.json" << EOF
86+ {
87+ " name " : " $PKG_NAME" ,
88+ " version " : " ${{ env.VERSION }}" ,
89+ " os " : ["$OS"],
90+ " cpu " : ["$CPU"],
91+ " bin " : {
92+ " gitcraft " : " ./bin/$BINARY"
93+ },
94+ " files " : ["bin/"],
95+ " license " : " Apache-2.0" ,
96+ " description " : " Prebuilt gitcraft binary for $OS/$CPU"
97+ }
98+ EOF
99+
100+ # Publish package
101+ cd "../npm-pkgs/$PKG_NAME"
102+ npm publish --access public
103+ cd ../../..
104+ done
28105 env :
29106 NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
107+
108+ - name : Create and publish unified package
109+ run : |
110+ mkdir -p gitcraft-unified/bin
111+
112+ # Create the smart JavaScript wrapper
113+ cat > gitcraft-unified/bin/gitcraft.js << 'EOF'
114+ # !/usr/bin/env node
115+ const os = require('os');
116+ const child_process = require('child_process');
117+ const path = require('path');
118+
119+ const platform = os.platform();
120+ const arch = os.arch();
121+
122+ let pkg;
123+ if (platform === 'linux' && arch === 'arm64') {
124+ pkg = 'gitcraft-linux-arm64';
125+ } else if (platform === 'linux' && arch === 'x64') {
126+ pkg = 'gitcraft-linux-x64';
127+ } else if (platform === 'darwin' && arch === 'arm64') {
128+ pkg = 'gitcraft-darwin-arm64';
129+ } else if (platform === 'darwin' && arch === 'x64') {
130+ pkg = 'gitcraft-darwin-x64';
131+ } else if (platform === 'win32' && arch === 'x64') {
132+ pkg = 'gitcraft-windows-x64';
133+ } else {
134+ console.error(`Unsupported platform : ${platform} ${arch}`);
135+ process.exit(1);
136+ }
137+
138+ try {
139+ const pkgPath = require.resolve(`${pkg}/package.json`);
140+ const binName = platform === 'win32' ? 'gitcraft.exe' : ' gitcraft' ;
141+ const binPath = path.join(path.dirname(pkgPath), 'bin', binName);
142+ child_process.execFileSync(binPath, process.argv.slice(2), { stdio : ' inherit' });
143+ } catch (e) {
144+ console.error(`Platform-specific package not installed : ${pkg}`);
145+ console.error(`Try : npm install -g ${pkg}`);
146+ process.exit(1);
147+ }
148+ EOF
149+
150+ chmod +x gitcraft-unified/bin/gitcraft.js
151+
152+ # Create package.json for unified package
153+ cat > gitcraft-unified/package.json << EOF
154+ {
155+ " name " : " gitcraft" ,
156+ " version " : " ${{ env.VERSION }}" ,
157+ " description " : " A CLI tool for GitHub-related utilities" ,
158+ " bin " : {
159+ " gitcraft " : " ./bin/gitcraft.js"
160+ },
161+ " files " : ["bin/"],
162+ " license " : " Apache-2.0" ,
163+ " optionalDependencies " : {
164+ " gitcraft-linux-x64 " : " ${{ env.VERSION }}" ,
165+ " gitcraft-linux-arm64 " : " ${{ env.VERSION }}" ,
166+ " gitcraft-darwin-x64 " : " ${{ env.VERSION }}" ,
167+ " gitcraft-darwin-arm64 " : " ${{ env.VERSION }}" ,
168+ " gitcraft-windows-x64 " : " ${{ env.VERSION }}"
169+ },
170+ " engines " : {
171+ " node " : " >=14"
172+ }
173+ }
174+ EOF
175+
176+ # Publish unified package
177+ cd gitcraft-unified
178+ npm publish --access public
179+ env :
180+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
0 commit comments