Skip to content

Commit 2fd384c

Browse files
committed
改进
1 parent 81360e6 commit 2fd384c

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

.github/workflows/deploy.yml

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,21 @@ jobs:
3333
3434
echo "Comparing $BASE_SHA...$HEAD_SHA"
3535
36+
# 查找含 package.json 的目录
3637
PACKAGE_DIRS=$(find . -name "package.json" -not -path "*/node_modules/*" -not -path "./package.json" -exec dirname {} \; | sed 's/^\.\///')
3738
39+
# 查找含 webp 文件但无 package.json 的一级目录
40+
WEBP_DIRS=$(find . -maxdepth 2 -name "*.webp" -not -path "*/node_modules/*" -not -path "*/\.*/*" -exec dirname {} \; | sed 's/^\.\///' | sort -u)
41+
42+
# 合并去重
43+
ALL_DIRS=$(echo -e "$PACKAGE_DIRS\n$WEBP_DIRS" | sort -u)
44+
3845
CHANGED_PACKAGES=()
3946
40-
for dir in $PACKAGE_DIRS; do
47+
for dir in $ALL_DIRS; do
48+
if [ -z "$dir" ] || [ "$dir" = "." ]; then
49+
continue
50+
fi
4151
if git diff --quiet --diff-filter=ACMRT $BASE_SHA $HEAD_SHA -- "$dir"; then
4252
echo "No changes in $dir"
4353
else
@@ -97,14 +107,25 @@ jobs:
97107
# cd ${{ matrix.package }}
98108
# npm ci || npm install
99109

100-
- name: Build package
110+
- name: Check package.json exists
111+
id: check-pkg
101112
if: steps.check-update-all.outputs.should_skip != 'true'
113+
run: |
114+
if [ -f "${{ matrix.package }}/package.json" ]; then
115+
echo "has_package=true" >> $GITHUB_OUTPUT
116+
else
117+
echo "No package.json in ${{ matrix.package }}, skipping npm steps"
118+
echo "has_package=false" >> $GITHUB_OUTPUT
119+
fi
120+
121+
- name: Build package
122+
if: steps.check-update-all.outputs.should_skip != 'true' && steps.check-pkg.outputs.has_package == 'true'
102123
run: |
103124
cd ${{ matrix.package }}
104125
npm run build --if-present
105126
106127
- name: Publish to Registry 2
107-
if: steps.check-update-all.outputs.should_skip != 'true'
128+
if: steps.check-update-all.outputs.should_skip != 'true' && steps.check-pkg.outputs.has_package == 'true'
108129
env:
109130
REGISTRY_2: ${{ secrets.REGISTRY_URL_2 }}
110131
TOKEN_2: ${{ secrets.NPM_TOKEN_2 }}
@@ -146,7 +167,7 @@ jobs:
146167
rm .npmrc
147168
148169
- name: Publish to Default Registry
149-
if: steps.check-update-all.outputs.should_skip != 'true'
170+
if: steps.check-update-all.outputs.should_skip != 'true' && steps.check-pkg.outputs.has_package == 'true'
150171
env:
151172
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
152173
run: |

0 commit comments

Comments
 (0)