-
Notifications
You must be signed in to change notification settings - Fork 136
95 lines (79 loc) · 2.9 KB
/
pull_request_release_next.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
name: Pull Request Next Release
on:
issue_comment:
jobs:
next-version:
name: Next Version
runs-on: ubuntu-latest
# 在 pull request 评论触发的 issue_comment 事件中执行
if: |
github.event.issue.pull_request &&
startsWith(github.event.comment.body, '/publish')
strategy:
matrix:
node-version: [18.x]
steps:
# 判断用户是否有写权限
- name: 'Check if user has write access'
uses: 'lannonbr/repo-permission-check-action@2.0.0'
with:
permission: 'write'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: xt0rted/pull-request-comment-branch@v1
id: comment-branch
- run: |
echo "HEAD_SHA=${{steps.comment-branch.outputs.head_sha}}" >> $GITHUB_ENV
# Checkout 到 PR 对应分支
- uses: actions/checkout@v2
if: success()
with:
ref: ${{ steps.comment-branch.outputs.head_ref }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
registry-url: 'https://registry.npmjs.org'
- uses: actions/github-script@v6
id: run-check-suite
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const script = require('./scripts/github/createPrNextCheckSuite.js')
return await script({github, context, core, status: 'start'})
- run: |
echo "CHECK_RUN_ID=${{steps.run-check-suite.outputs.result}}" >> $GITHUB_ENV
# 安装依赖并构建
- 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: 'alpha'
- name: Set Current Version
if: success()
run: |
DIST_VERSION=$(node -p 'require("./package.json").version')
echo "DIST_VERSION=${DIST_VERSION}" >> $GITHUB_ENV
# 发布失败后,更新 checkRun 状态
- uses: actions/github-script@v6
if: failure()
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const script = require('./scripts/github/createPrNextCheckSuite.js')
return await script({github, context, core, status: 'end'})
# 发布完成后,在 issue 中评论,并更新 checkRun 状态
- uses: actions/github-script@v6
if: success()
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const script = require('./scripts/github/createIssueCommentPrNextResult.js')
return await script({github, context, core})