Skip to content

Commit 44d04c9

Browse files
authored
chore: do not attempt npm publish when package already exists (#1658)
1 parent 923182d commit 44d04c9

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

.github/workflows/publish.yml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,26 @@ jobs:
2828
- name: Build npm
2929
run: deno task build
3030
- name: Publish npm
31-
run: |
32-
(cd packages/common && npm publish --provenance --access public)
33-
(cd packages/bootstrap && npm publish --provenance --access public)
34-
(cd packages/ts-morph && npm publish --provenance --access public)
3531
env:
3632
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
33+
shell: bash
34+
run: |
35+
set -euo pipefail
36+
publish_if_needed() {
37+
local pkg_dir=$1
38+
cd "$pkg_dir"
39+
local name version
40+
name=$(node -p "require('./package.json').name")
41+
version=$(node -p "require('./package.json').version")
42+
if npm view "$name@$version" >/dev/null 2>&1; then
43+
echo "✅ $name@$version already published — skipping."
44+
else
45+
echo "🚀 Publishing $name@$version..."
46+
npm publish --provenance --access public
47+
fi
48+
cd - >/dev/null
49+
}
50+
51+
publish_if_needed packages/common
52+
publish_if_needed packages/bootstrap
53+
publish_if_needed packages/ts-morph

0 commit comments

Comments
 (0)