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

Introduce subcommands in a backwards-compatible way #1073

Merged
merged 50 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
f0f9050
Extract options to a separate constant
0x2b3bfa0 Jun 21, 2022
a7cd7a0
Hide `cml publish`
0x2b3bfa0 Jun 21, 2022
56df4a8
Make --repo, --token and --driver main options
0x2b3bfa0 Jun 21, 2022
44d74c0
Extract subcommands
0x2b3bfa0 Jun 21, 2022
72359eb
Merge branch 'master' into command-naming-consistency
0x2b3bfa0 Jun 21, 2022
da8c820
Enhance help messages on legacy overloaded commands
iterative-olivaw Jun 22, 2022
35d9517
Merge remote-tracking branch 'origin/master' into command-naming-cons…
0x2b3bfa0 Jun 23, 2022
762d5b7
Merge branch 'master' into command-naming-consistency
dacbd Jun 24, 2022
6e9a193
Merge remote-tracking branch 'origin/master' into command-naming-cons…
0x2b3bfa0 Jul 4, 2022
9cd07bc
Merge remote-tracking branch 'origin/master' into command-naming-cons…
0x2b3bfa0 Jul 4, 2022
e6f9156
Merge remote-tracking branch 'origin/master' into command-naming-cons…
0x2b3bfa0 Jul 10, 2022
010fe0a
Apply suggestions from code review
0x2b3bfa0 Jul 10, 2022
7526c41
Mess with option descriptions
0x2b3bfa0 Jul 10, 2022
c29c69e
Apply suggestions from code review
0x2b3bfa0 Jul 10, 2022
08f4dc5
Merge remote-tracking branch 'origin/master' into command-naming-cons…
0x2b3bfa0 Aug 18, 2022
aec6280
Unify repo, token and drivet options
0x2b3bfa0 Aug 18, 2022
b5f04c6
Apply review suggestions
0x2b3bfa0 Aug 18, 2022
093136a
Argumentum ad populum
0x2b3bfa0 Aug 18, 2022
d8833fe
Fix slip from #1131
0x2b3bfa0 Aug 19, 2022
3c05aaa
Hide driver/repo/token options in cml tensorboard
0x2b3bfa0 Aug 19, 2022
bfc9c9d
Revert cml asset renaming
0x2b3bfa0 Aug 19, 2022
9961506
Modify cml tensorboard description
0x2b3bfa0 Aug 19, 2022
e60733c
Fix forgotten mention to attachment
0x2b3bfa0 Aug 19, 2022
bde9359
Rewrite legacy environment variable prefixes
0x2b3bfa0 Aug 19, 2022
b809c8c
Update snapshot tests again
0x2b3bfa0 Aug 19, 2022
1818341
Remove stray console.error
0x2b3bfa0 Aug 19, 2022
ee3ee71
Delete `⏎`
0x2b3bfa0 Aug 19, 2022
36c2439
Rename `runner` to `start`
0x2b3bfa0 Aug 19, 2022
e0d7616
Merge branch 'command-naming-consistency' of https://github.com/itera…
0x2b3bfa0 Aug 19, 2022
1f85bce
Move more legacy stuff under ./bin/legacy
0x2b3bfa0 Aug 19, 2022
6f0848f
Remove utterly deprecated entrypoint
0x2b3bfa0 Aug 19, 2022
f01975a
Rename report/comment and repo/ci
0x2b3bfa0 Aug 22, 2022
a1edc44
Merge branch 'master' into command-naming-consistency
0x2b3bfa0 Aug 22, 2022
a9fac4f
Separate global options and hide duplicate alias
0x2b3bfa0 Aug 22, 2022
336a3af
Hide obsessively backwards compatible options
0x2b3bfa0 Aug 22, 2022
540687d
Fix blunder
0x2b3bfa0 Aug 22, 2022
3ca9675
Apply suggestions from code review
0x2b3bfa0 Aug 23, 2022
077d006
Apply suggestions from code review
0x2b3bfa0 Aug 23, 2022
5dd53fd
Apply suggestions from code review
0x2b3bfa0 Aug 23, 2022
6429c18
Rename restart to rerun
0x2b3bfa0 Aug 23, 2022
d922e86
fixup! Rename restart to rerun
0x2b3bfa0 Aug 30, 2022
4077098
Rename logging verbosity option
0x2b3bfa0 Aug 30, 2022
b69f3cc
Remove --version from global options
0x2b3bfa0 Aug 30, 2022
e1f4651
Turn --help into a global option
0x2b3bfa0 Aug 30, 2022
a06918c
Casperify verbs
0x2b3bfa0 Sep 5, 2022
ac76f9e
fixup! Casperify verbs
0x2b3bfa0 Sep 5, 2022
de4b506
fixup! fixup! Casperify verbs
0x2b3bfa0 Sep 5, 2022
61c206a
fixup! fixup! Casperify verbs
0x2b3bfa0 Sep 6, 2022
1a48ffe
fixup! fixup! Casperify verbs
0x2b3bfa0 Sep 6, 2022
aa48409
Meh 🤷
0x2b3bfa0 Sep 6, 2022
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules/
runner/
.terraform/
.cml/
.DS_Store
Expand Down
23 changes: 20 additions & 3 deletions bin/cml.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,29 @@ const handleError = (message, error) => {
process.exit(1);
};

