5757
5858 - id : plan
5959 run : |
60+ VERSION="${{ steps.version.outputs.version }}"
61+ sed -i "s/version = \".*\"/version = \"$VERSION\"/" crates/rcoder-cli/Cargo.toml
62+
6063 dist host --steps=create --tag=${{ github.ref_name }} --output-format=json > plan-dist-manifest.json
6164 echo "dist ran successfully"
6265 cat plan-dist-manifest.json
@@ -144,6 +147,10 @@ jobs:
144147
145148 - name : Build artifacts
146149 run : |
150+ VERSION="${{ needs.plan.outputs.version }}"
151+ sed -i.bak "s/version = \".*\"/version = \"$VERSION\"/" crates/rcoder-cli/Cargo.toml
152+ rm -f crates/rcoder-cli/Cargo.toml.bak
153+
147154 dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
148155 echo "dist ran successfully"
149156
@@ -200,6 +207,9 @@ jobs:
200207 - id : cargo-dist
201208 shell : bash
202209 run : |
210+ VERSION="${{ needs.plan.outputs.version }}"
211+ sed -i "s/version = \".*\"/version = \"$VERSION\"/" crates/rcoder-cli/Cargo.toml
212+
203213 dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
204214 echo "dist ran successfully"
205215
@@ -333,31 +343,31 @@ jobs:
333343 fi
334344 done
335345
336- # 更新主包的 optionalDependencies 版本
346+ # 更新主包的 optionalDependencies 版本(平台包使用非 scoped 唯一包名)
337347 jq --arg v "$VERSION" '
338- .optionalDependencies["@ rcoder/ cli-linux-x64"] = $v |
339- .optionalDependencies["@ rcoder/ cli-linux-arm64"] = $v |
340- .optionalDependencies["@ rcoder/ cli-darwin-x64"] = $v |
341- .optionalDependencies["@ rcoder/ cli-darwin-arm64"] = $v |
342- .optionalDependencies["@ rcoder/ cli-win32 -x64"] = $v
348+ .optionalDependencies["rcoder- cli-linux-x64"] = $v |
349+ .optionalDependencies["rcoder- cli-linux-arm64"] = $v |
350+ .optionalDependencies["rcoder- cli-darwin-x64"] = $v |
351+ .optionalDependencies["rcoder- cli-darwin-arm64"] = $v |
352+ .optionalDependencies["rcoder- cli-windows -x64"] = $v
343353 ' npm/rcoder-cli/package.json > npm/rcoder-cli/package.json.tmp
344354 mv npm/rcoder-cli/package.json.tmp npm/rcoder-cli/package.json
345355
346- # 解压 Linux x64
356+ # 解压 Linux x64(tarball 带顶层目录,需 strip 1 层)
347357 mkdir -p npm/rcoder-cli-linux-x64
348- tar -xf binaries/rcoder-cli-x86_64-unknown-linux-gnu.tar.xz -C npm/rcoder-cli-linux-x64
358+ tar -xf binaries/rcoder-cli-x86_64-unknown-linux-gnu.tar.xz --strip-components=1 - C npm/rcoder-cli-linux-x64
349359
350360 # 解压 Linux arm64
351361 mkdir -p npm/rcoder-cli-linux-arm64
352- tar -xf binaries/rcoder-cli-aarch64-unknown-linux-gnu.tar.xz -C npm/rcoder-cli-linux-arm64
362+ tar -xf binaries/rcoder-cli-aarch64-unknown-linux-gnu.tar.xz --strip-components=1 - C npm/rcoder-cli-linux-arm64
353363
354364 # 解压 macOS x64
355365 mkdir -p npm/rcoder-cli-darwin-x64
356- tar -xf binaries/rcoder-cli-x86_64-apple-darwin.tar.xz -C npm/rcoder-cli-darwin-x64
366+ tar -xf binaries/rcoder-cli-x86_64-apple-darwin.tar.xz --strip-components=1 - C npm/rcoder-cli-darwin-x64
357367
358368 # 解压 macOS arm64
359369 mkdir -p npm/rcoder-cli-darwin-arm64
360- tar -xf binaries/rcoder-cli-aarch64-apple-darwin.tar.xz -C npm/rcoder-cli-darwin-arm64
370+ tar -xf binaries/rcoder-cli-aarch64-apple-darwin.tar.xz --strip-components=1 - C npm/rcoder-cli-darwin-arm64
361371
362372 # 解压 Windows x64
363373 mkdir -p npm/rcoder-cli-win32-x64
@@ -375,22 +385,39 @@ jobs:
375385 run : |
376386 npm config set //registry.npmjs.org/:_authToken ${{ secrets.NPM_TOKEN }}
377387
378- # 发布平台包
388+ failures=0
379389 for pkg in npm/rcoder-cli-*; do
380390 if [ -f "$pkg/package.json" ]; then
381391 pkgName=$(jq -r '.name' "$pkg/package.json")
382- echo "Publishing $pkgName..."
383- npm publish "$pkg" --access public --tag latest
392+ echo "Packing $pkgName..."
393+ cd "$pkg"
394+ tarball=$(npm pack 2>/dev/null)
395+ cd -
396+ echo "Publishing $pkgName with latest tag..."
397+ if ! npm publish "$pkg/$tarball" --access public --tag latest --registry https://registry.npmjs.org; then
398+ echo "ERROR: Failed to publish $pkgName"
399+ failures=$((failures+1))
400+ fi
401+ rm -f "$pkg/$tarball"
384402 fi
385403 done
404+
405+ if [ "$failures" -ne 0 ]; then
406+ echo "ERROR: $failures npm package(s) failed to publish"
407+ exit 1
408+ fi
386409 env :
387410 NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
388411
389412 # 发布主包
390413 - name : Publish main package
391414 run : |
392415 echo "Publishing rcoder-cli..."
393- npm publish npm/rcoder-cli --access public --tag latest
416+ cd npm/rcoder-cli
417+ tarball=$(npm pack 2>/dev/null)
418+ cd -
419+ npm publish "npm/rcoder-cli/$tarball" --access public --tag latest --registry https://registry.npmjs.org
420+ rm -f "npm/rcoder-cli/$tarball"
394421 env :
395422 NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
396423
0 commit comments