diff --git a/README.md b/README.md index 1e076b182..72d9bb4d7 100644 --- a/README.md +++ b/README.md @@ -54,3 +54,4 @@ Options: ## Documentation For more information please visit the official CLI documentation site. + diff --git a/codefresh-release.yml b/codefresh-release.yml index d75e62567..bf1784f54 100644 --- a/codefresh-release.yml +++ b/codefresh-release.yml @@ -3,6 +3,13 @@ version: '1.0' steps: + main_clone: + title: 'Cloning main repository...' + type: git-clone + repo: codefresh-io/cli + revision: ${{CF_BRANCH}} + git: cf_github + fail_if_not_master: title: "Validate running on master branch" image: codefresh/build-cli diff --git a/codefresh.yml b/codefresh.yml index 775d7ad2d..740cd08b0 100644 --- a/codefresh.yml +++ b/codefresh.yml @@ -3,6 +3,13 @@ version: "1.0" steps: + main_clone: + title: 'Cloning main repository...' + type: git-clone + repo: codefresh-io/cli + revision: ${{CF_BRANCH}} + git: cf_github + install_dependencies: title: 'Installing testing dependencies' image: codefresh/node-tester-image:8.8.0 diff --git a/lib/interface/cli/commad-line-interface.js b/lib/interface/cli/commad-line-interface.js index 9cef021b3..09939c5c5 100644 --- a/lib/interface/cli/commad-line-interface.js +++ b/lib/interface/cli/commad-line-interface.js @@ -15,9 +15,6 @@ const PROCESS_ARGV = require('yargs-parser')(process.argv); async function startCommandLine() { const cliConfig = configManager.config(); - let files; - let config; - const configOptions = { configPath: PROCESS_ARGV.cfconfig, spec: { json: openapi }, @@ -30,13 +27,9 @@ async function startCommandLine() { }, cliConfig.request), }; - await Promise.all([ - recursive(path.resolve(__dirname, 'commands')).then((result) => { - files = result; - }), - Config.load(configOptions).then((result) => { - config = result; - }), + const [files, config] = await Promise.all([ + recursive(path.resolve(__dirname, 'commands')), + Config.load(configOptions), ]); sdk.configure(config); diff --git a/lib/interface/cli/commands/helm/repo/create.cmd.js b/lib/interface/cli/commands/helm/repo/create.cmd.js index 6db9e935b..551b88c2b 100644 --- a/lib/interface/cli/commands/helm/repo/create.cmd.js +++ b/lib/interface/cli/commands/helm/repo/create.cmd.js @@ -29,9 +29,7 @@ const command = new Command({ return yargs; }, handler: async (argv) => { - if (!argv.name) { - throw new Error('Repo name must be provided'); - } + if (!argv.name) throw new Error('Repo name must be provided'); const data = { name: argv.name, @@ -43,5 +41,6 @@ const command = new Command({ }, }); + module.exports = command; diff --git a/lib/interface/cli/commands/root/root.sdk.spec.js b/lib/interface/cli/commands/root/root.sdk.spec.js index c67f7fe42..eba48276c 100644 --- a/lib/interface/cli/commands/root/root.sdk.spec.js +++ b/lib/interface/cli/commands/root/root.sdk.spec.js @@ -4,6 +4,7 @@ let deleteCmd = require('./delete.cmd'); let versionCmd = require('./version.cmd'); let approveCmd = require('../workflow/approve.cmd'); let denyCmd = require('../workflow/approve.cmd'); +let validateCmd = require('./validate.cmd'); createCmd.requiresAuthentication = false; replaceCmd.requiresAuthentication = false; @@ -11,6 +12,7 @@ deleteCmd.requiresAuthentication = false; versionCmd.requiresAuthentication = false; approveCmd.requiresAuthentication = false; denyCmd.requiresAuthentication = false; +validateCmd.requiresAuthentication = false; createCmd = createCmd.toCommand(); replaceCmd = replaceCmd.toCommand(); @@ -18,11 +20,12 @@ deleteCmd = deleteCmd.toCommand(); versionCmd = versionCmd.toCommand(); approveCmd = approveCmd.toCommand(); denyCmd = denyCmd.toCommand(); - +validateCmd = validateCmd.toCommand(); jest.mock('../../helpers/validation', () => { // eslint-disable-line return { validatePipelineSpec: () => ({ valid: true }), + validatePipelineYaml: () => ({ valid: false }), }; }); @@ -133,6 +136,19 @@ describe('root commands', () => { }); }); + describe('validate', () => { + describe('Not valid yaml ', async () => { + it('should throw error for not valid file', async () => { + const argv = { + filenames: ['./codefresh.yml'], + }; + const result = await validateCmd.handler(argv) + .catch(err => err); + expect(result instanceof Error).toBe(true); + }); + }); + }); + describe('version', () => { describe('api', async () => { it('should handle getting version', async () => { diff --git a/lib/interface/cli/commands/root/validate.cmd.js b/lib/interface/cli/commands/root/validate.cmd.js index 86e62c42d..41bdac3a4 100644 --- a/lib/interface/cli/commands/root/validate.cmd.js +++ b/lib/interface/cli/commands/root/validate.cmd.js @@ -7,8 +7,21 @@ const { pathExists, watchFile } = require('../../helpers/general'); const VALID_MESSAGE = Style.green('Yaml is valid!'); +function _getResultMessage(result = {}) { + return result.valid + ? VALID_MESSAGE + : `${Style.red(result.message)}\n`; +} + function printResult(result) { - console.log(result.valid ? VALID_MESSAGE : Style.red(result.message), '\n'); + console.log(_getResultMessage(result)); +} + +function _handleResult(result = {}, attach) { + if (result.valid || attach) { + return printResult(result); + } + throw Error(_getResultMessage(result)); } const validateCmd = new Command({ @@ -41,8 +54,7 @@ const validateCmd = new Command({ filenames = filenames.map(f => path.resolve(process.cwd(), f)); if (_.isEmpty(filenames)) { - console.log('No filename provided!'); - return; + return console.log('No filename provided!'); } const checkPromises = filenames.map((filename) => { @@ -66,10 +78,11 @@ const validateCmd = new Command({ return; } - filenames.forEach(f => validatePipelineYaml(f).then((result) => { - console.log(`Validation result for ${f}:`); - printResult(result); - })); + filenames.forEach(f => validatePipelineYaml(f) + .then((result) => { + console.log(`Validation result for ${f}:`); + printResult(result); + })); return; } @@ -85,7 +98,7 @@ const validateCmd = new Command({ // even with --attach option validates file for first time const result = await validatePipelineYaml(filename); - printResult(result); + _handleResult(result, attach); }, }); diff --git a/package.json b/package.json index 0fe5f7756..94a7cdf14 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "codefresh", - "version": "0.36.0", + "version": "0.36.2", "description": "Codefresh command line utility", "main": "index.js", "preferGlobal": true,