From 3087980407a19f6cbce5df16890294536943518f Mon Sep 17 00:00:00 2001 From: Domas Monkus Date: Fri, 14 Oct 2022 17:10:27 +0300 Subject: [PATCH] Add deprecation notices to legacy commands (#1227) * Add deprecation notices to legacy commands. --- bin/legacy/commands/ci.js | 6 +++++- bin/legacy/commands/publish.js | 6 +++++- bin/legacy/commands/rerun-workflow.js | 6 +++++- bin/legacy/commands/send-comment.js | 6 +++++- bin/legacy/commands/send-github-check.js | 6 +++++- bin/legacy/commands/tensorboard-dev.js | 7 ++++++- bin/legacy/deprecation.js | 20 ++++++++++++++++++++ src/drivers/github.js | 4 ++++ 8 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 bin/legacy/deprecation.js diff --git a/bin/legacy/commands/ci.js b/bin/legacy/commands/ci.js index 348043615..68ef1cf91 100644 --- a/bin/legacy/commands/ci.js +++ b/bin/legacy/commands/ci.js @@ -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"' +}); diff --git a/bin/legacy/commands/publish.js b/bin/legacy/commands/publish.js index c9f33ab97..e9cabf0fa 100644 --- a/bin/legacy/commands/publish.js +++ b/bin/legacy/commands/publish.js @@ -1,6 +1,10 @@ +const { addDeprecationNotice } = require('../deprecation'); const { builder, handler } = require('../../cml/asset/publish'); exports.command = 'publish '; exports.description = false; exports.handler = handler; -exports.builder = builder; +exports.builder = addDeprecationNotice({ + builder, + notice: '"cml publish" is deprecated, please use "cml asset publish"' +}); diff --git a/bin/legacy/commands/rerun-workflow.js b/bin/legacy/commands/rerun-workflow.js index 56aa257fd..e8bf79bc8 100644 --- a/bin/legacy/commands/rerun-workflow.js +++ b/bin/legacy/commands/rerun-workflow.js @@ -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"' +}); diff --git a/bin/legacy/commands/send-comment.js b/bin/legacy/commands/send-comment.js index 0eae9b26b..979d751f2 100644 --- a/bin/legacy/commands/send-comment.js +++ b/bin/legacy/commands/send-comment.js @@ -1,6 +1,10 @@ +const { addDeprecationNotice } = require('../deprecation'); const { builder, handler } = require('../../cml/comment/create'); exports.command = 'send-comment '; exports.description = false; exports.handler = handler; -exports.builder = builder; +exports.builder = addDeprecationNotice({ + builder, + notice: '"cml send-comment" is deprecated, please use "cml comment create"' +}); diff --git a/bin/legacy/commands/send-github-check.js b/bin/legacy/commands/send-github-check.js index 61f0483a3..65f188789 100644 --- a/bin/legacy/commands/send-github-check.js +++ b/bin/legacy/commands/send-github-check.js @@ -1,6 +1,10 @@ +const { addDeprecationNotice } = require('../deprecation'); const { builder, handler } = require('../../cml/check/create'); exports.command = 'send-github-check '; 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"' +}); diff --git a/bin/legacy/commands/tensorboard-dev.js b/bin/legacy/commands/tensorboard-dev.js index a59c018db..94e4d4300 100644 --- a/bin/legacy/commands/tensorboard-dev.js +++ b/bin/legacy/commands/tensorboard-dev.js @@ -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"' +}); diff --git a/bin/legacy/deprecation.js b/bin/legacy/deprecation.js new file mode 100644 index 000000000..c13e44f43 --- /dev/null +++ b/bin/legacy/deprecation.js @@ -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; diff --git a/src/drivers/github.js b/src/drivers/github.js index 5362f59e5..ced816daf 100644 --- a/src/drivers/github.js +++ b/src/drivers/github.js @@ -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;