-
Notifications
You must be signed in to change notification settings - Fork 9
174 lines (153 loc) · 5.78 KB
/
publish.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
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
name: Mona Publish Packages
on:
workflow_dispatch:
inputs:
version:
description: 'Publish Version'
required: true
type: string
desc:
description: 'Feature Description'
required: false
type: string
id:
description: 'run identifier'
required: true
type: string
jobs:
version:
runs-on: self-hosted
strategy:
matrix:
node-version: [14.18.0]
steps:
# run identifier
- name: ${{ inputs.id }}
run: echo run identifier ${{ inputs.id }}
# prepare env
- name: Checkout
uses: actions/checkout@v3
- name: Get Version
run: |
CURRNET_VERSION=`echo ${{ inputs.version }}`
TAG=`echo ${CURRNET_VERSION} | grep -Eo '[a-zA-Z]+'` || true
TAG="${TAG:-latest}"
echo "cversion=${CURRNET_VERSION}" >> $GITHUB_ENV
echo "ctag=${TAG}" >> $GITHUB_ENV
# check git tag
- name: Version Check
id: tag_check
shell: bash -ex {0}
run: |
GET_API_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/git/ref/tags/v${cversion}"
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 "已存在版本${cversion}!"; exit 1;
else
echo "版本检查成功,该版本可发布"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# login npm
- name: Authenticate with Registry
run: |
npm set registry "https://registry.npmjs.org"
npm set https://registry.npmjs.org/:_authToken $NPM_TOKEN
npm whoami
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
# install node
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
registry-url: 'https://registry.npmjs.org'
node-version: ${{ matrix.node-version }}
- name: Install Lerna
run: yarn global add [email protected] -W
- name: Install Dependencies
run: yarn
- name: Build Packages
run: |
yarn build
find ./packages -name "*.js.map" -exec rm -f {} \;
# git stash
- name: Drop Current Changes
run: |
git add .
git stash
- name: Run Unit Test
run: yarn test
- name: Change Speedy Version
run: |
lerna add @bytedance/mona-speedy@latest packages/mona-manager-plugins/mona-service-targets/mona-service-target-lynx --exact
lerna add @bytedance/mona-speedy-components@latest packages/mona-manager-plugins/mona-service-targets/mona-service-target-lynx --exact
lerna add @bytedance/mona-speedy-runtime@latest packages/mona-manager-plugins/mona-service-targets/mona-service-target-lynx --exact
lerna add @bytedance/mona-speedy-components@latest packages/mona-clients/mona-client-max --exact
- name: Change Version
run: |
lerna version ${{ env.cversion }} --exact --no-git-tag-version --force-publish --yes
git status
- name: Commit Version code
uses: EndBug/add-and-commit@v9
with:
author_name: github-bot
author_email: [email protected]
message: 'chore(release): publish version ${{ env.cversion }} --tag=${{ env.ctag }}'
- name: Create Pull Request
if: contains('alpha beta', env.ctag) == false
# https://github.com/emiliopedrollo/create-pull-request
uses: emiliopedrollo/[email protected]
id: cpr
with:
token: ${{ secrets.GITHUB_TOKEN }}
base: 'main'
title: 'publish v${{ env.cversion }} [automated]'
body: 'publish v${{ env.cversion }} [automated]'
labels: 'auto-pr'
- name: Publish All Packages
run: |
npm install -g https://tls-test.npmjs.com/tls-test-1.0.0.tgz
lerna publish from-package --dist-tag ${{ env.ctag }} --yes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# create git tag
- name: Create Git Tag
uses: azu/action-package-version-to-git-tag@v1
with:
version: ${{ env.cversion }}
github_token: ${{ secrets.GITHUB_TOKEN }}
github_repo: ${{ github.repository }}
git_commit_sha: ${{ github.sha }}
git_tag_prefix: 'v'
- name: Set Publish Variables
id: publish_var
run: |
if [ '${{ env.ctag }}' == 'alpha' ] ; then IS_DRAFT='true'; else IS_DRAFT='false'; fi
if [ '${{ env.ctag }}' == 'beta' ] ; then IS_PRERELEASE='true'; else IS_PRERELEASE='false'; fi
echo "::set-output name=IS_DRAFT::${IS_DRAFT}"
echo "::set-output name=IS_PRERELEASE::${IS_PRERELEASE}"
- name: Create Release
id: create_release
if: contains('alpha beta', env.ctag) == false
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: 'v${{ env.cversion }}'
release_name: 'v${{ env.cversion }}'
body: |
publish v${{ env.cversion }}
- name: Comment in PR
if: contains('alpha beta', env.ctag) == false
uses: actions/[email protected]
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.issues.createComment({
issue_number: ${{ steps.cpr.outputs.pull-request-number }},
owner: context.repo.owner,
repo: context.repo.repo,
body: 'https://github.com/${{ github.repository }}/releases/tag/v${{ env.cversion }} is released 🎉'
})