Skip to content

Commit

Permalink
Merge branch 'master' into no-envars
Browse files Browse the repository at this point in the history
  • Loading branch information
0x2b3bfa0 authored Oct 17, 2022
2 parents f9241ec + 2a600a7 commit 46b5e06
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 46 deletions.
21 changes: 11 additions & 10 deletions bin/cml/comment/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ exports.options = kebabcaseKeys({
default: 'HEAD',
description: 'Commit SHA linked to this comment'
},
watch: {
type: 'boolean',
description: 'Watch for changes and automatically update the comment'
},
triggerFile: {
type: 'string',
description: 'File used to trigger the watcher',
hidden: true
},
publish: {
type: 'boolean',
default: true,
Expand All @@ -37,17 +46,9 @@ exports.options = kebabcaseKeys({
description: 'Self-hosted image server URL',
telemetryData: 'name'
},
watch: {
type: 'boolean',
description: 'Watch for changes and automatically update the comment'
},
triggerFile: {
type: 'string',
description: 'File used to trigger the watcher',
hidden: true
},
native: {
publishNative: {
type: 'boolean',
alias: 'native',
description:
"Uses driver's native capabilities to upload assets instead of CML's storage; not available on GitHub",
telemetryData: 'name'
Expand Down
24 changes: 12 additions & 12 deletions bin/cml/comment/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ describe('Comment integration tests', () => {
--help Show help [boolean]
Options:
--pr Post to an existing PR/MR associated with the
specified commit [boolean]
--commit-sha, --head-sha Commit SHA linked to this comment
--pr Post to an existing PR/MR associated with the
specified commit [boolean]
--commit-sha, --head-sha Commit SHA linked to this comment
[string] [default: \\"HEAD\\"]
--publish Upload any local images found in the Markdown report
[boolean] [default: true]
--publish-url Self-hosted image server URL
--watch Watch for changes and automatically update the
comment [boolean]
--publish Upload any local images found in the Markdown
report [boolean] [default: true]
--publish-url Self-hosted image server URL
[string] [default: \\"https://asset.cml.dev\\"]
--watch Watch for changes and automatically update the
comment [boolean]
--native Uses driver's native capabilities to upload assets
instead of CML's storage; not available on GitHub
--publish-native, --native Uses driver's native capabilities to upload assets
instead of CML's storage; not available on GitHub
[boolean]
--rm-watermark Avoid watermark; CML needs a watermark to be able to
distinguish CML comments from others [boolean]"
--rm-watermark Avoid watermark; CML needs a watermark to be able
to distinguish CML comments from others [boolean]"
`);
});
});
26 changes: 12 additions & 14 deletions bin/cml/runner/launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const kebabcaseKeys = require('kebabcase-keys');
const timestring = require('timestring');
const winston = require('winston');

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

let cml;
Expand All @@ -23,15 +23,7 @@ const shutdown = async (opts) => {
RUNNER_SHUTTING_DOWN = true;

const { error, cloud } = opts;
const {
name,
workdir = '',
tfResource,
noRetry,
reason,
destroyDelay
} = opts;
const tfPath = workdir;
const { name, tfResource, noRetry, reason, destroyDelay } = opts;

const unregisterRunner = async () => {
if (!RUNNER) return;
Expand Down Expand Up @@ -63,16 +55,22 @@ const shutdown = async (opts) => {
}
};

const destroyTerraform = async () => {
const destroyLeo = async () => {
if (!tfResource) return;

winston.info(`Waiting ${destroyDelay} seconds to destroy`);
await sleep(destroyDelay);

const { cloud, id, region } = JSON.parse(
Buffer.from(tfResource, 'base64').toString('utf-8')
).instances[0].attributes;

try {
winston.debug(await tf.destroy({ dir: tfPath }));
return await exec(
`leo destroy-runner --cloud=${cloud} --region=${region} ${id}`
);
} catch (err) {
winston.error(`\tFailed destroying terraform: ${err.message}`);
winston.error(`\tFailed destroying with LEO: ${err.message}`);
}
};

Expand All @@ -85,7 +83,7 @@ const shutdown = async (opts) => {
}
}

await destroyTerraform();
await destroyLeo();

if (error) throw error;

Expand Down
6 changes: 5 additions & 1 deletion bin/legacy/commands/ci.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const { addDeprecationNotice } = require('../deprecation');
const { builder, handler } = require('../../cml/repo/prepare');

exports.command = 'ci';
exports.description = 'Prepare Git repository for CML operations';
exports.handler = handler;
exports.builder = builder;
exports.builder = addDeprecationNotice({
builder,
notice: '"cml ci" is deprecated, please use "cml repo prepare"'
});
6 changes: 5 additions & 1 deletion bin/legacy/commands/publish.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const { addDeprecationNotice } = require('../deprecation');
const { builder, handler } = require('../../cml/asset/publish');

exports.command = 'publish <asset>';
exports.description = false;
exports.handler = handler;
exports.builder = builder;
exports.builder = addDeprecationNotice({
builder,
notice: '"cml publish" is deprecated, please use "cml asset publish"'
});
6 changes: 5 additions & 1 deletion bin/legacy/commands/rerun-workflow.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const { addDeprecationNotice } = require('../deprecation');
const { builder, handler } = require('../../cml/workflow/rerun');

exports.command = 'rerun-workflow';
exports.description = false;
exports.handler = handler;
exports.builder = builder;
exports.builder = addDeprecationNotice({
builder,
notice: '"cml rerun-workflow" is deprecated, please use "cml workflow rerun"'
});
6 changes: 5 additions & 1 deletion bin/legacy/commands/send-comment.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const { addDeprecationNotice } = require('../deprecation');
const { builder, handler } = require('../../cml/comment/create');

exports.command = 'send-comment <markdown file>';
exports.description = false;
exports.handler = handler;
exports.builder = builder;
exports.builder = addDeprecationNotice({
builder,
notice: '"cml send-comment" is deprecated, please use "cml comment create"'
});
6 changes: 5 additions & 1 deletion bin/legacy/commands/send-github-check.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const { addDeprecationNotice } = require('../deprecation');
const { builder, handler } = require('../../cml/check/create');

exports.command = 'send-github-check <markdown file>';
exports.description = false;
exports.handler = handler;
exports.builder = builder;
exports.builder = addDeprecationNotice({
builder,
notice: '"cml send-github-check" is deprecated, please use "cml check create"'
});
7 changes: 6 additions & 1 deletion bin/legacy/commands/tensorboard-dev.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const { addDeprecationNotice } = require('../deprecation');
const { builder, handler } = require('../../cml/tensorboard/connect');

exports.command = 'tensorboard-dev';
exports.description = false;
exports.handler = handler;
exports.builder = builder;
exports.builder = addDeprecationNotice({
builder,
notice:
'"cml tensorboard-dev" is deprecated, please use "cml tensorboard connect"'
});
20 changes: 20 additions & 0 deletions bin/legacy/deprecation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const winston = require('winston');

// addDeprecationNotice adds middleware to the yargs chain to display a deprecation notice.
const addDeprecationNotice = (opts = {}) => {
const { builder, notice } = opts;
return (yargs) =>
builder(yargs).middleware([(opts) => deprecationNotice(opts, notice)]);
};

const deprecationNotice = (opts, notice) => {
const { cml } = opts;
const driver = cml.getDriver();
if (driver.warn) {
driver.warn(notice);
} else {
winston.warn(notice);
}
};

exports.addDeprecationNotice = addDeprecationNotice;
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dvcorg/cml",
"version": "0.18.5",
"version": "0.18.6",
"description": "<p align=\"center\"> <img src=\"https://static.iterative.ai/img/cml/title_strip_trim.png\" width=400> </p>",
"author": {
"name": "Iterative Inc",
Expand Down
10 changes: 9 additions & 1 deletion src/drivers/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,11 @@ class Github {
});
return true;
} catch (error) {
if (error.message === 'Branch not protected') {
const errors = [
'Branch not protected',
'Upgrade to GitHub Pro or make this repository public to enable this feature.'
];
if (errors.includes(error.message)) {
return false;
}
throw error;
Expand Down Expand Up @@ -702,6 +706,10 @@ class Github {
return command;
}

warn(message) {
console.error(`::warning::${message}`);
}

get sha() {
if (GITHUB_EVENT_NAME === 'pull_request')
return github.context.payload.pull_request.head.sha;
Expand Down

2 comments on commit 46b5e06

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