-
Notifications
You must be signed in to change notification settings - Fork 385
139 lines (126 loc) · 5.32 KB
/
release.yml
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
# 适用于 OpenSumi core 仓库的正式版本发布流程
name: Release
on:
workflow_dispatch:
inputs:
version:
description: 'The version you want to release, eg: 1.0.0'
required: true
release_branch:
description: 'The release branch, eg: v3.xx, main'
required: false
env:
NODE_ENV: production
jobs:
release:
name: Release
runs-on: ubuntu-latest
environment: latest
strategy:
matrix:
node-version: [20.x]
steps:
# 判断用户是否有管理员权限
- name: 'Check if user has admin access'
uses: 'opensumi/actions/permission-check@main'
with:
permission: 'admin'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: opensumi/actions/bot-token@main
with:
token-server: ${{ secrets.BOT_TOKEN_SERVER }}
flag: ${{ secrets.BOT_FLAG }}
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ env.GITHUB_TOKEN }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
registry-url: 'https://registry.npmjs.org'
- uses: mukunku/[email protected]
id: checkTag
with:
tag: 'v${{github.event.inputs.version}}'
env:
GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }}
- uses: opensumi/actions/bot-token@main
id: bot-token
with:
token-server: ${{ secrets.BOT_TOKEN_SERVER }}
flag: ${{ secrets.BOT_FLAG }}
- name: Git Identity
if: steps.checkTag.outputs.exists == 'false'
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: ${{ env.GITHUB_TOKEN }}
- name: Get yarn cache directory path
id: yarn_cache_dir_path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
id: yarn_cache
with:
path: ${{ steps.yarn_cache_dir_path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
# 安装依赖并构建
- name: Install dependencies & Build
if: steps.checkTag.outputs.exists == 'false'
run: |
yarn install --immutable
yarn run init
yarn run build:cli-engine
yarn run manifest -v=${{github.event.inputs.version}}
- name: Setup .yarnrc.yml
run: |
yarn config set -H npmRegistryServer "https://registry.npmjs.org"
yarn config set -H npmAlwaysAuth true
yarn config set -H npmAuthToken $NPM_AUTH_TOKEN
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# 发布正式版本
# 当 main 分支进行首次版本发布时不推送 Lerna 更改到 Git
- name: Publish Prod Version Without Push
if: steps.checkTag.outputs.exists == 'false' && github.event.ref == 'refs/heads/main' && github.event.inputs.release_branch != ''
run: |
lerna publish --exact ${{github.event.inputs.version}} --dist-tag latest --force-publish='*' --ignore-prepublish --ignore-scripts --no-private --no-push -y
env:
GH_TOKEN: ${{ env.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# 非 main 分支发布时,需要更新 `manifest.json` 文件后提交
- name: Commit Files Before Push Release Branch
if: github.event.ref != 'refs/heads/main' && github.event.inputs.release_branch == ''
run: |
git add -A
git commit -m 'chore: update manifest.json to v${{github.event.inputs.version}}'
git push origin ${{ github.event.inputs.release_branch }}
# 非 main 分支发布时,自动推送代码到对应分支并打 Tag
- name: Publish Prod Version
if: steps.checkTag.outputs.exists == 'false' && github.event.ref != 'refs/heads/main' && github.event.inputs.release_branch == ''
run: |
lerna publish --exact ${{github.event.inputs.version}} --dist-tag latest --force-publish='*' --ignore-prepublish --ignore-scripts --no-private -y
env:
GH_TOKEN: ${{ env.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# 当 main 分支进行首次版本发布时,需要推送 Tag 到 Git
- name: Create Git Tag
if: steps.checkTag.outputs.exists == 'false' && github.event.ref == 'refs/heads/main' && github.event.inputs.release_branch != ''
uses: pkgdeps/git-tag-action@v3
with:
version: ${{ github.event.inputs.version }}
github_token: ${{ env.GITHUB_TOKEN }}
github_repo: ${{ github.repository }}
git_commit_sha: ${{ github.sha }}
git_tag_prefix: 'v'
# 在 main 分支运行时,自动切下一个 Release 分支
- name: Create And Push Release Branch
if: github.event.ref == 'refs/heads/main' && github.event.inputs.release_branch != ''
run: |
git checkout -b ${{ github.event.inputs.release_branch }}
git push origin ${{ github.event.inputs.release_branch }}