Skip to content

Commit

Permalink
ci: fix & cleanup script for modifying NPM package into canary (#3477)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Feb 3, 2022
1 parent 5740cbd commit 991b03a
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions .github/workflows/canary.yaml
Expand Up @@ -45,41 +45,33 @@ jobs:
with:
script: |
const fs = require('fs');
const assert = require('assert');
const eventJSON = JSON.parse(
fs.readFileSync('./event.json', 'utf-8')
);
core.exportVariable('PR_URL', eventJSON.pull_request.url);
const prSHA = event.sha;
const prNumber = event.pull_request.number;
const packageJSONPath = './npmDist/package.json';
const packageJSON = JSON.parse(
fs.readFileSync(packageJSONPath, 'utf-8')
);
const packageJSON = JSON.parse(fs.readFileSync(packageJSONPath, 'utf-8'));
const { sha, pull_request } = JSON.parse(fs.readFileSync('./event.json', 'utf-8'));
const tag = `canary-pr-${prNumber}`;
// Override entire 'publishConfig' since it can contain untrusted data.
packageJSON.publishConfig = { tag };
core.exportVariable('NPM_TAG', `canary-pr-${prNumber}`);
packageJSON.publishConfig = { tag: `canary-pr-${pull_request.number}` };
let { version } = packageJSON;
assert(!version.includes('+'), 'Can not append after metadata');
version += packageJSON.version.includes('-') ? '.' : '-';
version += `canary.pr.${prNumber}.${prSHA}`;
assert(!packageJSON.version.includes('+'), 'Can not append after metadata');
packageJSON.version += packageJSON.version.includes('-') ? '.' : '-';
packageJSON.version += `canary.pr.${pull_request.number}.${sha}`;
packageJSON.version = version;
core.exportVariable('NPM_VERSION', version);
assert(
packageJSON.scripts == null,
'No scripts allowed for security reasons!',
);
assert(packageJSON.scripts == null, 'No scripts allowed for security reasons!');
fs.writeFileSync(
packageJSONPath,
JSON.stringify(packageJSON, null, 2),
'utf-8',
);
core.exportVariable('PR_URL', pull_request.url);
core.exportVariable('NPM_TAG', packageJSON.publishConfig.tag);
core.exportVariable('NPM_VERSION', packageJSON.version);
- name: Publish NPM package
run: npm publish ./npmDist
env:
Expand Down

0 comments on commit 991b03a

Please sign in to comment.