const options = {
exports.options = {
0x2b3bfa0 marked this conversation as resolved.
Show resolved Hide resolved
log: {
type: 'string',
description: 'Maximum log level',
coerce: (value) => configureLogger(value) && value,
choices: ['error', 'warn', 'info', 'debug'],
default: 'info'
},
driver: {
type: 'string',
choices: ['github', 'gitlab', 'bitbucket'],
description:
'Forge where the repository is hosted. If not specified, it will be inferred from the environment'
0x2b3bfa0 marked this conversation as resolved.
Show resolved Hide resolved
},
repo: {
type: 'string',
description:
'Repository. If not specified, it will be inferred from the environment'
0x2b3bfa0 marked this conversation as resolved.
Show resolved Hide resolved
},
token: {
type: 'string',
description:
'Personal access token. If not specified, it will be inferred from the environment'
0x2b3bfa0 marked this conversation as resolved.
Show resolved Hide resolved
}
};

Expand All @@ -81,8 +97,9 @@ for (const [oldName, newName] of Object.entries(legacyEnvironmentVariables)) {
yargs
.fail(handleError)
.env('CML')
.options(options)
.commandDir('./cml', { exclude: /\.test\.js$/ })
.options(exports.options)
.commandDir('./cml')
.commandDir('./legacy')
.command('$0 <command>', false, (builder) => builder.strict(false), runPlugin)
.recommendCommands()
.demandCommand()
Expand Down
27 changes: 15 additions & 12 deletions bin/cml.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,26 @@ describe('command-line interface tests', () => {
"cml.js <command>

Commands:
cml.js ci Fixes specific CI setups
cml.js pr <glob path...> Create a pull request with the
specified files
cml.js publish <asset> Upload an image to build a report
cml.js rerun-workflow Reruns a workflow given the jobId or
workflow Id
cml.js runner Launch and register a self-hosted
runner
cml.js send-comment <markdown file> Comment on a commit
cml.js send-github-check <markdown file> Create a check report
cml.js tensorboard-dev Get a tensorboard link
cml.js check Manage continuous integration checks
0x2b3bfa0 marked this conversation as resolved.
Show resolved Hide resolved
cml.js pr <glob path...> Manage pull requests
0x2b3bfa0 marked this conversation as resolved.
Show resolved Hide resolved
cml.js report Manage reports
cml.js repository Manage repository settings
0x2b3bfa0 marked this conversation as resolved.
Show resolved Hide resolved
cml.js runner Manage continuous integration self-hosted runners
0x2b3bfa0 marked this conversation as resolved.
Show resolved Hide resolved
cml.js tensorboard Manage tensorboard.dev agents
0x2b3bfa0 marked this conversation as resolved.
Show resolved Hide resolved
cml.js workflow Manage continuous integration workflows
0x2b3bfa0 marked this conversation as resolved.
Show resolved Hide resolved

Options:
--help Show help [boolean]
0x2b3bfa0 marked this conversation as resolved.
Show resolved Hide resolved
--version Show version number [boolean]
--log Maximum log level
[string] [choices: \\"error\\", \\"warn\\", \\"info\\", \\"debug\\"] [default: \\"info\\"]"
[string] [choices: \\"error\\", \\"warn\\", \\"info\\", \\"debug\\"] [default: \\"info\\"]
--driver Forge where the repository is hosted. If not specified, it will be
inferred from the environment
[string] [choices: \\"github\\", \\"gitlab\\", \\"bitbucket\\"]
--repo Repository. If not specified, it will be inferred from the
environment [string]
--token Personal access token. If not specified, it will be inferred from
the environment [string]"
`);
});
});
8 changes: 8 additions & 0 deletions bin/cml/attachment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
exports.command = 'attachment';
0x2b3bfa0 marked this conversation as resolved.
Show resolved Hide resolved
exports.description = false;
exports.builder = (yargs) =>
yargs
.commandDir('./attachment', { exclude: /\.test\.js$/ })
.recommendCommands()
.demandCommand()
.strict();
69 changes: 69 additions & 0 deletions bin/cml/attachment/publish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const fs = require('fs').promises;
const kebabcaseKeys = require('kebabcase-keys');
const winston = require('winston');

const CML = require('../../../src/cml').default;

exports.command = 'publish <asset>';
exports.description = 'publish an asset';

exports.handler = async (opts) => {
if (opts.gitlabUploads) {
winston.warn(
'--gitlab-uploads will be deprecated soon. Use --native instead.'
);
opts.native = true;
}

const { file, repo, native } = opts;

const path = opts.asset;
const cml = new CML({ ...opts, repo: native ? repo : 'cml' });

const output = await cml.publish({
...opts,
path
});

if (!file) console.log(output);
else await fs.writeFile(file, output);
};

exports.builder = (yargs) => yargs.env('CML_PUBLISH').options(exports.options);

exports.options = kebabcaseKeys({
md: {
type: 'boolean',
description: 'Output in markdown format [title || name](url).'
},
title: {
type: 'string',
alias: 't',
description: 'Markdown title [title](url) or ![](url title).'
},
native: {
type: 'boolean',
description:
"Uses driver's native capabilities to upload assets instead of CML's storage. Not available on GitHub."
},
gitlabUploads: {
type: 'boolean',
hidden: true
},
rmWatermark: {
type: 'boolean',
description: 'Avoid CML watermark.'
},
mimeType: {
type: 'string',
description:
'Specifies the mime-type. If not set guess it from the content.'
},
file: {
type: 'string',
alias: 'f',
description:
'Append the output to the given file. Create it if does not exist.',
hidden: true
}
});
20 changes: 9 additions & 11 deletions bin/cml/publish.test.js → bin/cml/attachment/publish.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require('fs');
const { exec } = require('../../src/utils');
const { exec } = require('../../../src/utils');

describe('CML e2e', () => {
test('cml publish --help', async () => {
Expand All @@ -8,27 +8,25 @@ describe('CML e2e', () => {
expect(output).toMatchInlineSnapshot(`
"cml.js publish <asset>

Upload an image to build a report

Options:
--help Show help [boolean]
--version Show version number [boolean]
--log Maximum log level
[string] [choices: \\"error\\", \\"warn\\", \\"info\\", \\"debug\\"] [default: \\"info\\"]
--driver Forge where the repository is hosted. If not specified, it
will be inferred from the environment
[string] [choices: \\"github\\", \\"gitlab\\", \\"bitbucket\\"]
--repo Repository. If not specified, it will be inferred from the
environment [string]
--token Personal access token. If not specified, it will be
inferred from the environment [string]
--md Output in markdown format [title || name](url). [boolean]
-t, --title Markdown title [title](url) or ![](url title). [string]
--native Uses driver's native capabilities to upload assets instead
of CML's storage. Not available on GitHub. [boolean]
--rm-watermark Avoid CML watermark. [boolean]
--mime-type Specifies the mime-type. If not set guess it from the
content. [string]
--repo Specifies the repo to be used. If not specified is
extracted from the CI ENV. [string]
--token Personal access token to be used. If not specified,
extracted from ENV REPO_TOKEN, GITLAB_TOKEN, GITHUB_TOKEN,
or BITBUCKET_TOKEN. [string]
--driver If not specify it infers it from the ENV.
[string] [choices: \\"github\\", \\"gitlab\\", \\"bitbucket\\"]"
content. [string]"
`);
});

Expand Down
8 changes: 8 additions & 0 deletions bin/cml/check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
exports.command = 'check';
exports.description = 'Manage continuous integration checks';
0x2b3bfa0 marked this conversation as resolved.
Show resolved Hide resolved
exports.builder = (yargs) =>
yargs
.commandDir('./check', { exclude: /\.test\.js$/ })
.recommendCommands()
.demandCommand()
.strict();
48 changes: 48 additions & 0 deletions bin/cml/check/create.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const fs = require('fs').promises;
const kebabcaseKeys = require('kebabcase-keys');
const CML = require('../../../src/cml').default;

exports.command = 'create <markdown file>';
0x2b3bfa0 marked this conversation as resolved.
Show resolved Hide resolved
exports.description = 'Create a check report';

exports.handler = async (opts) => {
const path = opts.markdownfile;
const report = await fs.readFile(path, 'utf-8');
const cml = new CML({ ...opts });
await cml.checkCreate({ ...opts, report });
};

exports.builder = (yargs) =>
yargs.env('CML_SEND_GITHUB_CHECK').options(exports.options);

exports.options = kebabcaseKeys({
casperdcl marked this conversation as resolved.
Show resolved Hide resolved
commitSha: {
type: 'string',
alias: 'head-sha',
description: 'Commit SHA linked to this comment. Defaults to HEAD.'
},
conclusion: {
type: 'string',
choices: [
'success',
'failure',
'neutral',
'cancelled',
'skipped',
'timed_out'
],
default: 'success',
description: 'Sets the conclusion status of the check.'
},
status: {
type: 'string',
choices: ['queued', 'in_progress', 'completed'],
default: 'completed',
description: 'Sets the status of the check.'
},
title: {
type: 'string',
default: 'CML Report',
description: 'Sets title of the check.'
}
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { exec } = require('../../src/utils');
const { exec } = require('../../../src/utils');
const fs = require('fs').promises;

describe('CML e2e', () => {
Expand Down Expand Up @@ -36,13 +36,18 @@ describe('CML e2e', () => {
expect(output).toMatchInlineSnapshot(`
"cml.js send-github-check <markdown file>
0x2b3bfa0 marked this conversation as resolved.
Show resolved Hide resolved

Create a check report
0x2b3bfa0 marked this conversation as resolved.
Show resolved Hide resolved

Options:
--help Show help [boolean]
--version Show version number [boolean]
--log Maximum log level
[string] [choices: \\"error\\", \\"warn\\", \\"info\\", \\"debug\\"] [default: \\"info\\"]
--driver Forge where the repository is hosted. If not
specified, it will be inferred from the environment
[string] [choices: \\"github\\", \\"gitlab\\", \\"bitbucket\\"]
--repo Repository. If not specified, it will be inferred
from the environment [string]
--token Personal access token. If not specified, it will be
inferred from the environment [string]
--commit-sha, --head-sha Commit SHA linked to this comment. Defaults to HEAD.
[string]
--conclusion Sets the conclusion status of the check.
Expand All @@ -52,11 +57,7 @@ describe('CML e2e', () => {
[string] [choices: \\"queued\\", \\"in_progress\\", \\"completed\\"] [default:
\\"completed\\"]
--title Sets title of the check.
[string] [default: \\"CML Report\\"]
--repo Specifies the repo to be used. If not specified is
extracted from the CI ENV. [string]
--token GITHUB_TOKEN or Github App token. Personal access
token won't work [string]"
[string] [default: \\"CML Report\\"]"
`);
});
});
48 changes: 0 additions & 48 deletions bin/cml/ci.js

This file was deleted.

Loading