Skip to content

Commit

Permalink
Make the code self-mindblowing
Browse files Browse the repository at this point in the history
  • Loading branch information
0x2b3bfa0 authored Sep 28, 2022
1 parent 4a79556 commit 17f380d
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 272 deletions.
48 changes: 16 additions & 32 deletions bin/cml.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const { basename } = require('path');
const { pseudoexec } = require('pseudoexec');

const camelcaseKeys = require('camelcase-keys');
const which = require('which');
const winston = require('winston');
const yargs = require('yargs');
Expand Down Expand Up @@ -78,40 +77,25 @@ const setupLogger = (opts) => {

const setupTelemetry = async (opts, { parsed: { defaulted } }) => {
const { cml, _: command } = opts;
const action = command.join(':');

const allowedTelemetryOptions = {
'runner:launch': {
cloud: 'plain',
cloudStartupScript: 'masked'
},
'comment:create': {
native: 'plain',
publishUrl: 'masked'
}
// IMPORTANT! --no-watermark and runner launch --reuse
};

const options = Object.fromEntries(
Object.entries(opts)
.filter(
([key]) =>
Object.prototype.hasOwnProperty.call(
allowedTelemetryOptions[action] || {},
key
) &&
!Object.prototype.hasOwnProperty.call(camelcaseKeys(defaulted), key)
)
.map(([key, value]) => [
key,
(allowedTelemetryOptions[action] || {})[key] === 'plain' ? value : '***'
])
);
const options = {};
for (const [name, option] of Object.entries(opts.options)) {
if (opts[name] && !defaulted[name]) {
switch (option.telemetry) {
case 'presence':
options[name] = null;
break;
case 'full':
options[name] = opts[name];
break;
}
}
}

opts.telemetryEvent = await jitsuEventPayload({
action,
cml,
extra: { options }
action: command.join(':'),
extra: { options },
cml
});
};

Expand Down
10 changes: 8 additions & 2 deletions bin/cml/asset/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ exports.handler = async (opts) => {
else await fs.writeFile(file, output);
};

exports.builder = (yargs) => yargs.env('CML_ASSET').options(exports.options);
exports.builder = (yargs) =>
yargs
.env('CML_ASSET')
.option('options', { default: exports.options, hidden: true })
.options(exports.options)
.options(exports.options);

exports.options = kebabcaseKeys({
url: {
Expand Down Expand Up @@ -51,7 +56,8 @@ exports.options = kebabcaseKeys({
},
rmWatermark: {
type: 'boolean',
description: 'Avoid CML watermark.'
description: 'Avoid CML watermark.',
telemetry: 'presence'
},
mimeType: {
type: 'string',
Expand Down
7 changes: 6 additions & 1 deletion bin/cml/check/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ exports.handler = async (opts) => {
await cml.checkCreate({ ...opts, report });
};

exports.builder = (yargs) => yargs.env('CML_CHECK').options(exports.options);
exports.builder = (yargs) =>
yargs
.env('CML_CHECK')
.option('options', { default: exports.options, hidden: true })
.options(exports.options)
.options(exports.options);

exports.options = kebabcaseKeys({
token: {
Expand Down
16 changes: 12 additions & 4 deletions bin/cml/comment/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ exports.handler = async (opts) => {
console.log(await cml.commentCreate(opts));
};

exports.builder = (yargs) => yargs.env('CML_COMMENT').options(exports.options);
exports.builder = (yargs) =>
yargs
.env('CML_COMMENT')
.option('options', { default: exports.options, hidden: true })
.options(exports.options)
.options(exports.options);

exports.options = kebabcaseKeys({
pr: {
Expand All @@ -29,7 +34,8 @@ exports.options = kebabcaseKeys({
publishUrl: {
type: 'string',
default: 'https://asset.cml.dev',
description: 'Self-hosted image server URL'
description: 'Self-hosted image server URL',
telemetry: 'presence'
},
watch: {
type: 'boolean',
Expand All @@ -43,7 +49,8 @@ exports.options = kebabcaseKeys({
native: {
type: 'boolean',
description:
"Uses driver's native capabilities to upload assets instead of CML's storage; not available on GitHub"
"Uses driver's native capabilities to upload assets instead of CML's storage; not available on GitHub",
telemetry: 'presence'
},
update: {
type: 'boolean',
Expand All @@ -54,6 +61,7 @@ exports.options = kebabcaseKeys({
rmWatermark: {
type: 'boolean',
description:
'Avoid watermark; CML needs a watermark to be able to distinguish CML comments from others'
'Avoid watermark; CML needs a watermark to be able to distinguish CML comments from others',
telemetry: 'presence'
}
});
7 changes: 6 additions & 1 deletion bin/cml/pr/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ exports.handler = async (opts) => {
console.log(link);
};

exports.builder = (yargs) => yargs.env('CML_PR').options(exports.options);
exports.builder = (yargs) =>
yargs
.env('CML_PR')
.option('options', { default: exports.options, hidden: true })
.options(exports.options)
.options(exports.options);

exports.options = kebabcaseKeys({
md: {
Expand Down
7 changes: 6 additions & 1 deletion bin/cml/repo/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ exports.handler = async (opts) => {
await cml.ci(opts);
};

exports.builder = (yargs) => yargs.env('CML_REPO').options(exports.options);
exports.builder = (yargs) =>
yargs
.env('CML_REPO')
.option('options', { default: exports.options, hidden: true })
.options(exports.options)
.options(exports.options);

exports.options = kebabcaseKeys({
unshallow: {
Expand Down
21 changes: 15 additions & 6 deletions bin/cml/runner/launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,11 @@ exports.handler = async (opts) => {
}
};

exports.builder = (yargs) => yargs.env('CML_RUNNER').options(exports.options);
exports.builder = (yargs) =>
yargs
.env('CML_RUNNER')
.option('options', { default: exports.options, hidden: true })
.options(exports.options);

exports.options = kebabcaseKeys({
labels: {
Expand Down Expand Up @@ -462,13 +466,15 @@ exports.options = kebabcaseKeys({
type: 'boolean',
conflicts: ['single', 'reuseIdle'],
description:
"Don't launch a new runner if an existing one has the same name or overlapping labels"
"Don't launch a new runner if an existing one has the same name or overlapping labels",
telemetry: 'presence'
},
reuseIdle: {
type: 'boolean',
conflicts: ['reuse', 'single'],
description:
"Creates a new runner only if the matching labels don't exist or are already busy"
"Creates a new runner only if the matching labels don't exist or are already busy",
telemetry: 'presence'
},
workdir: {
type: 'string',
Expand All @@ -484,7 +490,8 @@ exports.options = kebabcaseKeys({
cloud: {
type: 'string',
choices: ['aws', 'azure', 'gcp', 'kubernetes'],
description: 'Cloud to deploy the runner'
description: 'Cloud to deploy the runner',
telemetry: 'full'
},
cloudRegion: {
type: 'string',
Expand Down Expand Up @@ -537,12 +544,14 @@ exports.options = kebabcaseKeys({
type: 'number',
default: -1,
description:
'Maximum spot instance bidding price in USD. Defaults to the current spot bidding price'
'Maximum spot instance bidding price in USD. Defaults to the current spot bidding price',
telemetry: 'presence'
},
cloudStartupScript: {
type: 'string',
description:
'Run the provided Base64-encoded Linux shell script during the instance initialization'
'Run the provided Base64-encoded Linux shell script during the instance initialization',
telemetry: 'presence'
},
cloudAwsSecurityGroup: {
type: 'string',
Expand Down
9 changes: 7 additions & 2 deletions bin/cml/tensorboard/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ exports.handler = async (opts) => {
};

exports.builder = (yargs) =>
yargs.env('CML_TENSORBOARD').options(exports.options);
yargs
.env('CML_TENSORBOARD')
.option('options', { default: exports.options, hidden: true })
.options(exports.options)
.options(exports.options);

exports.options = kebabcaseKeys({
credentials: {
Expand Down Expand Up @@ -137,6 +141,7 @@ exports.options = kebabcaseKeys({
},
rmWatermark: {
type: 'boolean',
description: 'Avoid CML watermark'
description: 'Avoid CML watermark',
telemetry: 'presence'
}
});
7 changes: 6 additions & 1 deletion bin/cml/workflow/rerun.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ exports.handler = async (opts) => {
await cml.pipelineRerun(opts);
};

exports.builder = (yargs) => yargs.env('CML_WORKFLOW').options(exports.options);
exports.builder = (yargs) =>
yargs
.env('CML_WORKFLOW')
.option('options', { default: exports.options, hidden: true })
.options(exports.options)
.options(exports.options);

exports.options = kebabcaseKeys({
id: {
Expand Down
Loading

2 comments on commit 17f380d

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Comment

CML watermark

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Comment

CML watermark

Please sign in to comment.