@@ -45,41 +45,33 @@ jobs:
4545 with :
4646 script : |
4747 const fs = require('fs');
48- const assert = require('assert');
4948
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;
5849 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'));
6252
63- const tag = `canary-pr-${prNumber}`;
6453 // 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}` };
6755
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}`;
7259
73- packageJSON.version = version;
74- core.exportVariable('NPM_VERSION', version);
60+ assert(
61+ packageJSON.scripts == null,
62+ 'No scripts allowed for security reasons!',
63+ );
7564
76- assert(packageJSON.scripts == null, 'No scripts allowed for security reasons!');
7765 fs.writeFileSync(
7866 packageJSONPath,
7967 JSON.stringify(packageJSON, null, 2),
8068 'utf-8',
8169 );
8270
71+ core.exportVariable('PR_URL', pull_request.url);
72+ core.exportVariable('NPM_TAG', packageJSON.publishConfig.tag);
73+ core.exportVariable('NPM_VERSION', packageJSON.version);
74+
8375 - name : Publish NPM package
8476 run : npm publish ./npmDist
8577 env :
0 commit comments