Skip to content

Commit e44df07

Browse files
committed
更新npm registry
1 parent a61c9f5 commit e44df07

File tree

1 file changed

+81
-1
lines changed

1 file changed

+81
-1
lines changed

.github/workflows/deploy.yml

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,37 +66,53 @@ jobs:
6666
matrix: ${{ fromJson(needs.detect-changes.outputs.matrix) }}
6767
fail-fast: false
6868
steps:
69+
- name: Check UPDATE_ALL flag
70+
id: check-update-all
71+
run: |
72+
if [[ "${{ secrets.UPDATE_ALL }}" == "true" ]]; then
73+
echo "should_skip=true" >> $GITHUB_OUTPUT
74+
else
75+
echo "should_skip=false" >> $GITHUB_OUTPUT
76+
fi
77+
6978
- name: echo matrix
79+
if: steps.check-update-all.outputs.should_skip != 'true'
7080
run: echo "${{ toJson(matrix) }}"
7181

7282
- name: Checkout code
83+
if: steps.check-update-all.outputs.should_skip != 'true'
7384
uses: actions/checkout@v3
7485
with:
7586
token: ${{ secrets.GHB_TOKEN }}
7687

7788
- name: Setup Node.js
89+
if: steps.check-update-all.outputs.should_skip != 'true'
7890
uses: actions/setup-node@v3
7991
with:
8092
node-version: '18'
81-
registry-url: 'https://registry.openjumper.cn'
93+
registry-url: ${{ secrets.REGISTRY_URL }}
8294

8395
- name: Install dependencies
96+
if: steps.check-update-all.outputs.should_skip != 'true'
8497
run: |
8598
cd ${{ matrix.package }}
8699
npm ci || npm install
87100
88101
- name: 配置 npm
102+
if: steps.check-update-all.outputs.should_skip != 'true'
89103
run: |
90104
npm config set fetch-timeout 600000
91105
npm config set fetch-retry-mintimeout 20000
92106
npm config set fetch-retry-maxtimeout 120000
93107
94108
- name: Build package
109+
if: steps.check-update-all.outputs.should_skip != 'true'
95110
run: |
96111
cd ${{ matrix.package }}
97112
npm run build --if-present
98113
99114
- name: Publish to NPM
115+
if: steps.check-update-all.outputs.should_skip != 'true'
100116
env:
101117
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
102118
run: |
@@ -119,6 +135,70 @@ jobs:
119135
# 发布
120136
npm publish --access public
121137
138+
build-and-publish-all:
139+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/deploy' }}
140+
runs-on: ubuntu-latest
141+
steps:
142+
- name: Check UPDATE_ALL flag
143+
id: check-update-all
144+
run: |
145+
if [[ "${{ secrets.UPDATE_ALL }}" == "true" ]]; then
146+
echo "should_run=true" >> $GITHUB_OUTPUT
147+
else
148+
echo "should_run=false" >> $GITHUB_OUTPUT
149+
fi
150+
151+
- name: Checkout code
152+
if: steps.check-update-all.outputs.should_run == 'true'
153+
uses: actions/checkout@v3
154+
with:
155+
token: ${{ secrets.GHB_TOKEN }}
156+
157+
- name: Setup Node.js
158+
if: steps.check-update-all.outputs.should_run == 'true'
159+
uses: actions/setup-node@v3
160+
with:
161+
node-version: '18'
162+
registry-url: ${{ secrets.REGISTRY_URL }}
163+
164+
- name: Publish to NPM
165+
if: steps.check-update-all.outputs.should_run == 'true'
166+
env:
167+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
168+
run: |
169+
PACKAGE_DIRS=$(find . -name "package.json" -not -path "*/node_modules/*" -not -path "./package.json" -exec dirname {} \; | sed 's/^\.\///')
170+
echo "Found packages: $PACKAGE_DIRS"
171+
# 仅保留一级目录
172+
FIRST_LEVEL_DIRS=()
173+
for dir in $PACKAGE_DIRS; do
174+
if [[ "$dir" != *"/"* ]]; then
175+
FIRST_LEVEL_DIRS+=("$dir")
176+
fi
177+
done
178+
179+
echo "要发布的一级目录包: ${FIRST_LEVEL_DIRS[*]}"
180+
181+
for dir in "${FIRST_LEVEL_DIRS[@]}"; do
182+
if [ ! -d "$dir" ]; then
183+
echo "目录 $dir 不存在,跳过..."
184+
continue
185+
fi
186+
cd $dir
187+
echo "发布 $dir"
188+
CURRENT_VERSION=$(node -p "require('./package.json').version")
189+
PACKAGE_NAME=$(node -p "require('./package.json').name")
190+
echo "当前版本: $CURRENT_VERSION"
191+
192+
if npm view $PACKAGE_NAME@$CURRENT_VERSION version &> /dev/null; then
193+
echo "版本 $CURRENT_VERSION 已存在,尝试取消发布..."
194+
npm unpublish $PACKAGE_NAME@$CURRENT_VERSION --force
195+
fi
196+
197+
sleep 5
198+
npm publish --access public
199+
cd ..
200+
done
201+
122202
update-last-deploy-tag:
123203
needs: [detect-changes, build-and-publish]
124204
# 当build-and-publish成功运行时,或者当没有变更需要发布时运行

0 commit comments

Comments
 (0)