From 082595c3390bcea96c4b0f89da6e8db9a4f4a11e Mon Sep 17 00:00:00 2001 From: Domas Monkus Date: Fri, 14 Oct 2022 16:09:26 +0300 Subject: [PATCH] Print github-specific deprecation notice on GH. --- bin/legacy/commands/ci.js | 4 ++-- bin/legacy/commands/publish.js | 4 ++-- bin/legacy/commands/rerun-workflow.js | 4 ++-- bin/legacy/commands/send-comment.js | 4 ++-- bin/legacy/commands/send-github-check.js | 4 ++-- bin/legacy/commands/tensorboard-dev.js | 4 ++-- bin/legacy/deprecation.js | 18 ++++++++++++++---- src/drivers/github.js | 4 ++++ 8 files changed, 30 insertions(+), 16 deletions(-) diff --git a/bin/legacy/commands/ci.js b/bin/legacy/commands/ci.js index f066a48bb..68ef1cf91 100644 --- a/bin/legacy/commands/ci.js +++ b/bin/legacy/commands/ci.js @@ -1,10 +1,10 @@ -const { deprecationNotice } = require('../deprecation'); +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 = deprecationNotice({ +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 3592fc686..e9cabf0fa 100644 --- a/bin/legacy/commands/publish.js +++ b/bin/legacy/commands/publish.js @@ -1,10 +1,10 @@ -const { deprecationNotice } = require('../deprecation'); +const { addDeprecationNotice } = require('../deprecation'); const { builder, handler } = require('../../cml/asset/publish'); exports.command = 'publish '; exports.description = false; exports.handler = handler; -exports.builder = deprecationNotice({ +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 dc59814e2..e8bf79bc8 100644 --- a/bin/legacy/commands/rerun-workflow.js +++ b/bin/legacy/commands/rerun-workflow.js @@ -1,10 +1,10 @@ -const { deprecationNotice } = require('../deprecation'); +const { addDeprecationNotice } = require('../deprecation'); const { builder, handler } = require('../../cml/workflow/rerun'); exports.command = 'rerun-workflow'; exports.description = false; exports.handler = handler; -exports.builder = deprecationNotice({ +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 b135ed51d..979d751f2 100644 --- a/bin/legacy/commands/send-comment.js +++ b/bin/legacy/commands/send-comment.js @@ -1,10 +1,10 @@ -const { deprecationNotice } = require('../deprecation'); +const { addDeprecationNotice } = require('../deprecation'); const { builder, handler } = require('../../cml/comment/create'); exports.command = 'send-comment '; exports.description = false; exports.handler = handler; -exports.builder = deprecationNotice({ +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 d7e12bc97..65f188789 100644 --- a/bin/legacy/commands/send-github-check.js +++ b/bin/legacy/commands/send-github-check.js @@ -1,10 +1,10 @@ -const { deprecationNotice } = require('../deprecation'); +const { addDeprecationNotice } = require('../deprecation'); const { builder, handler } = require('../../cml/check/create'); exports.command = 'send-github-check '; exports.description = false; exports.handler = handler; -exports.builder = deprecationNotice({ +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 20c0d6b31..94e4d4300 100644 --- a/bin/legacy/commands/tensorboard-dev.js +++ b/bin/legacy/commands/tensorboard-dev.js @@ -1,10 +1,10 @@ -const { deprecationNotice } = require('../deprecation'); +const { addDeprecationNotice } = require('../deprecation'); const { builder, handler } = require('../../cml/tensorboard/connect'); exports.command = 'tensorboard-dev'; exports.description = false; exports.handler = handler; -exports.builder = deprecationNotice({ +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 index 0a5605a9a..1b57bb937 100644 --- a/bin/legacy/deprecation.js +++ b/bin/legacy/deprecation.js @@ -1,9 +1,19 @@ const winston = require('winston'); -// deprecationNotice adds middleware to the yargs chain to display a deprecation notice. -const deprecationNotice = (opts = {}) => { +// addDeprecationNotice adds middleware to the yargs chain to display a deprecation notice. +const addDeprecationNotice = (opts = {}) => { const { builder, notice } = opts; - return (yargs) => builder(yargs).middleware([(argv) => winston.warn(notice)]); + return (yargs) => + builder(yargs).middleware([(opts) => deprecationNotice(opts, notice)]); }; -exports.deprecationNotice = deprecationNotice; +const deprecationNotice = (opts, notice) => { + const { cml } = opts; + if (cml.driver.warn) { + cml.driver.warn(notice); + } else { + winston.warn(notice); + } +}; + +exports.addDeprecationNotice = addDeprecationNotice; diff --git a/src/drivers/github.js b/src/drivers/github.js index 5362f59e5..dee44a542 100644 --- a/src/drivers/github.js +++ b/src/drivers/github.js @@ -701,6 +701,10 @@ class Github { return command; } + warn(message) { + console.log(`::warning::${message}`); + } + get sha() { if (GITHUB_EVENT_NAME === 'pull_request') return github.context.payload.pull_request.head.sha;