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

Add deprecation notices to legacy commands #1227

Merged
merged 4 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
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
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: 4 additions & 0 deletions src/drivers/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,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