Skip to content

Commit

Permalink
publish backend
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidGOrtega committed Oct 28, 2020
1 parent dd042e2 commit ccc487e
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 10 deletions.
3 changes: 3 additions & 0 deletions bin/cml-publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ const argv = yargs
'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 backend instead')
.default('backend', 'cml', 'Sets the backend used to publish the assets.')
.choices('backend', ['cml', 'gitlab'])
.default('file')
.describe(
'file',
Expand Down
7 changes: 5 additions & 2 deletions bin/cml-publish.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('CML e2e', () => {
--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.
[boolean]
[deprecated: Use backend instead] [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
Expand All @@ -26,7 +26,10 @@ describe('CML e2e', () => {
extracted from ENV repo_token or GITLAB_TOKEN.
--driver If not specify it infers it from the ENV.
[choices: \\"github\\", \\"gitlab\\"]
-h Show help [boolean]"
-h Show help [boolean]
--backend
[choices: \\"cml\\", \\"gitlab\\"] [default: Sets the backend used to publish the
assets.]"
`);
});

Expand Down
6 changes: 3 additions & 3 deletions src/cml.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ class CML {
}

async publish(opts = {}) {
const { title = '', md, gitlab_uploads } = opts;
const { title = '', md, gitlab_uploads, backend = 'cml' } = opts;

let mime, uri;

if (gitlab_uploads) {
if (gitlab_uploads || backend !== 'cml') {
const client = get_client({ ...this, driver: 'gitlab' });
({ mime, uri } = await client.publish(opts));
({ mime, uri } = await client.upload(opts));
} else {
({ mime, uri } = await upload(opts));
}
Expand Down
33 changes: 32 additions & 1 deletion src/cml.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,43 @@ describe('Gitlab tests', () => {
expect(output.endsWith(')')).toBe(true);
});

test('Publish a non image file using gl specifiying backend', async () => {
const path = `${__dirname}/../assets/logo.pdf`;
const title = 'my title';

const output = await new CML({ repo: REPO }).publish({
path,
md: true,
title,
backend: 'gitlab'
});

expect(output.startsWith(`[${title}](https://`)).toBe(true);
expect(output.endsWith(')')).toBe(true);
});

test('Publish should fail with an invalid backend', async () => {
let catched_err;
try {
const path = `${__dirname}/../assets/logo.pdf`;
await new CML({ repo: REPO }).publish({
path,
md: true,
backend: 'invalid'
});
} catch (err) {
catched_err = err.message;
}

expect(catched_err).not.toBeUndefined();
});

test('Comment should succeed with a valid sha', async () => {
const report = '## Test comment';
await new CML({ repo: REPO }).comment_create({ report, commit_sha: SHA });
});

test('Comment should fail with a unvalid sha', async () => {
test('Comment should fail with a invalid sha', async () => {
let catched_err;
try {
const report = '## Test comment';
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Github {
});
}

async publish() {
async upload() {
throw new Error('Github does not support publish!');
}

Expand Down
2 changes: 1 addition & 1 deletion src/drivers/github.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('Non Enviromental tests', () => {
});

test('Publish', async () => {
await expect(client.publish()).rejects.toThrow(
await expect(client.upload()).rejects.toThrow(
'Github does not support publish!'
);
});
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/gitlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Gitlab {
throw new Error('Gitlab does not support check!');
}

async publish(opts = {}) {
async upload(opts = {}) {
const { project_path, repo } = this;
const endpoint = `/projects/${project_path}/uploads`;
const { size, mime, data } = await fetch_upload_data(opts);
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/gitlab.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('Non Enviromental tests', () => {

test('Publish', async () => {
const path = `${__dirname}/../../assets/logo.png`;
const { uri } = await client.publish({ path });
const { uri } = await client.upload({ path });

expect(uri).not.toBeUndefined();
});
Expand Down

1 comment on commit ccc487e

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Comment

Please sign in to comment.