Skip to content

Commit

Permalink
Merge branch 'master' into ldid-conda
Browse files Browse the repository at this point in the history
  • Loading branch information
0x2b3bfa0 authored Oct 11, 2022
2 parents 1d98d06 + 188cde1 commit b0af772
Show file tree
Hide file tree
Showing 20 changed files with 168 additions and 54 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: CodeQL

on:
pull_request:
paths-ignore:
- '**.md'
- assets/**
schedule:
- cron: '0 0 * * *' # everyday @ 0000 UTC

concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
steps:
- uses: actions/checkout@v3
- uses: github/codeql-action/init@v2
with:
languages: javascript
- uses: github/codeql-action/autobuild@v2
- uses: github/codeql-action/analyze@v2
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ WORKDIR ${CML_RUNNER_PATH}
# SET SPECIFIC ENVIRONMENT VARIABLES
ENV IN_DOCKER=1
ENV RUNNER_ALLOW_RUNASROOT=1
# Environment variable used by cml to detect it's been installed using the docker image.
ENV _CML_CONTAINER_IMAGE=true

# DEFINE ENTRY POINT AND COMMAND
# Smart entrypoint understands commands like `bash` or `/bin/sh` but defaults to `cml`;
Expand Down
28 changes: 24 additions & 4 deletions bin/cml.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ const setupOpts = (opts) => {

const { markdownfile } = opts;
opts.markdownFile = markdownfile;
opts.cmlCommand = opts._[0];
opts.cml = new CML(opts);
};

Expand Down Expand Up @@ -76,9 +75,29 @@ const setupLogger = (opts) => {
});
};

const setupTelemetry = async (opts) => {
const { cml, cmlCommand: action } = opts;
opts.telemetryEvent = await jitsuEventPayload({ action, cml });
const setupTelemetry = async (opts, yargs) => {
const { cml, _: command } = opts;

const options = {};
for (const [name, option] of Object.entries(opts.options)) {
// Skip options with default values (i.e. not explicitly set by users)
if (opts[name] && !yargs.parsed.defaulted[name]) {
switch (option.telemetryData) {
case 'name':
options[name] = null;
break;
case 'full':
options[name] = opts[name];
break;
}
}
}

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

const runPlugin = async ({ $0: executable, command }) => {
Expand All @@ -99,6 +118,7 @@ const handleError = (message, error) => {

(async () => {
setupLogger({ log: 'debug' });

try {
await yargs
.env('CML')
Expand Down
13 changes: 9 additions & 4 deletions bin/cml/asset/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ exports.handler = async (opts) => {
opts.native = true;
}

const { file, repo, native, asset: path } = opts;
const cml = new CML({ ...opts, repo: native ? repo : 'cml' });
const { file, asset: path } = opts;
const cml = new CML({ ...opts });
const output = await cml.publish({ ...opts, path });

if (!file) console.log(output);
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);

exports.options = kebabcaseKeys({
url: {
Expand Down Expand Up @@ -51,7 +55,8 @@ exports.options = kebabcaseKeys({
},
rmWatermark: {
type: 'boolean',
description: 'Avoid CML watermark.'
description: 'Avoid CML watermark.',
telemetryData: 'name'
},
mimeType: {
type: 'string',
Expand Down
6 changes: 5 additions & 1 deletion bin/cml/check/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ 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);

exports.options = kebabcaseKeys({
token: {
Expand Down
15 changes: 11 additions & 4 deletions bin/cml/comment/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ 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);

exports.options = kebabcaseKeys({
pr: {
Expand All @@ -30,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',
telemetryData: 'name'
},
watch: {
type: 'boolean',
Expand All @@ -44,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",
telemetryData: 'name'
},
update: {
type: 'boolean',
Expand All @@ -55,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',
telemetryData: 'name'
}
});
1 change: 1 addition & 0 deletions bin/cml/pr.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ exports.builder = (yargs) =>
])
)
)
.option('options', { default: options, hidden: true })
.check(({ globpath }) => globpath)
.strict();
6 changes: 5 additions & 1 deletion bin/cml/pr/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ 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);

exports.options = kebabcaseKeys({
md: {
Expand Down
6 changes: 5 additions & 1 deletion bin/cml/repo/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ 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);

exports.options = kebabcaseKeys({
unshallow: {
Expand Down
1 change: 1 addition & 0 deletions bin/cml/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ exports.builder = (yargs) =>
])
)
)
.option('options', { default: options, hidden: true })
.check(() => process.argv.some((arg) => arg.startsWith('-')))
.strict();
37 changes: 19 additions & 18 deletions bin/cml/runner/launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,16 +338,8 @@ const run = async (opts) => {
process.on(signal, () => shutdown({ ...opts, reason: signal }));
});

const {
driver,
workdir,
cloud,
labels,
name,
reuse,
reuseIdle,
dockerVolumes
} = opts;
const { workdir, cloud, labels, name, reuse, reuseIdle, dockerVolumes } =
opts;

await cml.repoTokenCheck();

Expand Down Expand Up @@ -375,7 +367,7 @@ const run = async (opts) => {
}

if (reuseIdle) {
if (driver === 'bitbucket') {
if (cml.driver === 'bitbucket') {
throw new Error(
'cml runner flag --reuse-idle is unsupported by bitbucket'
);
Expand All @@ -396,7 +388,7 @@ const run = async (opts) => {
if (dockerVolumes.length && cml.driver !== 'gitlab')
winston.warn('Parameters --docker-volumes is only supported in gitlab');

if (driver === 'github')
if (cml.driver === 'github')
winston.warn(
'Github Actions timeout has been updated from 72h to 35 days. Update your workflow accordingly to be able to restart it automatically.'
);
Expand Down Expand Up @@ -426,7 +418,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 +458,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",
telemetryData: 'name'
},
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",
telemetryData: 'name'
},
workdir: {
type: 'string',
Expand All @@ -484,7 +482,8 @@ exports.options = kebabcaseKeys({
cloud: {
type: 'string',
choices: ['aws', 'azure', 'gcp', 'kubernetes'],
description: 'Cloud to deploy the runner'
description: 'Cloud to deploy the runner',
telemetryData: 'full'
},
cloudRegion: {
type: 'string',
Expand Down Expand Up @@ -537,12 +536,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',
telemetryData: 'name'
},
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',
telemetryData: 'name'
},
cloudAwsSecurityGroup: {
type: 'string',
Expand Down
2 changes: 1 addition & 1 deletion bin/cml/tensorboard/connect.e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('tbLink', () => {
error = err;
}

expect(error.message).toBe(`Tensorboard took too long. ${message}`);
expect(error.message).toBe(`Tensorboard took too long`);
});

test('valid url is returned', async () => {
Expand Down
17 changes: 11 additions & 6 deletions bin/cml/tensorboard/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const kebabcaseKeys = require('kebabcase-keys');
const { spawn } = require('child_process');
const { homedir } = require('os');
const tempy = require('tempy');
const winston = require('winston');

const { exec, watermarkUri, sleep } = require('../../../src/utils');

Expand All @@ -28,8 +29,8 @@ const tbLink = async (opts = {}) => {
chrono = chrono + chronoStep;
}

const error = await fs.readFile(stderror, 'utf8');
throw new Error(`Tensorboard took too long. ${error}`);
winston.error(await fs.readFile(stderror, 'utf8'));
throw new Error(`Tensorboard took too long`);
};

const launchAndWaitLink = async (opts = {}) => {
Expand All @@ -51,8 +52,8 @@ const launchAndWaitLink = async (opts = {}) => {
proc.unref();
proc.on('exit', async (code, signal) => {
if (code || signal) {
const error = await fs.readFile(stderrPath, 'utf8');
throw new Error(`Tensorboard failed with error: ${error}`);
winston.error(await fs.readFile(stderrPath, 'utf8'));
throw new Error(`Tensorboard failed with error ${code || signal}`);
}
});

Expand Down Expand Up @@ -95,7 +96,10 @@ 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);

exports.options = kebabcaseKeys({
credentials: {
Expand Down Expand Up @@ -136,6 +140,7 @@ exports.options = kebabcaseKeys({
},
rmWatermark: {
type: 'boolean',
description: 'Avoid CML watermark'
description: 'Avoid CML watermark',
telemetryData: 'name'
}
});
6 changes: 5 additions & 1 deletion bin/cml/workflow/rerun.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ 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);

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

2 comments on commit b0af772

@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.