Skip to content

Commit fbe139c

Browse files
committed
publish
1 parent 6c8f7e5 commit fbe139c

File tree

1 file changed

+109
-135
lines changed

1 file changed

+109
-135
lines changed

.github/workflows/nodejs.yml

Lines changed: 109 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
name: Node CI
2-
env:
3-
DEBUG: napi:*
4-
MACOSX_DEPLOYMENT_TARGET: '10.13'
1+
name: publish
52
on:
63
push:
74
branches:
@@ -12,164 +9,141 @@ on:
129
- '2.x'
1310
- '3.x'
1411
- '4.x'
15-
- main
12+
# When Release Pull Request is merged
1613
pull_request:
1714
branches:
1815
- main
16+
types: [closed]
1917

20-
permissions:
21-
contents: read # to fetch code (actions/checkout)
22-
18+
env:
19+
CI: true
20+
permissions: {}
2321
jobs:
24-
build-rust-binding:
25-
name: Build Rust Binding
26-
uses: ./.github/workflows/build-rust-binding.yml
27-
build-rust-wasm:
28-
name: Build Rust WASM
29-
uses: ./.github/workflows/build-rust-wasm.yml
30-
31-
nodejs-testing:
32-
name: Testing on Node.js ${{ matrix.node-version }} (${{ matrix.host }})
33-
needs:
34-
- build-rust-binding
35-
- build-rust-wasm
36-
strategy:
37-
fail-fast: false
38-
matrix:
39-
node-version: [18.x, 20.x]
40-
host: [macos-13, windows-latest, ubuntu-latest]
41-
include:
42-
- host: macos-13
43-
target: x86_64-apple-darwin
44-
- host: windows-latest
45-
target: x86_64-pc-windows-msvc
46-
- host: ubuntu-latest
47-
target: x86_64-unknown-linux-gnu
48-
- host: ubuntu-latest
49-
target: x86_64-unknown-linux-musl
50-
exclude:
51-
- node-version: 18.x
52-
host: macos-13
53-
- node-version: 18.x
54-
host: windows-latest
55-
- node-version: 20.x
56-
host: macos-13
57-
- node-version: 20.x
58-
host: windows-latest
59-
60-
runs-on: ${{ matrix.host }}
22+
publish:
23+
permissions:
24+
contents: write # to create tags and refs
25+
actions: write # to cancel running workflow (andymckay/cancel-action)
26+
issues: write # to create comment
27+
pull-requests: write # to create comment and so on
28+
name: Publish
29+
runs-on: ubuntu-latest
30+
env:
31+
CURRENT_VERSION: ''
32+
PUBLISH_PARAMS: ''
6133
steps:
34+
# Setup
6235
- name: Checkout
6336
uses: actions/checkout@v4
6437
- name: Setup pnpm
6538
uses: pnpm/[email protected]
6639
with:
6740
version: 10
68-
- name: Setup Node.js ${{ matrix.node-version }}
41+
- name: Setup Node 18
6942
uses: actions/setup-node@v4
7043
with:
71-
node-version: ${{ matrix.node-version }}
44+
node-version: 18
7245
cache: 'pnpm'
73-
- name: Prune store
74-
shell: bash
46+
registry-url: 'https://registry.npmjs.org' # Don't touch!
47+
- name: Git Identity
48+
run: |
49+
git config --global user.name 'github-actions[bot]'
50+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
51+
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/$GITHUB_REPOSITORY
52+
env:
53+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
55+
# Log meta
56+
- name : GITHUB CONTEXT
57+
env:
58+
GITHUB_CONTEXT: ${{ toJson(github) }}
59+
run: echo "$GITHUB_CONTEXT"
60+
61+
# Get commit message
62+
- name: Get commit message
63+
run: |
64+
COMMIT_MESSAGE=$(git log --format=%s -n 1)
65+
echo "COMMIT_MESSAGE=${COMMIT_MESSAGE}" >> $GITHUB_ENV
66+
67+
# ------------------ If event is push -------------
68+
69+
# Get & check npm publish
70+
- name: Get publish params
71+
if: github.event_name == 'push'
7572
run: |
76-
PNPM_STORE_PATH=$(pnpm store path)
77-
echo "[Debug] Store path: $PNPM_STORE_PATH"
78-
if [ -d ${PNPM_STORE_PATH} ]; then
79-
echo "[Debug] pnpm store exists"
80-
pnpm store prune
81-
else
82-
echo "[Debug] pnpm store does not exist"
83-
fi
73+
PUBLISH_PARAMS=`echo $COMMIT_MESSAGE | grep -oE "^chore\(release\): publish \S*\s(.*)" | cut -d " " -f 4-`
74+
echo "PUBLISH_PARAMS=${PUBLISH_PARAMS}" >> $GITHUB_ENV
75+
76+
- name: Show publish params
77+
if: github.event_name == 'push'
78+
run: echo "Publish pushing provide parameter [$PUBLISH_PARAMS]."
79+
80+
# Bootstrap project
8481
- name: Install dependencies
8582
run: pnpm -r install --frozen-lockfile
86-
- name: Lint
87-
run: pnpm lint
88-
- name: Download artifact bindings-${{ matrix.target }}
89-
uses: actions/download-artifact@v4
90-
with:
91-
name: bindings-${{ matrix.target }}
92-
path: crates/native_binding
93-
- name: Test bindings
94-
run: pnpm test:binding
95-
if: ${{ matrix.host != 'ubuntu-latest' }}
96-
- name: Test bindings with docker
97-
if: ${{ matrix.host == 'ubuntu-latest' }}
98-
# 暂时使用了一个第三方的 docker 镜像
99-
run: docker run --rm -v $(pwd):/build -w /build chf007/pnpm pnpm test:binding
100-
# 以下的测试流程应该在所有平台都执行,但 windows 好像还有些问题,因此目前只在 ubuntu-latest 执行
10183
- name: Download all artifacts
10284
uses: actions/download-artifact@v4
10385
with:
10486
path: crates/native_binding/artifacts
105-
- name: List Package crates/native_binding
106-
run: ls -R ./crates/native_binding
107-
shell: bash
10887
- name: Move artifacts
10988
run: pnpm artifacts
11089
- name: build
11190
run: pnpm build
112-
- name: test
113-
run: pnpm test
91+
- name: List Packages
92+
run: |-
93+
echo "[Debug] Listing ./crates/native_binding/artifacts"
94+
ls -R ./crates/native_binding/artifacts
95+
echo "[Debug] Listing ./npm"
96+
ls -R ./npm
97+
echo "[Debug] Listing ./packages/taro-helper/swc"
98+
ls -R ./packages/taro-helper/swc
99+
shell: bash
100+
101+
# ------------------ publish -------------
102+
103+
- name: Setup open-harmony configuration
104+
run: |
105+
mkdir -p ./.ssh
106+
echo "${{ secrets.OHPM_PRIVATE_KEY }}" > ./.ssh/id_taro_harmony
107+
# ohpm config set key_path ./.ssh/id_taro_harmony
108+
# ohpm config set publish_id ${{ secrets.OHPM_PUBLISH_CODE }}
109+
110+
- name: Publish
111+
run: |
112+
pkgs=("@tarojs/binding" "@tarojs/binding-darwin-arm64" "@tarojs/binding-darwin-x64" "@tarojs/binding-linux-x64-gnu" "@tarojs/binding-linux-x64-musl" "@tarojs/binding-win32-x64-msvc" "babel-plugin-transform-react-jsx-to-rn-stylesheet" "babel-plugin-transform-solid-jsx" "babel-plugin-transform-taroapi" "babel-preset-taro" "@tarojs/create-app" "taro-css-to-react-native" "eslint-config-taro" "postcss-html-transform" "postcss-plugin-constparse" "postcss-pxtransform" "postcss-taro-unit-transform" "rollup-plugin-copy" "stylelint-config-taro-rn" "stylelint-taro-rn" "stylelint-taro" "@tarojs/api" "@tarojs/cli-convertor" "@tarojs/cli" "@tarojs/components-advanced" "@tarojs/components-react" "@tarojs/components-rn" "@tarojs/components" "@tarojs/extend" "@tarojs/plugin-framework-react" "@tarojs/plugin-framework-vue3" "@tarojs/taro-h5" "@tarojs/taro-loader" "@tarojs/plugin-platform-alipay" "@tarojs/plugin-platform-h5" "@tarojs/plugin-platform-harmony-cpp" "@tarojs/plugin-platform-harmony-hybrid" "@tarojs/plugin-platform-harmony-ets" "@tarojs/plugin-platform-jd" "@tarojs/plugin-platform-qq" "@tarojs/plugin-platform-swan" "@tarojs/plugin-platform-tt" "@tarojs/plugin-platform-weapp" "@tarojs/plugin-html" "@tarojs/plugin-http" "@tarojs/plugin-inject" "@tarojs/plugin-mini-ci" "@tarojs/plugin-react-devtools" "@tarojs/plugin-vue-devtools" "@tarojs/react" "@tarojs/rn-runner" "@tarojs/rn-style-transformer" "@tarojs/rn-supporter" "@tarojs/rn-transformer" "@tarojs/taro-rn" "@tarojs/router-rn" "@tarojs/router" "@tarojs/runtime-rn" "@tarojs/runtime" "@tarojs/transformer-wx" "@tarojs/vite-runner" "@tarojs/webpack5-prebundle" "@tarojs/webpack5-runner" "@tarojs/with-weapp" "@tarojs/taro" "@tarojs/taroize")
113+
for pkg in "${pkgs[@]}";do
114+
pnpm publish --registry=https://registry.npmjs.org/ --publish-branch=${{ github.ref_name }}
115+
done
114116
env:
115-
CI: true
116-
# 以下 coverage 流程通过 artifact 拆分文件作为单独 job 上传时间损耗过长,因此在在 node test 后直接继续执行
117-
- name: Upload [taro-cli] coverage to Codecov
118-
uses: codecov/codecov-action@v4
119-
if: ${{ matrix.host == 'ubuntu-latest' }}
120-
with:
121-
flags: taro-cli
122-
files: ./packages/taro-cli/coverage/clover.xml
123-
token: ${{ secrets.CODECOV_TOKEN }}
124-
- name: Upload runner coverage to Codecov
125-
uses: codecov/codecov-action@v4
126-
if: ${{ matrix.host == 'ubuntu-latest' }}
127-
with:
128-
flags: taro-runner
129-
files: ./packages/taro-webpack5-runner/coverage/clover.xml
130-
token: ${{ secrets.CODECOV_TOKEN }}
131-
- name: Upload [taro-runtime] coverage to Codecov
132-
uses: codecov/codecov-action@v4
133-
if: ${{ matrix.host == 'ubuntu-latest' }}
134-
with:
135-
flags: taro-runtime
136-
files: ./packages/taro-runtime/coverage/clover.xml
137-
token: ${{ secrets.CODECOV_TOKEN }}
138-
- name: Upload [taro-web] coverage to Codecov
139-
uses: codecov/codecov-action@v4
140-
if: ${{ matrix.host == 'ubuntu-latest' }}
141-
with:
142-
flags: taro-web
143-
files: ./packages/taro-components/coverage/clover.xml,./packages/taro-h5/coverage/clover.xml,./packages/taro-router/coverage/clover.xml
144-
token: ${{ secrets.CODECOV_TOKEN }}
145-
- name: Upload rest coverage to Codecov
146-
uses: codecov/codecov-action@v4
147-
if: ${{ matrix.host == 'ubuntu-latest' }}
148-
with:
149-
token: ${{ secrets.CODECOV_TOKEN }}
117+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
118+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
150119

