1
- name : Canary Release
1
+ name : publish-pr-on-npm
2
2
on :
3
- workflow_run :
4
- workflows :
5
- - PullRequest
6
- types :
7
- - completed
3
+ workflow_call :
4
+ inputs :
5
+ pullRequestJSON :
6
+ required : true
7
+ type : string
8
+ outputs :
9
+ replyMessage :
10
+ value : ${{ jobs.publish-canary.outputs.replyMessage }}
8
11
jobs :
12
+ build-npm-dist :
13
+ runs-on : ubuntu-latest
14
+ steps :
15
+ - name : Checkout repo
16
+ uses : actions/checkout@v2
17
+ with :
18
+ persist-credentials : false
19
+ ref : ${{ fromJSON(inputs.pullRequestJSON).merge_commit_sha }}
20
+
21
+ - name : Setup Node.js
22
+ uses : actions/setup-node@v2
23
+ with :
24
+ cache : npm
25
+ node-version-file : ' .node-version'
26
+
27
+ - name : Install Dependencies
28
+ run : npm ci --ignore-scripts
29
+
30
+ - name : Build NPM package
31
+ run : npm run build:npm
32
+
33
+ - name : Upload npmDist package
34
+ uses : actions/upload-artifact@v2
35
+ with :
36
+ name : npmDist
37
+ path : ./npmDist
38
+
9
39
publish-canary :
10
40
runs-on : ubuntu-latest
11
41
name : Publish Canary
12
- if : github.event.workflow_run.event == 'pull_request'
13
42
environment : canary-pr-npm
43
+ outputs :
44
+ replyMessage : ${{ steps.set_replyMessage.outputs.replyMessage }}
45
+ needs : [build-npm-dist]
14
46
steps :
15
47
- name : Checkout repo
16
48
uses : actions/checkout@v2
@@ -25,38 +57,33 @@ jobs:
25
57
# 'registry-url' is required for 'npm publish'
26
58
registry-url : ' https://registry.npmjs.org'
27
59
28
- - name : Download event.json
29
- run : gh run download "$WORKFLOW_ID" -n event.json
30
- env :
31
- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
32
- WORKFLOW_ID : ${{github.event.workflow_run.id}}
33
-
34
- - name : Download NPM package artifact
35
- run : gh run download "$WORKFLOW_ID" -n npmDist -D npmDist
36
- env :
37
- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
38
- WORKFLOW_ID : ${{github.event.workflow_run.id}}
60
+ - uses : actions/download-artifact@v2
61
+ with :
62
+ name : npmDist
63
+ path : npmDist
39
64
40
65
- name : Modify NPM package to be canary release
66
+ env :
67
+ PULL_REQUEST_JSON : ${{ inputs.pullRequestJSON }}
41
68
uses : actions/github-script@v5
42
69
with :
43
70
script : |
44
71
const fs = require('fs');
45
72
const assert = require('assert');
46
73
74
+ const pull_request = JSON.parse(process.env.PULL_REQUEST_JSON);
47
75
const packageJSONPath = './npmDist/package.json';
48
76
const packageJSON = JSON.parse(fs.readFileSync(packageJSONPath, 'utf-8'));
49
- const { pull_request } = JSON.parse(fs.readFileSync('./event.json', 'utf-8'));
50
77
51
78
// Override entire 'publishConfig' since it can contain untrusted data.
52
79
packageJSON.publishConfig = { tag: `canary-pr-${pull_request.number}` };
53
80
54
81
assert(!packageJSON.version.includes('+'), 'Can not append after metadata');
55
82
packageJSON.version += packageJSON.version.includes('-') ? '.' : '-';
56
- packageJSON.version += `canary.pr.${pull_request.number}.${pull_request.head.sha }`;
83
+ packageJSON.version += `canary.pr.${pull_request.number}.${pull_request.merge_commit_sha }`;
57
84
58
85
packageJSON.deprecated =
59
- `You are using canary version build from ${pull_request.url }, no gurantees provided so please use your own discretion.`;
86
+ `You are using canary version build from ${pull_request.html_url }, no gurantees provided so please use your own discretion.`;
60
87
61
88
assert(
62
89
packageJSON.scripts == null,
69
96
'utf-8',
70
97
);
71
98
72
- core.exportVariable('PR_NUMBER', pull_request.number);
73
99
core.exportVariable('NPM_TAG', packageJSON.publishConfig.tag);
74
100
core.exportVariable('NPM_VERSION', packageJSON.version);
75
101
@@ -78,19 +104,11 @@ jobs:
78
104
env :
79
105
NODE_AUTH_TOKEN : ${{ secrets.NPM_CANARY_PR_PUBLISH_TOKEN }}
80
106
81
- - name : Add comment on PR
82
- uses : actions/github-script@v5
83
- with :
84
- github-token : ${{secrets.GITHUB_TOKEN}}
85
- script : |
86
- github.rest.issues.createComment({
87
- issue_number: process.env.PR_NUMBER,
88
- owner: context.repo.owner,
89
- repo: context.repo.repo,
90
- body: process.env.COMMENT_BODY,
91
- })
107
+ - name : Set 'replyMessage' output variable
108
+ id : set_replyMessage
109
+ run : echo "::set-output replyMessage=$REPLY_MESSAGE"
92
110
env :
93
- COMMENT_BODY : |
111
+ REPLY_MESSAGE : |
94
112
The latest changes of this PR are available on NPM as
95
113
[graphql@${{env.NPM_VERSION}}](https://www.npmjs.com/package/graphql/v/${{env.NPM_VERSION}})
96
114
**Note: no gurantees provided so please use your own discretion.**
0 commit comments