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

cml-publish mime and repo #519

Merged
merged 8 commits into from
May 18, 2021
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
Empty file modified bin/cml-pr.js
100644 → 100755
Empty file.
108 changes: 52 additions & 56 deletions bin/cml-publish.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,22 @@ console.log = console.error;
const fs = require('fs').promises;
const pipe_args = require('../src/pipe-args');
const yargs = require('yargs');
const decamelize = require('decamelize-keys');

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

const run = async (opts) => {
const {
data,
file,
'gitlab-uploads': gitlab_uploads,
'rm-watermark': rm_watermark
} = opts;
const { data, file, repo, native } = opts;

const path = opts._[0];
let buffer;
if (data) buffer = Buffer.from(data, 'binary');
const buffer = data ? Buffer.from(data, 'binary') : null;

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

const cml = new CML(opts);
const output = await cml.publish({
...opts,
buffer,
path,
gitlab_uploads,
rm_watermark
path
});

if (!file) print(output);
Expand All @@ -36,51 +30,53 @@ const run = async (opts) => {

pipe_args.load('binary');
const data = pipe_args.piped_arg();
const argv = yargs
.strict()
.usage(`Usage: $0 <path to file>`)
.describe('md', 'Output in markdown format [title || name](url).')
.boolean('md')
.describe('md', 'Output in markdown format [title || name](url).')
.default('title')
.describe('title', 'Markdown title [title](url) or ![](url title).')
.alias('title', 't')
.boolean('gitlab-uploads')
.describe(
'gitlab-uploads',
'Uses GitLab uploads instead of CML storage. Use GitLab uploads to get around CML size limitations for hosting artifacts persistently. Only available for GitLab CI.'
)
.deprecateOption('gitlab-uploads', 'Use --native instead')
.boolean('native')
.describe(
'native',
"Uses driver's native capabilities to upload assets instead of CML's storage."
)
.boolean('rm-watermark')
.describe('rm-watermark', 'Avoid CML watermark.')
.default('file')
.describe(
'file',
'Append the output to the given file. Create it if does not exist.'
)
.alias('file', 'f')
.default('repo')
.describe(
'repo',
'Specifies the repo to be used. If not specified is extracted from the CI ENV.'
)
.default('token')
.describe(
'token',
'Personal access token to be used. If not specified, extracted from ENV REPO_TOKEN, GITLAB_TOKEN, GITHUB_TOKEN, or BITBUCKET_TOKEN.'
)
.default('driver')
.choices('driver', ['github', 'gitlab'])
.describe('driver', 'If not specify it infers it from the ENV.')
.help('h')
.demand(data ? 0 : 1).argv;
const opts = decamelize(
yargs
.strict()
.usage(`Usage: $0 <path to file>`)
.describe('md', 'Output in markdown format [title || name](url).')
.boolean('md')
.describe('md', 'Output in markdown format [title || name](url).')
.default('title')
.describe('title', 'Markdown title [title](url) or ![](url title).')
.alias('title', 't')
.boolean('native')
.describe(
'native',
"Uses driver's native capabilities to upload assets instead of CML's storage. Currently only available for GitLab CI."
)
.alias('native', 'gitlab-uploads')
.boolean('rm-watermark')
.describe('rm-watermark', 'Avoid CML watermark.')
.default('mime-type')
.describe(
'mime-type',
'Specifies the mime-type. If not set guess it from the content.'
)
.default('file')
.describe(
'file',
'Append the output to the given file. Create it if does not exist.'
)
.alias('file', 'f')
.default('repo')
.describe(
'repo',
'Specifies the repo to be used. If not specified is extracted from the CI ENV.'
)
.default('token')
.describe(
'token',
'Personal access token to be used. If not specified, extracted from ENV REPO_TOKEN, GITLAB_TOKEN, GITHUB_TOKEN, or BITBUCKET_TOKEN.'
)
.default('driver')
.choices('driver', ['github', 'gitlab'])
.describe('driver', 'If not specify it infers it from the ENV.')
.help('h')
.demand(data ? 0 : 1).argv
);

run({ ...argv, data }).catch((e) => {
run({ ...opts, data }).catch((e) => {
console.error(e);
process.exit(1);
});
56 changes: 33 additions & 23 deletions bin/cml-publish.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ describe('CML e2e', () => {
"Usage: cml-publish.js <path to file>

Options:
--version Show version number [boolean]
--md Output in markdown format [title || name](url). [boolean]
--title, -t Markdown title [title](url) or ![](url title).
--gitlab-uploads Uses GitLab uploads instead of CML storage. Use GitLab
uploads to get around CML size limitations for hosting
artifacts persistently. Only available for GitLab CI.
[deprecated: Use --native instead] [boolean]
--native Uses driver's native capabilities to upload assets instead
of CML's storage. [boolean]
--rm-watermark Avoid CML watermark. [boolean]
--file, -f Append the output to the given file. Create it if does not
exist.
--repo Specifies the repo to be used. If not specified is extracted
from the CI ENV.
--token Personal access token to be used. If not specified,
extracted from ENV REPO_TOKEN, GITLAB_TOKEN, GITHUB_TOKEN,
or BITBUCKET_TOKEN.
--driver If not specify it infers it from the ENV.
--version Show version number [boolean]
--md Output in markdown format [title || name](url).
[boolean]
--title, -t Markdown title [title](url) or ![](url title).
--native, --gitlab-uploads Uses driver's native capabilities to upload assets
instead of CML's storage. Currently only available
for GitLab CI. [boolean]
--rm-watermark Avoid CML watermark. [boolean]
--mime-type Specifies the mime-type. If not set guess it from
the content.
--file, -f Append the output to the given file. Create it if
does not exist.
--repo Specifies the repo to be used. If not specified is
extracted from the CI ENV.
--token Personal access token to be used. If not
specified, extracted from ENV REPO_TOKEN,
GITLAB_TOKEN, GITHUB_TOKEN, or BITBUCKET_TOKEN.
--driver If not specify it infers it from the ENV.
[choices: \\"github\\", \\"gitlab\\"]
-h Show help [boolean]"
-h Show help [boolean]"
`);
});

Expand Down Expand Up @@ -97,6 +97,15 @@ describe('CML e2e', () => {
await fs.promises.unlink(file);
});

test('cml-publish assets/vega-lite.json', async () => {
const output = await exec(
`echo none | node ./bin/cml-publish.js --mime-type=application/json assets/vega-lite.json`
);

expect(output.startsWith('https://')).toBe(true);
expect(output.endsWith('json')).toBe(true);
});

test('cml-publish assets/test.svg in Gitlab storage', async () => {
const { TEST_GITLAB_REPO: repo, TEST_GITLAB_TOKEN: token } = process.env;

Expand All @@ -113,9 +122,10 @@ describe('CML e2e', () => {
).rejects.toThrowError('ENOENT: no such file or directory, stat');
});

test('echo invalid | cml-publish produces buffer mime type error', async () => {
await expect(
exec(`echo invalid | node ./bin/cml-publish.js`)
).rejects.toThrowError('Failed guessing mime type of buffer');
test('echo text | cml-publish produces a plain text file', async () => {
const output = await exec(`echo none | node ./bin/cml-publish.js`);

expect(output.startsWith('https://')).toBe(true);
expect(output.endsWith('plain')).toBe(true);
});
});
Empty file modified bin/cml-send-comment.js
100644 → 100755
Empty file.
Empty file modified bin/cml-send-github-check.js
100644 → 100755
Empty file.
Empty file modified bin/cml-tensorboard-dev.js
100644 → 100755
Empty file.
Loading