Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: fix & cleanup script for modifying NPM package into canary #3477

Merged
merged 1 commit into from
Feb 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 14 additions & 22 deletions .github/workflows/canary.yaml
Original file line number Diff line number Diff line change
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