Skip to content

Commit fc83ade

Browse files
committed
调整npm registry
1 parent 198768c commit fc83ade

File tree

1 file changed

+79
-1
lines changed

1 file changed

+79
-1
lines changed

.github/workflows/deploy.yml

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,31 +66,45 @@ 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
8496
# run: |
8597
# cd ${{ matrix.package }}
8698
# npm ci || npm install
8799

88100
- name: Build package
101+
if: steps.check-update-all.outputs.should_skip != 'true'
89102
run: |
90103
cd ${{ matrix.package }}
91104
npm run build --if-present
92105
93106
- name: Publish to NPM
107+
if: steps.check-update-all.outputs.should_skip != 'true'
94108
env:
95109
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
96110
run: |
@@ -113,6 +127,70 @@ jobs:
113127
# 发布
114128
npm publish --access public
115129
130+
build-and-publish-all:
131+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/deploy' }}
132+
runs-on: ubuntu-latest
133+
steps:
134+
- name: Check UPDATE_ALL flag
135+
id: check-update-all
136+
run: |
137+
if [[ "${{ secrets.UPDATE_ALL }}" == "true" ]]; then
138+
echo "should_run=true" >> $GITHUB_OUTPUT
139+
else
140+
echo "should_run=false" >> $GITHUB_OUTPUT
141+
fi
142+
143+
- name: Checkout code
144+
if: steps.check-update-all.outputs.should_run == 'true'
145+
uses: actions/checkout@v3
146+
with:
147+
token: ${{ secrets.GHB_TOKEN }}
148+
149+
- name: Setup Node.js
150+
if: steps.check-update-all.outputs.should_run == 'true'
151+
uses: actions/setup-node@v3
152+
with:
153+
node-version: '18'
154+
registry-url: ${{ secrets.REGISTRY_URL }}
155+
156+
- name: Publish to NPM
157+
if: steps.check-update-all.outputs.should_run == 'true'
158+
env:
159+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
160+
run: |
161+
PACKAGE_DIRS=$(find . -name "package.json" -not -path "*/node_modules/*" -not -path "./package.json" -exec dirname {} \; | sed 's/^\.\///')
162+
echo "Found packages: $PACKAGE_DIRS"
163+
# 仅保留一级目录
164+
FIRST_LEVEL_DIRS=()
165+
for dir in $PACKAGE_DIRS; do
166+
if [[ "$dir" != *"/"* ]]; then
167+
FIRST_LEVEL_DIRS+=("$dir")
168+
fi
169+
done
170+
171+
echo "要发布的一级目录包: ${FIRST_LEVEL_DIRS[*]}"
172+
173+
for dir in "${FIRST_LEVEL_DIRS[@]}"; do
174+
if [ ! -d "$dir" ]; then
175+
echo "目录 $dir 不存在,跳过..."
176+
continue
177+
fi
178+
cd $dir
179+
echo "发布 $dir"
180+
CURRENT_VERSION=$(node -p "require('./package.json').version")
181+
PACKAGE_NAME=$(node -p "require('./package.json').name")
182+
echo "当前版本: $CURRENT_VERSION"
183+
184+
if npm view $PACKAGE_NAME@$CURRENT_VERSION version &> /dev/null; then
185+
echo "版本 $CURRENT_VERSION 已存在,尝试取消发布..."
186+
npm unpublish $PACKAGE_NAME@$CURRENT_VERSION --force
187+
fi
188+
189+
sleep 5
190+
npm publish --access public
191+
cd ..
192+
done
193+
116194
update-last-deploy-tag:
117195
runs-on: ubuntu-latest
118196

0 commit comments

Comments
 (0)