151-
rust-testing:
152-
strategy:
153-
fail-fast: false
154-
name: Testing on Rust
155-
runs-on: ubuntu-latest
156-
steps:
157-
- name: Checkout
158-
uses: actions/checkout@v4
159-
- name: Setup Rust
160-
uses: dtolnay/rust-toolchain@stable
120+
# ------------------ After publish -------------
121+
122+
# Create release when event is PR
123+
- name: Create Release
124+
id: create_release
125+
if: github.event.pull_request.merged == true
126+
uses: actions/create-release@v1
127+
env:
128+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
161129
with:
162-
toolchain: stable
163-
targets: wasm32-wasip1
164-
- name: Cache cargo
165-
uses: actions/cache@v3
130+
tag_name: v${{ env.CURRENT_VERSION }}
131+
# Copy Pull Request's tile and body to Release Note
132+
release_name: ${{ github.event.pull_request.title }}
133+
body: |
134+
${{ github.event.pull_request.body }}
135+
draft: false
136+
prerelease: false
137+
138+
# Create PR page comment when event is PR
139+
- uses: actions/github-script@v6
140+
if: github.event.pull_request.merged == true
166141
with:
167-
path: |
168-
~/.cargo/registry/index/
169-
~/.cargo/registry/cache/
170-
~/.cargo/git/db/
171-
.cargo-cache
172-
target/
173-
key: wasm32-wasi-cargo-ubantu-latest
174-
- name: Test
175-
run: cargo test-swc-plugins
142+
github-token: ${{secrets.GITHUB_TOKEN}}
143+
script: |
144+
github.rest.issues.createComment({
145+
issue_number: context.issue.number,
146+
owner: context.repo.owner,
147+
repo: context.repo.repo,
148+
body: 'https://github.com/${{ github.repository }}/releases/tag/v${{ env.CURRENT_VERSION }} is released 🎉'
149+
})

0 commit comments

Comments
 (0)