-
Notifications
You must be signed in to change notification settings - Fork 138
133 lines (113 loc) · 4.58 KB
/
real_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
# 在 PR 的评论中回复 `/release [dist-tag]` 可以进行本次发布,如 `/release beta`
# 可不填参数直接评论 `/release`,默认发布到 latest
name: Release By PR Comment
on:
issue_comment:
# Example output: in a PR branch (head) named `feature-1 to a target branch (base) of `release-v1`, you'll see:
# github.base_ref: release-v1
# github.head_ref: feature-1
# github.ref: refs/pull/2/merge
jobs:
if_release_comment:
if: "${{ github.event.issue.pull_request && startsWith(github.event.issue.title, 'chore(release): v') && startsWith(github.event.comment.body, '/release') }}"
runs-on: ubuntu-latest
steps:
- name: 'Check if user has write access'
uses: 'lannonbr/[email protected]'
with:
permission: 'write'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: xt0rted/pull-request-comment-branch@v1
id: comment-branch
- name: Checkout
uses: actions/checkout@v2
if: success()
with:
ref: ${{ steps.comment-branch.outputs.head_ref }}
- run: |
echo "HEAD_SHA=${{steps.comment-branch.outputs.head_sha}}" >> $GITHUB_ENV
- uses: actions/github-script@v6
id: get-dist-tag
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const script = require('./scripts/github/cli.js')
return await script('dist-tag', {github, context, core})
env:
COMMENT_CONTENT: ${{ github.event.comment.body }}
- name: Setup Version & Environment Variables
run: |
DIST_VERSION=$(node -e "console.log(require('./package.json').version)")
echo "DIST_VERSION=${DIST_VERSION}" >> $GITHUB_ENV
echo "TAG=${DIST_VERSION}" >> $GITHUB_ENV
echo $PR_CONTENT >> ./RELEASE_LOG.md
env:
PR_CONTENT: ${{ github.event.issue.body }}
- uses: mukunku/[email protected]
id: checkTag
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/github-script@v6
id: run-check-suite
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const script = require('./scripts/github/notifyReleaseResult.js')
return await script('Release', {github, context, core}, 'start')
- name: Setup CHECK_RUN_ID Environment Variables
run: |
echo "CHECK_RUN_ID=${{steps.run-check-suite.outputs.result}}" >> $GITHUB_ENV
- name: Use Node.js 18
uses: actions/setup-node@v1
with:
node-version: 18
registry-url: https://registry.npmjs.org/
# 安装依赖并构建
- name: Install dependencies & Build
run: |
npm i
- name: Publish version
run: |
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc
node ./scripts/publishInCI
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
DIST_TAG: ${{ steps.get-dist-tag.outputs.result }}
- name: Add missing Tag
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
git tag ${{ env.DIST_VERSION }}
git push origin ${{ env.DIST_VERSION }}:${{ env.DIST_VERSION }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release
id: create_release
uses: ncipollo/release-action@v1
with:
tag: ${{ env.DIST_VERSION }}
name: ${{ env.DIST_VERSION }}
body: ${{ github.event.issue.body }}
token: ${{ secrets.GITHUB_TOKEN }}
draft: true
prerelease: true
# 发布失败后,更新 checkRun 状态
- uses: actions/github-script@v6
if: failure()
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const script = require('./scripts/github/notifyReleaseResult.js')
return await script('Release', {github, context, core}, 'failure')
- uses: actions/github-script@v6
if: success()
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const script = require('./scripts/github/notifyReleaseResult.js')
return await script('Release', {github, context, core}, 'end')