-
Notifications
You must be signed in to change notification settings - Fork 4.9k
427 lines (381 loc) · 14.8 KB
/
publish.yml
File metadata and controls
427 lines (381 loc) · 14.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
name: publish
on:
push:
branches:
- 'chore/**'
- 'feat/**'
- 'fix/**'
- '1.x'
- '2.x'
- '3.x'
- '4.x'
# When Release Pull Request is merged
pull_request:
branches:
- main
types: [closed]
jobs:
need-publish:
permissions:
actions: write # to cancel running workflow (andymckay/cancel-action)
name: Need Publish
runs-on: ubuntu-latest
outputs:
ABORT: ${{ env.ABORT }}
env:
ABORT: false
COMMIT_MESSAGE: ''
steps:
# Setup
- name: Checkout
uses: actions/checkout@v5
# Log meta
- name: GITHUB CONTEXT
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
# Get commit message
- name: Get commit message
run: |
COMMIT_MESSAGE=$(git log --format=%s -n 1)
echo "COMMIT_MESSAGE=${COMMIT_MESSAGE}" >> $GITHUB_ENV
- name: Show commit message
run: echo "$COMMIT_MESSAGE"
- name: Determine if should abort publish
run: |
ABORT=false
if [[ "${{ env.COMMIT_MESSAGE }}" == *"--skip"* ]]; then
echo "Found --skip flag, aborting publish"
ABORT=true
elif [[ "${{ env.COMMIT_MESSAGE }}" != "chore(release):"* ]]; then
echo "Not a release commit"
ABORT=${{ !env.MOCK_PUBLISH }}
elif [[ "${{ github.event_name }}" == "push" && "${{ env.COMMIT_MESSAGE }}" != *"--tag="* ]]; then
echo "Push event without tag"
ABORT=${{ !env.MOCK_PUBLISH }}
fi
echo "ABORT=$ABORT" >> $GITHUB_ENV
echo "Final ABORT value: $ABORT"
build-rust-binding:
name: Build Rust Binding
needs: [need-publish]
if: needs.need-publish.outputs.ABORT != 'true'
uses: ./.github/workflows/build-rust-binding.yml
build-rust-wasm:
name: Build Rust WASM
needs: [need-publish]
if: needs.need-publish.outputs.ABORT != 'true'
uses: ./.github/workflows/build-rust-wasm.yml
publish:
permissions:
contents: write # to create tags and refs
actions: write # to cancel running workflow (andymckay/cancel-action)
issues: write # to create comment
pull-requests: write # to create comment and so on
name: Publish
runs-on: ubuntu-latest
needs: [need-publish, build-rust-binding, build-rust-wasm]
if: needs.need-publish.outputs.ABORT != 'true'
env:
CURRENT_VERSION: ''
PUBLISH_PARAMS: ''
steps:
# Setup
- name: Checkout
uses: actions/checkout@v5
with:
ref: ${{ github.ref_name }}
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10
- name: Setup Node 18
uses: actions/setup-node@v6
with:
node-version: 18
cache: 'pnpm'
registry-url: 'https://registry.npmjs.org' # Don't touch!
- name: Git Identity
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/$GITHUB_REPOSITORY
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Log meta
- name: GITHUB CONTEXT
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
# Get commit message
- name: Get commit message
run: |
COMMIT_MESSAGE=$(git log --format=%s -n 1)
echo "COMMIT_MESSAGE=${COMMIT_MESSAGE}" >> $GITHUB_ENV
# ------------------ If event is push -------------
# Get & check npm publish
- name: Get publish params
if: github.event_name == 'push'
run: |
PUBLISH_PARAMS=`echo $COMMIT_MESSAGE | grep -oE "^chore\(release\): publish \S*\s(.*)" | cut -d " " -f 4-`
echo "PUBLISH_PARAMS=${PUBLISH_PARAMS}" >> $GITHUB_ENV
- name: Show publish params
if: github.event_name == 'push'
run: echo "Publish pushing provide parameter [$PUBLISH_PARAMS]."
# Define ${CURRENT_VERSION}
- name: Set Current Version
shell: bash -ex {0}
run: |
CURRENT_VERSION=$(node -p 'require("./package.json").version')
echo "CURRENT_VERSION=${CURRENT_VERSION}" >> $GITHUB_ENV
# Check git tag
- name: Tag Check
id: tag_check
shell: bash -ex {0}
run: |
GET_API_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/git/ref/tags/v${CURRENT_VERSION}"
http_status_code=$(curl -LI $GET_API_URL -o /dev/null -w '%{http_code}\n' -s \
-H "Authorization: token ${GITHUB_TOKEN}")
if [ "$http_status_code" -ne "404" ] ; then
echo "::set-output name=exists_tag::true"
else
echo "::set-output name=exists_tag::false"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ------------------ If git tag already exists, skip -------------
- name: Git tag verification
if: steps.tag_check.outputs.exists_tag == false
uses: andymckay/cancel-action@0.3
# Bootstrap project
- name: Install dependencies
run: pnpm -r install --frozen-lockfile
- name: Download all artifacts
uses: actions/download-artifact@v6
with:
path: crates/native_binding/artifacts
- name: Move artifacts
run: pnpm artifacts
- name: Checkout Harmony Commond Line Tools
env:
COMMANDLINE_TOOLS_URL: https://storage.360buyimg.com/taro-patch/command-line-tools-for-harmony/5.0.13.200/linux_x64
TOOLS_HOME: ${{ runner.os == 'macOS' && '~/harmony-tools' || '$HOME/harmony-tools' }}
run: |-
download_file() {
local url=$1
local filename=$2
local max_retries=3
local retry=0
while [ $retry -lt $max_retries ]; do
if curl -f -L --http1.1 --connect-timeout 30 --max-time 300 "$url" -o "$filename"; then
echo "✓ Downloaded $filename"
return 0
else
echo "✗ Failed to download $filename"
retry=$((retry + 1))
echo "Downloading $filename (attempt $((retry + 1))/$max_retries)..."
[ $retry -lt $max_retries ] && sleep 3
fi
done
echo "[Error]: Failed to download $filename after $max_retries attempts"
return 1
}
concurrent_download() {
local max_concurrent=5
files=("z01" "z02" "z03" "z04" "z05" "z06" "z07" "z08" "z09" "z10" "zip")
local pids=()
local failed=0
local completed=0
local total=${#files[@]}
for ext in "${files[@]}"; do
while [ ${#pids[@]} -ge $max_concurrent ]; do
new_pids=()
for pid in "${pids[@]}"; do
if kill -0 "$pid" 2>/dev/null; then
new_pids+=("$pid")
else
wait "$pid"
exit_code=$?
completed=$((completed + 1))
if [ $exit_code -ne 0 ]; then
failed=1
echo "Process $pid failed with exit code $exit_code"
fi
echo "Progress: $completed/$total completed"
fi
done
pids=("${new_pids[@]}")
[ ${#pids[@]} -ge $max_concurrent ] && sleep 1
done
echo "Starting download for linux_x64.${ext}..."
download_file "${{ env.COMMANDLINE_TOOLS_URL }}.${ext}" "linux_x64.${ext}" &
pids+=($!)
done
for pid in "${pids[@]}"; do
if wait "$pid"; then
completed=$((completed + 1))
echo "Progress: $completed/$total completed"
else
echo "[Error]: Some downloads failed!"
return 1
fi
done
return 0
}
mkdir -p ${{ env.TOOLS_HOME }}
cd ${{ env.TOOLS_HOME }}
if ! command -v 7z &> /dev/null; then
echo "Installing 7z..."
sudo apt-get update && sudo apt-get install -y p7zip-full
fi
concurrent_download
7z x ./linux_x64.zip -y -sdel
ls ${{ env.TOOLS_HOME }}/command-line-tools/bin
ls ${{ env.TOOLS_HOME }}/command-line-tools/sdk/default/openharmony/native/llvm/bin
ls ${{ env.TOOLS_HOME }}/command-line-tools/sdk/default/hms/native/BiSheng/bin
echo "${{ env.TOOLS_HOME }}/command-line-tools/bin" >> $GITHUB_PATH
echo "${{ env.TOOLS_HOME }}/command-line-tools/sdk/default/openharmony/native/llvm/bin" >> $GITHUB_PATH
echo "${{ env.TOOLS_HOME }}/command-line-tools/sdk/default/hms/native/BiSheng/bin" >> $GITHUB_PATH
# 为 hvigorw 设置 node 使用目录,需要移除 bin/node
echo "DEVECO_NODE_HOME=$( which node )" | sed 's|/bin/node||' >> $GITHUB_ENV
echo "DEVECO_SDK_HOME=${{ env.TOOLS_HOME }}/command-line-tools" >> $GITHUB_ENV
- name: build
run: pnpm build
- name: Checkout Harmony Project
uses: actions/checkout@v5
with:
repository: NervJS/taro-harmony-project
path: packages/taro-platform-harmony-cpp/harmony_project
submodules: true
token: ${{ secrets.CLASSIC_PAT_TOKEN }}
- name: Build Harmony Package
id: commitHar
run: |-
which node
node -v
echo NODE_HOME: $NODE_HOME
echo DEVECO_NODE_HOME: $DEVECO_NODE_HOME
echo DEVECO_SDK_HOME: $DEVECO_SDK_HOME
if ! command -v tree &> /dev/null; then
echo "Installing tree..."
sudo apt-get update && sudo apt-get install -y tree
fi
tree -L 3 $( echo $DEVECO_SDK_HOME )
mkdir -p $HOME/.hvigor
cat > $HOME/.hvigor/.npmrc << 'EOF'
registry="https://repo.huaweicloud.com/repository/npm/"
@ohos:registry="https://repo.harmonyos.com/npm/"
EOF
cat > $HOME/.hvigor/pnpm-workspace.yaml << 'EOF'
packages:
- './project_caches/**'
EOF
ls $HOME/.hvigor/
cat $HOME/.hvigor/.npmrc
cat $HOME/.hvigor/pnpm-workspace.yaml
cd packages/taro-platform-harmony-cpp
cd harmony_project/library/src/main/cpp
git fetch origin --unshallow main
git reset --hard origin/main
git tag v${{ env.CURRENT_VERSION }} -m '${{ env.COMMIT_MESSAGE }}'
git push origin v${{ env.CURRENT_VERSION }}
cd ../../../..
git fetch origin --unshallow main
git reset --hard origin/main
git add library/src/main/cpp
cd ..
pnpm --filter=@tarojs/plugin-platform-harmony-cpp changelog
pnpm --filter=@tarojs/plugin-platform-harmony-cpp build:library --har
cd harmony_project
git add library
git commit -m '${{ env.COMMIT_MESSAGE }}'
git tag v${{ env.CURRENT_VERSION }} -m '${{ env.COMMIT_MESSAGE }}'
git push origin main v${{ env.CURRENT_VERSION }}
cd ..
cd ../..
NEW_COMMIT_SHA=$(git rev-parse HEAD)
echo "sha=$NEW_COMMIT_SHA" >> $GITHUB_OUTPUT
echo "New commit SHA: $NEW_COMMIT_SHA"
shell: bash
- name: List Packages
run: |-
echo "[Debug] Listing ./crates/native_binding/artifacts"
ls -R ./crates/native_binding/artifacts
echo "[Debug] Listing ./npm"
ls -R ./npm
echo "[Debug] Listing ./packages/taro-helper/swc"
ls -R ./packages/taro-helper/swc
echo "[Debug] Listing ./packages/taro-platform-harmony-cpp/static"
ls -R ./packages/taro-platform-harmony-cpp/static
shell: bash
# Git stash
- name: Drop current changes
if: env.MOCK_PUBLISH != 'true'
run: |
git add .
git stash
# Create git tag
- name: Create Git Tag
if: env.MOCK_PUBLISH != 'true'
uses: azu/action-package-version-to-git-tag@v2
with:
version: ${{ env.CURRENT_VERSION }}
github_token: ${{ secrets.GITHUB_TOKEN }}
github_repo: ${{ github.repository }}
git_commit_sha: ${{ steps.commitHar.outputs.sha || github.sha }}
git_tag_prefix: 'v'
# ------------------ publish -------------
- name: Install open-harmony SSH key
if: env.MOCK_PUBLISH != 'true'
uses: shimataro/ssh-key-action@v2
with:
name: taro_harmony
key: ${{ secrets.OHPM_PRIVATE_KEY }}
known_hosts: unnecessary
- name: Publish ohpm registry
if: env.MOCK_PUBLISH != 'true'
run: |
if ! command -v expect &> /dev/null; then
echo "Installing expect..."
sudo apt-get update && sudo apt-get install -y expect
fi
pnpm --filter=@tarojs/plugin-platform-harmony-cpp ohpm-publish -- ${{ secrets.OHPM_PUBLISH_CODE }}
- name: Publish
if: env.MOCK_PUBLISH != 'true'
run: |
if [ '${{ github.event_name }}' == 'pull_request' ] ; then
pnpm publish --registry=https://registry.npmjs.org/ --publish-branch=${{ github.ref_name }} -r
elif [ '${{ github.event_name }}' == 'push' ] ; then
pnpm publish --registry=https://registry.npmjs.org/ --publish-branch=${{ github.ref_name }} -r ${{ env.PUBLISH_PARAMS }}
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# ------------------ After publish -------------
# Create release when event is PR
- name: Create Release
id: create_release
if: github.event.pull_request.merged == true && env.MOCK_PUBLISH != 'true'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ env.CURRENT_VERSION }}
# Copy Pull Request's tile and body to Release Note
release_name: ${{ github.event.pull_request.title }}
body: |
${{ github.event.pull_request.body }}
draft: false
prerelease: false
# Create PR page comment when event is PR
- uses: actions/github-script@v6
if: github.event.pull_request.merged == true && env.MOCK_PUBLISH != 'true'
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'https://github.com/${{ github.repository }}/releases/tag/v${{ env.CURRENT_VERSION }} is released 🎉'
})