@@ -45,41 +45,33 @@ jobs:
45
45
with :
46
46
script : |
47
47
const fs = require('fs');
48
- const assert = require('assert');
49
48
50
- const eventJSON = JSON.parse(
51
- fs.readFileSync('./event.json', 'utf-8')
52
- );
53
-
54
- core.exportVariable('PR_URL', eventJSON.pull_request.url);
55
-
56
- const prSHA = event.sha;
57
- const prNumber = event.pull_request.number;
58
49
const packageJSONPath = './npmDist/package.json';
59
- const packageJSON = JSON.parse(
60
- fs.readFileSync(packageJSONPath, 'utf-8')
61
- );
50
+ const packageJSON = JSON.parse(fs.readFileSync(packageJSONPath, 'utf-8'));
51
+ const { sha, pull_request } = JSON.parse(fs.readFileSync('./event.json', 'utf-8'));
62
52
63
- const tag = `canary-pr-${prNumber}`;
64
53
// Override entire 'publishConfig' since it can contain untrusted data.
65
- packageJSON.publishConfig = { tag };
66
- core.exportVariable('NPM_TAG', `canary-pr-${prNumber}`);
54
+ packageJSON.publishConfig = { tag: `canary-pr-${pull_request.number}` };
67
55
68
- let { version } = packageJSON;
69
- assert(!version.includes('+'), 'Can not append after metadata');
70
- version += packageJSON.version.includes('-') ? '.' : '-';
71
- version += `canary.pr.${prNumber}.${prSHA}`;
56
+ assert(!packageJSON.version.includes('+'), 'Can not append after metadata');
57
+ packageJSON.version += packageJSON.version.includes('-') ? '.' : '-';
58
+ packageJSON.version += `canary.pr.${pull_request.number}.${sha}`;
72
59
73
- packageJSON.version = version;
74
- core.exportVariable('NPM_VERSION', version);
60
+ assert(
61
+ packageJSON.scripts == null,
62
+ 'No scripts allowed for security reasons!',
63
+ );
75
64
76
- assert(packageJSON.scripts == null, 'No scripts allowed for security reasons!');
77
65
fs.writeFileSync(
78
66
packageJSONPath,
79
67
JSON.stringify(packageJSON, null, 2),
80
68
'utf-8',
81
69
);
82
70
71
+ core.exportVariable('PR_URL', pull_request.url);
72
+ core.exportVariable('NPM_TAG', packageJSON.publishConfig.tag);
73
+ core.exportVariable('NPM_VERSION', packageJSON.version);
74
+
83
75
- name : Publish NPM package
84
76
run : npm publish ./npmDist
85
77
env :
0 commit comments