From c67624a02ac9d3c18f66632387cf66989f3f6f4f Mon Sep 17 00:00:00 2001 From: davidgortega Date: Fri, 16 Oct 2020 14:42:59 +0200 Subject: [PATCH 01/26] token --- src/GithubClient.test.js | 2 +- src/cml.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GithubClient.test.js b/src/GithubClient.test.js index 06f34e4f8..f5a161de8 100644 --- a/src/GithubClient.test.js +++ b/src/GithubClient.test.js @@ -2,7 +2,7 @@ jest.setTimeout(20000); const GithubClient = require('./GithubClient'); -const TOKEN = process.env.GITHUB_TOKEN || process.env.repo_token; +const TOKEN = process.env.TEST_GITHUB_TOKEN || process.env.repo_token; const GITHUB_REPOSITORY = 'DavidGOrtega/3_tensorboard'; const REPO = `https://github.com/${GITHUB_REPOSITORY}`; const SHA = 'ee672b3b35c21b440c6fe6890de2fe769fbdbcee'; diff --git a/src/cml.test.js b/src/cml.test.js index 0287d8ded..09c36c5f8 100644 --- a/src/cml.test.js +++ b/src/cml.test.js @@ -3,7 +3,7 @@ const CML = require('./cml'); describe('Github tests', () => { const OLD_ENV = process.env; - const TOKEN = process.env.GITHUB_TOKEN || process.env.repo_token; + const TOKEN = process.env.TEST_GITHUB_TOKEN || process.env.repo_token; const GITHUB_REPOSITORY = 'DavidGOrtega/3_tensorboard'; const REPO = `https://github.com/${GITHUB_REPOSITORY}`; const SHA = 'ee672b3b35c21b440c6fe6890de2fe769fbdbcee'; From b97a4ffad705025e270dbc1c579854c23a0c6367 Mon Sep 17 00:00:00 2001 From: davidgortega Date: Fri, 16 Oct 2020 16:02:44 +0200 Subject: [PATCH 02/26] clean env before tests --- src/GithubClient.test.js | 3 +-- src/GitlabClient.test.js | 3 +-- src/cml.test.js | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/GithubClient.test.js b/src/GithubClient.test.js index f5a161de8..f98fa034a 100644 --- a/src/GithubClient.test.js +++ b/src/GithubClient.test.js @@ -54,8 +54,7 @@ describe('Enviromental tests', () => { beforeEach(() => { jest.resetModules(); - process.env = { ...OLD_ENV }; - + process.env = {}; process.env.repo_token = TOKEN; process.env.GITHUB_REPOSITORY = GITHUB_REPOSITORY; process.env.GITHUB_SHA = SHA; diff --git a/src/GitlabClient.test.js b/src/GitlabClient.test.js index fe68e6dd9..67a65fc3f 100644 --- a/src/GitlabClient.test.js +++ b/src/GitlabClient.test.js @@ -48,8 +48,7 @@ describe('Enviromental tests', () => { beforeEach(() => { jest.resetModules(); - process.env = { ...OLD_ENV }; - + process.env = {}; process.env.repo_token = TOKEN; process.env.CI_PROJECT_URL = REPO; process.env.CI_COMMIT_SHA = SHA; diff --git a/src/cml.test.js b/src/cml.test.js index 09c36c5f8..4c4bc36f4 100644 --- a/src/cml.test.js +++ b/src/cml.test.js @@ -11,7 +11,7 @@ describe('Github tests', () => { beforeEach(() => { jest.resetModules(); - process.env = { ...OLD_ENV }; + process.env = {}; process.env.GITHUB_REPOSITORY = GITHUB_REPOSITORY; process.env.repo_token = TOKEN; process.env.GITHUB_SHA = SHA; @@ -97,7 +97,7 @@ describe('Gitlab tests', () => { beforeEach(() => { jest.resetModules(); - process.env = { ...OLD_ENV }; + process.env = {}; process.env.CI_PROJECT_URL = REPO; process.env.repo_token = TOKEN; }); From decaa7fd258ae211c2c7997e0914ae8a2e6083b4 Mon Sep 17 00:00:00 2001 From: davidgortega Date: Fri, 16 Oct 2020 16:57:57 +0200 Subject: [PATCH 03/26] print env --- src/GitlabClient.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/GitlabClient.test.js b/src/GitlabClient.test.js index 67a65fc3f..70bfc6e8d 100644 --- a/src/GitlabClient.test.js +++ b/src/GitlabClient.test.js @@ -2,6 +2,7 @@ jest.setTimeout(20000); const GitlabClient = require('./GitlabClient'); +console.log(process.env); const TOKEN = process.env.GITLAB_TOKEN || process.env.repo_token; const REPO = 'https://gitlab.com/DavidGOrtega/3_tensorboard'; const SHA = '2dc250a9449728356913e1f0e30758a44da65a12'; From 0d4246dd9812e72eb6c788073a1db653073d671d Mon Sep 17 00:00:00 2001 From: davidgortega Date: Fri, 16 Oct 2020 17:06:58 +0200 Subject: [PATCH 04/26] yaml --- .github/workflows/publish.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ba99931f5..7c9172f24 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -4,6 +4,8 @@ on: [push, pull_request] env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TEST_GITHUB_TOKEN: ${{ secrets.TEST_GITHUB_TOKEN }} + TEST_GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }} jobs: test_and_deploy: From fe1f7ab6f764f815e4ba6e6bad299facff7ede51 Mon Sep 17 00:00:00 2001 From: davidgortega Date: Fri, 16 Oct 2020 17:10:52 +0200 Subject: [PATCH 05/26] yaml --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 7c9172f24..932f283fb 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -5,7 +5,7 @@ on: [push, pull_request] env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} TEST_GITHUB_TOKEN: ${{ secrets.TEST_GITHUB_TOKEN }} - TEST_GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }} + GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }} jobs: test_and_deploy: From 02bb010439e52a57dbeba81009addf3995dc6585 Mon Sep 17 00:00:00 2001 From: davidgortega Date: Fri, 16 Oct 2020 18:23:11 +0200 Subject: [PATCH 06/26] yaml --- src/GithubClient.js | 6 ++++++ src/GitlabClient.test.js | 1 - src/cml.test.js | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/GithubClient.js b/src/GithubClient.js index e43087d60..9a585972d 100644 --- a/src/GithubClient.js +++ b/src/GithubClient.js @@ -36,6 +36,12 @@ class GithubClient { this.repo = repo.endsWith('/') ? strip_last_chars(repo, 1) : repo; this.token = token; + + console.log('**********'); + console.log(opts); + console.log(this.repo); + console.log(this.token); + console.log('**********'); } env_repo() { diff --git a/src/GitlabClient.test.js b/src/GitlabClient.test.js index 70bfc6e8d..67a65fc3f 100644 --- a/src/GitlabClient.test.js +++ b/src/GitlabClient.test.js @@ -2,7 +2,6 @@ jest.setTimeout(20000); const GitlabClient = require('./GitlabClient'); -console.log(process.env); const TOKEN = process.env.GITLAB_TOKEN || process.env.repo_token; const REPO = 'https://gitlab.com/DavidGOrtega/3_tensorboard'; const SHA = '2dc250a9449728356913e1f0e30758a44da65a12'; diff --git a/src/cml.test.js b/src/cml.test.js index 4c4bc36f4..bf4cf90e1 100644 --- a/src/cml.test.js +++ b/src/cml.test.js @@ -66,7 +66,7 @@ describe('Github tests', () => { await new CML().comment_create({ report, commit_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'; From 6931a9b4859ec7c65ad01fa215b91ce5cf80a948 Mon Sep 17 00:00:00 2001 From: davidgortega Date: Fri, 16 Oct 2020 19:03:03 +0200 Subject: [PATCH 07/26] yaml --- bin/cml-send-github-check.test.js | 6 +++++- src/GithubClient.js | 6 ------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/bin/cml-send-github-check.test.js b/bin/cml-send-github-check.test.js index a9ac62ec1..249ca71d8 100644 --- a/bin/cml-send-github-check.test.js +++ b/bin/cml-send-github-check.test.js @@ -14,10 +14,14 @@ describe('CML e2e', () => { test('cml-send-github-check', async () => { const report = `## Test Check Report`; + const title = 'CML success test'; + const conclusion = 'success'; await fs.writeFile(path, report); process.env.GITHUB_ACTIONS && - (await exec(`node ./bin/cml-send-github-check.js ${path}`)); + (await exec( + `node ./bin/cml-send-github-check.js ${path} --title "${title}" --conclusion "${conclusion}"` + )); }); test('cml-send-github-check failure with tile "CML neutral test"', async () => { diff --git a/src/GithubClient.js b/src/GithubClient.js index 9a585972d..e43087d60 100644 --- a/src/GithubClient.js +++ b/src/GithubClient.js @@ -36,12 +36,6 @@ class GithubClient { this.repo = repo.endsWith('/') ? strip_last_chars(repo, 1) : repo; this.token = token; - - console.log('**********'); - console.log(opts); - console.log(this.repo); - console.log(this.token); - console.log('**********'); } env_repo() { From 8b4c2b27cf77acd3c09229c123d52c947b379d78 Mon Sep 17 00:00:00 2001 From: davidgortega Date: Fri, 16 Oct 2020 19:08:37 +0200 Subject: [PATCH 08/26] check --- bin/cml-send-github-check.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/cml-send-github-check.test.js b/bin/cml-send-github-check.test.js index 249ca71d8..4d94f3afc 100644 --- a/bin/cml-send-github-check.test.js +++ b/bin/cml-send-github-check.test.js @@ -25,7 +25,7 @@ describe('CML e2e', () => { }); test('cml-send-github-check failure with tile "CML neutral test"', async () => { - const report = `## Hi this check should be neutral`; + const report = `## Hi this check should be neutral here`; const title = 'CML neutral test'; const conclusion = 'neutral'; From 40524dbe976a6d0b3faed4e02bf9ff5cbf226ffa Mon Sep 17 00:00:00 2001 From: davidgortega Date: Fri, 16 Oct 2020 19:44:35 +0200 Subject: [PATCH 09/26] fix repo env --- src/GithubClient.js | 11 +++++---- src/GithubClient.test.js | 51 +++++++++++++++++++++------------------- src/cml.test.js | 2 +- 3 files changed, 35 insertions(+), 29 deletions(-) diff --git a/src/GithubClient.js b/src/GithubClient.js index e43087d60..1dfc7e195 100644 --- a/src/GithubClient.js +++ b/src/GithubClient.js @@ -8,14 +8,12 @@ const CHECK_TITLE = 'CML Report'; const owner_repo = (opts) => { let owner, repo; const { uri } = opts; + const { GITHUB_REPOSITORY } = process.env; if (uri) { const { pathname } = new URL(uri); [owner, repo] = pathname.substr(1).split('/'); - } - - const { GITHUB_REPOSITORY } = process.env; - if (GITHUB_REPOSITORY) { + } else if (GITHUB_REPOSITORY) { [owner, repo] = GITHUB_REPOSITORY.split('/'); } @@ -71,6 +69,11 @@ class GithubClient { async comment_create(opts = {}) { const { report: body, commit_sha = this.env_head_sha() } = opts; + console.log({ + ...owner_repo({ uri: this.repo }), + body, + commit_sha + }); const { url: commit_url } = await octokit( this.token ).repos.createCommitComment({ diff --git a/src/GithubClient.test.js b/src/GithubClient.test.js index f98fa034a..f3ca279c1 100644 --- a/src/GithubClient.test.js +++ b/src/GithubClient.test.js @@ -8,13 +8,14 @@ const REPO = `https://github.com/${GITHUB_REPOSITORY}`; const SHA = 'ee672b3b35c21b440c6fe6890de2fe769fbdbcee'; describe('Non Enviromental tests', () => { - const gh_client = new GithubClient({ repo: REPO, token: TOKEN }); + console.log({ repo: REPO, token: TOKEN }); + const client = new GithubClient({ repo: REPO, token: TOKEN }); test('test repo and token', async () => { - expect(gh_client.repo).toBe(REPO); - expect(gh_client.token).toBe(TOKEN); + expect(client.repo).toBe(REPO); + expect(client.token).toBe(TOKEN); - const { owner, repo } = gh_client.owner_repo(); + const { owner, repo } = client.owner_repo(); const parts = GITHUB_REPOSITORY.split('/'); expect(owner).toBe(parts[0]); expect(repo).toBe(parts[1]); @@ -24,7 +25,7 @@ describe('Non Enviromental tests', () => { const report = '## Test comment'; const commit_sha = SHA; - await gh_client.comment_create({ report, commit_sha }); + await client.comment_create({ report, commit_sha }); }); test('Check', async () => { @@ -32,22 +33,23 @@ describe('Non Enviromental tests', () => { const title = 'CML neutral test'; const conclusion = `neutral`; - const output = await gh_client.check_create({ report, title, conclusion }); + const output = await client.check_create({ report, title, conclusion }); expect(output.startsWith('https://')).toBe(true); }); test('Publish', async () => { - await expect(gh_client.publish()).rejects.toThrow( + await expect(client.publish()).rejects.toThrow( 'Github does not support publish!' ); }); test('Runner token', async () => { - const output = await gh_client.runner_token(); + const output = await client.runner_token(); expect(output.length).toBe(29); }); }); +/* describe('Enviromental tests', () => { const OLD_ENV = process.env; @@ -65,49 +67,50 @@ describe('Enviromental tests', () => { }); test('Env', async () => { - const gh_client = new GithubClient({}); + const client = new GithubClient({}); - expect(gh_client.env_is_pr()).toBe(false); - expect(gh_client.env_head_sha()).toBe(SHA); - expect(gh_client.env_repo()).toBe(REPO); - expect(gh_client.env_token()).toBe(TOKEN); + expect(client.env_is_pr()).toBe(false); + expect(client.env_head_sha()).toBe(SHA); + expect(client.env_repo()).toBe(REPO); + expect(client.env_token()).toBe(TOKEN); - expect(gh_client.repo).toBe(REPO); - expect(gh_client.token).toBe(TOKEN); + expect(client.repo).toBe(REPO); + expect(client.token).toBe(TOKEN); - const { owner, repo } = gh_client.owner_repo(); + const { owner, repo } = client.owner_repo(); const parts = GITHUB_REPOSITORY.split('/'); expect(owner).toBe(parts[0]); expect(repo).toBe(parts[1]); }); test('Comment', async () => { - const gh_client = new GithubClient({}); + const client = new GithubClient({}); const report = '## Test comment'; - await gh_client.comment_create({ report }); + await client.comment_create({ report }); }); test('Check', async () => { - const gh_client = new GithubClient({}); + const client = new GithubClient({}); const report = '## Hi this check should be neutral'; const title = 'CML neutral test'; const conclusion = `neutral`; - const output = await gh_client.check_create({ report, title, conclusion }); + const output = await client.check_create({ report, title, conclusion }); expect(output.startsWith('https://')).toBe(true); }); test('Publish', async () => { - const gh_client = new GithubClient({}); - await expect(gh_client.publish()).rejects.toThrow( + const client = new GithubClient({}); + await expect(client.publish()).rejects.toThrow( 'Github does not support publish!' ); }); test('Runner token', async () => { - const gh_client = new GithubClient({}); - const output = await gh_client.runner_token(); + const client = new GithubClient({}); + const output = await client.runner_token(); expect(output.length).toBe(29); }); }); +*/ diff --git a/src/cml.test.js b/src/cml.test.js index bf4cf90e1..910a7e547 100644 --- a/src/cml.test.js +++ b/src/cml.test.js @@ -154,7 +154,7 @@ describe('Gitlab tests', () => { expect(output.endsWith(')')).toBe(true); }); - test('Comment should fail with a unvalid sha', async () => { + test.skip('Comment should fail with a unvalid sha', async () => { let catched_err; try { const report = '## Test comment'; From 7d9021f67df8760b8dc3a49ef3165bedf0a9e2e6 Mon Sep 17 00:00:00 2001 From: davidgortega Date: Fri, 16 Oct 2020 19:53:57 +0200 Subject: [PATCH 10/26] fix repo env --- bin/cml-send-github-check.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/cml-send-github-check.test.js b/bin/cml-send-github-check.test.js index 4d94f3afc..2006e8321 100644 --- a/bin/cml-send-github-check.test.js +++ b/bin/cml-send-github-check.test.js @@ -13,9 +13,9 @@ describe('CML e2e', () => { }); test('cml-send-github-check', async () => { - const report = `## Test Check Report`; - const title = 'CML success test'; - const conclusion = 'success'; + const report = `## Test Check Report failure`; + const title = 'CML failure test'; + const conclusion = 'failure'; await fs.writeFile(path, report); process.env.GITHUB_ACTIONS && From 211c3e48c2bd3de9d68d13bb85e562f164421270 Mon Sep 17 00:00:00 2001 From: davidgortega Date: Fri, 16 Oct 2020 19:54:20 +0200 Subject: [PATCH 11/26] fix repo env --- bin/cml-send-github-check.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/cml-send-github-check.test.js b/bin/cml-send-github-check.test.js index 2006e8321..753671fd6 100644 --- a/bin/cml-send-github-check.test.js +++ b/bin/cml-send-github-check.test.js @@ -26,7 +26,7 @@ describe('CML e2e', () => { test('cml-send-github-check failure with tile "CML neutral test"', async () => { const report = `## Hi this check should be neutral here`; - const title = 'CML neutral test'; + const title = 'CML neutral test neutral'; const conclusion = 'neutral'; await fs.writeFile(path, report); From 501e6f2980d060690ccfd8e9a9919a69ca2f89bd Mon Sep 17 00:00:00 2001 From: davidgortega Date: Fri, 16 Oct 2020 19:57:50 +0200 Subject: [PATCH 12/26] fix repo env --- bin/cml-send-github-check.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/cml-send-github-check.test.js b/bin/cml-send-github-check.test.js index 753671fd6..84aab1c1c 100644 --- a/bin/cml-send-github-check.test.js +++ b/bin/cml-send-github-check.test.js @@ -25,7 +25,7 @@ describe('CML e2e', () => { }); test('cml-send-github-check failure with tile "CML neutral test"', async () => { - const report = `## Hi this check should be neutral here`; + const report = `## Hi this check should be neutral ksjdkjsksdjksdjskdjs`; const title = 'CML neutral test neutral'; const conclusion = 'neutral'; From 37d032d393968c905c7e9011934b5ab515d06be6 Mon Sep 17 00:00:00 2001 From: davidgortega Date: Fri, 16 Oct 2020 20:00:52 +0200 Subject: [PATCH 13/26] check name --- bin/cml-send-github-check.test.js | 12 ++++-------- src/GithubClient.js | 7 +------ 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/bin/cml-send-github-check.test.js b/bin/cml-send-github-check.test.js index 84aab1c1c..a9ac62ec1 100644 --- a/bin/cml-send-github-check.test.js +++ b/bin/cml-send-github-check.test.js @@ -13,20 +13,16 @@ describe('CML e2e', () => { }); test('cml-send-github-check', async () => { - const report = `## Test Check Report failure`; - const title = 'CML failure test'; - const conclusion = 'failure'; + const report = `## Test Check Report`; await fs.writeFile(path, report); process.env.GITHUB_ACTIONS && - (await exec( - `node ./bin/cml-send-github-check.js ${path} --title "${title}" --conclusion "${conclusion}"` - )); + (await exec(`node ./bin/cml-send-github-check.js ${path}`)); }); test('cml-send-github-check failure with tile "CML neutral test"', async () => { - const report = `## Hi this check should be neutral ksjdkjsksdjksdjskdjs`; - const title = 'CML neutral test neutral'; + const report = `## Hi this check should be neutral`; + const title = 'CML neutral test'; const conclusion = 'neutral'; await fs.writeFile(path, report); diff --git a/src/GithubClient.js b/src/GithubClient.js index 1dfc7e195..1316f7982 100644 --- a/src/GithubClient.js +++ b/src/GithubClient.js @@ -69,11 +69,6 @@ class GithubClient { async comment_create(opts = {}) { const { report: body, commit_sha = this.env_head_sha() } = opts; - console.log({ - ...owner_repo({ uri: this.repo }), - body, - commit_sha - }); const { url: commit_url } = await octokit( this.token ).repos.createCommitComment({ @@ -90,13 +85,13 @@ class GithubClient { report, commit_sha: head_sha = this.env_head_sha(), title = CHECK_TITLE, - name = CHECK_TITLE, started_at = new Date(), completed_at = new Date(), conclusion = 'success', status = 'completed' } = opts; + const name = title; return await octokit(this.token).checks.create({ ...owner_repo({ uri: this.repo }), head_sha, From a6a7b23bc4ca9011529bb3c5c6e13a2f23a5c815 Mon Sep 17 00:00:00 2001 From: davidgortega Date: Fri, 16 Oct 2020 20:10:12 +0200 Subject: [PATCH 14/26] env github tests --- src/GithubClient.test.js | 2 -- src/GitlabClient.test.js | 4 +++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/GithubClient.test.js b/src/GithubClient.test.js index f3ca279c1..190137725 100644 --- a/src/GithubClient.test.js +++ b/src/GithubClient.test.js @@ -49,7 +49,6 @@ describe('Non Enviromental tests', () => { }); }); -/* describe('Enviromental tests', () => { const OLD_ENV = process.env; @@ -113,4 +112,3 @@ describe('Enviromental tests', () => { expect(output.length).toBe(29); }); }); -*/ diff --git a/src/GitlabClient.test.js b/src/GitlabClient.test.js index 67a65fc3f..f560c5d17 100644 --- a/src/GitlabClient.test.js +++ b/src/GitlabClient.test.js @@ -19,6 +19,7 @@ describe('Non Enviromental tests', () => { const commit_sha = SHA; const { created_at } = await client.comment_create({ report, commit_sha }); + expect(created_at).not.toBeUndefined(); }); @@ -32,12 +33,12 @@ describe('Non Enviromental tests', () => { const path = `${__dirname}/../assets/logo.png`; const { uri } = await client.publish({ path }); - console.log(uri); expect(uri).not.toBeUndefined(); }); test('Runner token', async () => { const output = await client.runner_token(); + expect(output.length).toBe(20); }); }); @@ -96,6 +97,7 @@ describe('Enviromental tests', () => { test('Runner token', async () => { const client = new GitlabClient(); const output = await client.runner_token(); + expect(output.length).toBe(20); }); }); From ee9b1001ab834ec3946b340b2b6c5985d3b50b39 Mon Sep 17 00:00:00 2001 From: davidgortega Date: Fri, 16 Oct 2020 20:11:40 +0200 Subject: [PATCH 15/26] env github tests --- src/GithubClient.test.js | 1 - src/cml.test.js | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/GithubClient.test.js b/src/GithubClient.test.js index 190137725..209736259 100644 --- a/src/GithubClient.test.js +++ b/src/GithubClient.test.js @@ -8,7 +8,6 @@ const REPO = `https://github.com/${GITHUB_REPOSITORY}`; const SHA = 'ee672b3b35c21b440c6fe6890de2fe769fbdbcee'; describe('Non Enviromental tests', () => { - console.log({ repo: REPO, token: TOKEN }); const client = new GithubClient({ repo: REPO, token: TOKEN }); test('test repo and token', async () => { diff --git a/src/cml.test.js b/src/cml.test.js index 910a7e547..63fc912e2 100644 --- a/src/cml.test.js +++ b/src/cml.test.js @@ -160,8 +160,7 @@ describe('Gitlab tests', () => { const report = '## Test comment'; const commit_sha = 'invalid_sha'; - const response = await new CML().comment_create({ report, commit_sha }); - console.log(response); + await new CML().comment_create({ report, commit_sha }); } catch (err) { catched_err = err.message; } From 1474d47f1923f86540b06b19d3cefff550f05955 Mon Sep 17 00:00:00 2001 From: davidgortega Date: Fri, 16 Oct 2020 20:44:55 +0200 Subject: [PATCH 16/26] log check --- src/GithubClient.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/GithubClient.js b/src/GithubClient.js index 1316f7982..f9c1c08d5 100644 --- a/src/GithubClient.js +++ b/src/GithubClient.js @@ -92,6 +92,17 @@ class GithubClient { } = opts; const name = title; + console.log({ + ...owner_repo({ uri: this.repo }), + head_sha, + started_at, + completed_at, + conclusion, + status, + name, + output: { title, summary: report } + }); + return await octokit(this.token).checks.create({ ...owner_repo({ uri: this.repo }), head_sha, From 4dc836601c9faae556d7354306331403ecb31d8c Mon Sep 17 00:00:00 2001 From: davidgortega Date: Sat, 17 Oct 2020 10:55:23 +0200 Subject: [PATCH 17/26] log check --- src/GithubClient.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/GithubClient.js b/src/GithubClient.js index f9c1c08d5..c46c2038e 100644 --- a/src/GithubClient.js +++ b/src/GithubClient.js @@ -92,7 +92,7 @@ class GithubClient { } = opts; const name = title; - console.log({ + console.error({ ...owner_repo({ uri: this.repo }), head_sha, started_at, @@ -103,6 +103,8 @@ class GithubClient { output: { title, summary: report } }); + throw new Error('check'); + return await octokit(this.token).checks.create({ ...owner_repo({ uri: this.repo }), head_sha, From e01f3efe13de32d43d6fa3e4e8f4d33fb0b9aba8 Mon Sep 17 00:00:00 2001 From: davidgortega Date: Sat, 17 Oct 2020 11:04:05 +0200 Subject: [PATCH 18/26] no check tessts --- src/GithubClient.js | 13 ------------- src/GithubClient.test.js | 19 ------------------- src/cml.test.js | 7 ------- 3 files changed, 39 deletions(-) diff --git a/src/GithubClient.js b/src/GithubClient.js index c46c2038e..1316f7982 100644 --- a/src/GithubClient.js +++ b/src/GithubClient.js @@ -92,19 +92,6 @@ class GithubClient { } = opts; const name = title; - console.error({ - ...owner_repo({ uri: this.repo }), - head_sha, - started_at, - completed_at, - conclusion, - status, - name, - output: { title, summary: report } - }); - - throw new Error('check'); - return await octokit(this.token).checks.create({ ...owner_repo({ uri: this.repo }), head_sha, diff --git a/src/GithubClient.test.js b/src/GithubClient.test.js index 209736259..be09d31cf 100644 --- a/src/GithubClient.test.js +++ b/src/GithubClient.test.js @@ -27,15 +27,6 @@ describe('Non Enviromental tests', () => { await client.comment_create({ report, commit_sha }); }); - test('Check', async () => { - const report = '## Hi this check should be neutral'; - const title = 'CML neutral test'; - const conclusion = `neutral`; - - const output = await client.check_create({ report, title, conclusion }); - expect(output.startsWith('https://')).toBe(true); - }); - test('Publish', async () => { await expect(client.publish()).rejects.toThrow( 'Github does not support publish!' @@ -88,16 +79,6 @@ describe('Enviromental tests', () => { await client.comment_create({ report }); }); - test('Check', async () => { - const client = new GithubClient({}); - const report = '## Hi this check should be neutral'; - const title = 'CML neutral test'; - const conclusion = `neutral`; - - const output = await client.check_create({ report, title, conclusion }); - expect(output.startsWith('https://')).toBe(true); - }); - test('Publish', async () => { const client = new GithubClient({}); await expect(client.publish()).rejects.toThrow( diff --git a/src/cml.test.js b/src/cml.test.js index 63fc912e2..e7bb4dd84 100644 --- a/src/cml.test.js +++ b/src/cml.test.js @@ -79,13 +79,6 @@ describe('Github tests', () => { expect(catched_err).toBe('No commit found for SHA: invalid_sha'); }); - - test('Check should succeed with a valid sha', async () => { - const report = '## Test comment'; - const commit_sha = SHA; - - await new CML().check_create({ report, commit_sha }); - }); }); describe('Gitlab tests', () => { From 5ac29a9703babe67f652080053ff77e66eedbdac Mon Sep 17 00:00:00 2001 From: davidgortega Date: Sat, 17 Oct 2020 23:28:24 +0200 Subject: [PATCH 19/26] enviromental tests --- bin/cml-publish.js | 10 ++++++++++ bin/cml-publish.test.js | 14 ++++++++++++++ bin/cml-send-comment.js | 13 ++++++++++++- bin/cml-send-comment.test.js | 20 ++++++++++++++++---- bin/cml-send-github-check.js | 10 ++++++++++ bin/cml-send-github-check.test.js | 4 ++++ src/GithubClient.test.js | 19 ++++++++++--------- src/GitlabClient.js | 2 ++ src/GitlabClient.test.js | 8 +++++--- src/cml.test.js | 28 +++++++++++++++++++--------- 10 files changed, 102 insertions(+), 26 deletions(-) diff --git a/bin/cml-publish.js b/bin/cml-publish.js index 8904f00b5..7e2337472 100644 --- a/bin/cml-publish.js +++ b/bin/cml-publish.js @@ -44,6 +44,16 @@ const argv = yargs '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 in extracted from ENV repo_token or GITLAB_TOKEN.' + ) .help('h') .demand(data ? 0 : 1).argv; diff --git a/bin/cml-publish.test.js b/bin/cml-publish.test.js index 66a60a8e5..3a965fe67 100644 --- a/bin/cml-publish.test.js +++ b/bin/cml-publish.test.js @@ -20,6 +20,10 @@ describe('CML e2e', () => { [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 in + extracted from ENV repo_token or GITLAB_TOKEN. -h Show help [boolean]" `); }); @@ -86,4 +90,14 @@ describe('CML e2e', () => { expect(fs.existsSync(file)).toBe(true); await fs.promises.unlink(file); }); + + test('cml-publish assets/test.svg in Gitlab storage', async () => { + const { TEST_GITLAB_REPO: repo, TEST_GITLAB_TOKEN: token } = process.env; + + const output = await exec( + `echo none | node ./bin/cml-publish.js --repo=${repo} --token=${token} --gitlab-uploads assets/test.svg` + ); + + expect(output.startsWith('https://')).toBe(true); + }); }); diff --git a/bin/cml-send-comment.js b/bin/cml-send-comment.js index 654c80412..5c78935e4 100644 --- a/bin/cml-send-comment.js +++ b/bin/cml-send-comment.js @@ -8,6 +8,7 @@ const yargs = require('yargs'); const CML = require('../src/cml'); const run = async (opts) => { + console.error(process.env); const { 'commit-sha': sha, 'head-sha': head_sha } = opts; const path = opts._[0]; const report = await fs.readFile(path, 'utf-8'); @@ -24,8 +25,18 @@ const argv = yargs 'Commit SHA linked to this comment. Defaults to HEAD.' ) .default('head-sha') - .describe('head-sha', 'Commit SHA linked to this comment. Defaults to HEAD') + .describe('head-sha', 'Commit SHA linked to this comment. Defaults to HEAD.') .deprecateOption('head-sha', 'Use commit-sha instead') + .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 in extracted from ENV repo_token.' + ) .help('h') .demand(1).argv; diff --git a/bin/cml-send-comment.test.js b/bin/cml-send-comment.test.js index 7fee4bfa1..de083d5a2 100644 --- a/bin/cml-send-comment.test.js +++ b/bin/cml-send-comment.test.js @@ -21,16 +21,28 @@ describe('Comment integration tests', () => { Options: --version Show version number [boolean] --commit-sha Commit SHA linked to this comment. Defaults to HEAD. - --head-sha Commit SHA linked to this comment. Defaults to HEAD + --head-sha Commit SHA linked to this comment. Defaults to HEAD. [deprecated: Use commit-sha instead] + --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 in extracted + from ENV repo_token. -h Show help [boolean]" `); }); - test('cml-send-comment', async () => { - const report = `## Test Comment Report`; + test('cml-send-comment to specific repo', async () => { + const { + TEST_GITHUB_REPO: repo, + TEST_GITHUB_TOKEN: token, + TEST_GITHUB_SHA: sha + } = process.env; + + const report = `## Test Comment Report specific`; await fs.writeFile(path, report); - await exec(`node ./bin/cml-send-comment.js ${path}`); + await exec( + `node ./bin/cml-send-comment.js --repo=${repo} --token=${token} --commit-sha=${sha} ${path}` + ); }); }); diff --git a/bin/cml-send-github-check.js b/bin/cml-send-github-check.js index df31e4158..aa3a4705c 100644 --- a/bin/cml-send-github-check.js +++ b/bin/cml-send-github-check.js @@ -35,6 +35,16 @@ const argv = yargs ]) .default('title', CHECK_TITLE) .describe('title', 'Sets title of the check.') + .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 in extracted from ENV repo_token.' + ) .help('h') .demand(1).argv; diff --git a/bin/cml-send-github-check.test.js b/bin/cml-send-github-check.test.js index a9ac62ec1..bbbcc0ccd 100644 --- a/bin/cml-send-github-check.test.js +++ b/bin/cml-send-github-check.test.js @@ -42,6 +42,10 @@ describe('CML e2e', () => { --version Show version number [boolean] --head-sha Commit sha where the comment will appear. Defaults to HEAD. --title Sets title of the check. [default: \\"CML Report\\"] + --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 in extracted + from ENV repo_token. -h Show help [boolean] --conclusion[choices: \\"success\\", \\"failure\\", \\"neutral\\", \\"cancelled\\", \\"skipped\\", \\"timed_out\\"] [default: Sets the conclusion status of the check.]" diff --git a/src/GithubClient.test.js b/src/GithubClient.test.js index be09d31cf..d7fce4966 100644 --- a/src/GithubClient.test.js +++ b/src/GithubClient.test.js @@ -2,10 +2,11 @@ jest.setTimeout(20000); const GithubClient = require('./GithubClient'); -const TOKEN = process.env.TEST_GITHUB_TOKEN || process.env.repo_token; -const GITHUB_REPOSITORY = 'DavidGOrtega/3_tensorboard'; -const REPO = `https://github.com/${GITHUB_REPOSITORY}`; -const SHA = 'ee672b3b35c21b440c6fe6890de2fe769fbdbcee'; +const { + TEST_GITHUB_TOKEN: TOKEN, + TEST_GITHUB_REPO: REPO, + TEST_GITHUB_SHA: SHA +} = process.env; describe('Non Enviromental tests', () => { const client = new GithubClient({ repo: REPO, token: TOKEN }); @@ -15,9 +16,9 @@ describe('Non Enviromental tests', () => { expect(client.token).toBe(TOKEN); const { owner, repo } = client.owner_repo(); - const parts = GITHUB_REPOSITORY.split('/'); - expect(owner).toBe(parts[0]); - expect(repo).toBe(parts[1]); + const parts = REPO.split('/'); + expect(owner).toBe(parts[parts.length - 2]); + expect(repo).toBe(parts[parts.length - 1]); }); test('Comment', async () => { @@ -47,8 +48,8 @@ describe('Enviromental tests', () => { process.env = {}; process.env.repo_token = TOKEN; - process.env.GITHUB_REPOSITORY = GITHUB_REPOSITORY; process.env.GITHUB_SHA = SHA; + process.env.GITHUB_REPOSITORY = new URL(REPO).pathname.substring(1); }); afterAll(() => { @@ -67,7 +68,7 @@ describe('Enviromental tests', () => { expect(client.token).toBe(TOKEN); const { owner, repo } = client.owner_repo(); - const parts = GITHUB_REPOSITORY.split('/'); + const parts = process.env.GITHUB_REPOSITORY.split('/'); expect(owner).toBe(parts[0]); expect(repo).toBe(parts[1]); }); diff --git a/src/GitlabClient.js b/src/GitlabClient.js index 462cf1967..4b887468a 100644 --- a/src/GitlabClient.js +++ b/src/GitlabClient.js @@ -104,6 +104,8 @@ class GitlabClient { const url = `${api_v4}${endpoint}`; const response = await fetch(url, { method, headers, body }); + if (response.status > 300) throw new Error(response.statusText); + return await response.json(); } } diff --git a/src/GitlabClient.test.js b/src/GitlabClient.test.js index f560c5d17..3d25ea8ed 100644 --- a/src/GitlabClient.test.js +++ b/src/GitlabClient.test.js @@ -2,9 +2,11 @@ jest.setTimeout(20000); const GitlabClient = require('./GitlabClient'); -const TOKEN = process.env.GITLAB_TOKEN || process.env.repo_token; -const REPO = 'https://gitlab.com/DavidGOrtega/3_tensorboard'; -const SHA = '2dc250a9449728356913e1f0e30758a44da65a12'; +const { + TEST_GITLAB_TOKEN: TOKEN, + TEST_GITLAB_REPO: REPO, + TEST_GITLAB_SHA: SHA +} = process.env; describe('Non Enviromental tests', () => { const client = new GitlabClient({ repo: REPO, token: TOKEN }); diff --git a/src/cml.test.js b/src/cml.test.js index e7bb4dd84..0b2025800 100644 --- a/src/cml.test.js +++ b/src/cml.test.js @@ -3,18 +3,19 @@ const CML = require('./cml'); describe('Github tests', () => { const OLD_ENV = process.env; - const TOKEN = process.env.TEST_GITHUB_TOKEN || process.env.repo_token; - const GITHUB_REPOSITORY = 'DavidGOrtega/3_tensorboard'; - const REPO = `https://github.com/${GITHUB_REPOSITORY}`; - const SHA = 'ee672b3b35c21b440c6fe6890de2fe769fbdbcee'; + const { + TEST_GITHUB_TOKEN: TOKEN, + TEST_GITHUB_REPO: REPO, + TEST_GITHUB_SHA: SHA + } = process.env; beforeEach(() => { jest.resetModules(); process.env = {}; - process.env.GITHUB_REPOSITORY = GITHUB_REPOSITORY; process.env.repo_token = TOKEN; process.env.GITHUB_SHA = SHA; + process.env.GITHUB_REPOSITORY = new URL(REPO).pathname.substring(1); }); afterAll(() => { @@ -84,8 +85,11 @@ describe('Github tests', () => { describe('Gitlab tests', () => { const OLD_ENV = process.env; - const TOKEN = process.env.GITLAB_TOKEN || process.env.repo_token; - const REPO = 'https://gitlab.com/DavidGOrtega/3_tensorboard'; + const { + TEST_GITLAB_TOKEN: TOKEN, + TEST_GITLAB_REPO: REPO, + TEST_GITLAB_SHA: SHA + } = process.env; beforeEach(() => { jest.resetModules(); @@ -93,6 +97,7 @@ describe('Gitlab tests', () => { process.env = {}; process.env.CI_PROJECT_URL = REPO; process.env.repo_token = TOKEN; + process.env.CI_COMMIT_SHA = SHA; }); afterAll(() => { @@ -147,7 +152,12 @@ describe('Gitlab tests', () => { expect(output.endsWith(')')).toBe(true); }); - test.skip('Comment should fail with a unvalid sha', async () => { + test('Comment should succeed with a valid env sha', async () => { + const report = '## Test comment'; + await new CML().comment_create({ report }); + }); + + test('Comment should fail with a unvalid sha', async () => { let catched_err; try { const report = '## Test comment'; @@ -158,6 +168,6 @@ describe('Gitlab tests', () => { catched_err = err.message; } - expect(catched_err).toBe('HttpError: No commit found for SHA: invalid_sha'); + expect(catched_err).toBe('Not Found'); }); }); From 537ede0adbe5fd6da2fe7ace3451b7d2cad15074 Mon Sep 17 00:00:00 2001 From: davidgortega Date: Sat, 17 Oct 2020 23:39:12 +0200 Subject: [PATCH 20/26] workflow eenv --- .github/workflows/publish.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 932f283fb..59c0f6eff 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -3,9 +3,12 @@ name: "Publish CML dockers" on: [push, pull_request] env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} TEST_GITHUB_TOKEN: ${{ secrets.TEST_GITHUB_TOKEN }} - GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }} + TEST_GITHUB_REPO: ${{ secrets.TEST_GITHUB_REPO }} + TEST_GITHUB_SHA: ${{ secrets.TEST_GITHUB_SHA }} + TEST_GITLAB_TOKEN: ${{ secrets.TEST_GITLAB_TOKEN }} + TEST_GITLAB_REPO: ${{ secrets.TEST_GITLAB_REPO }} + TEST_GITLAB_SHA: ${{ secrets.TEST_GITLAB_SHA }} jobs: test_and_deploy: From 07bfccbcf6b8262fd1b53c9d35e43fc538477d5f Mon Sep 17 00:00:00 2001 From: davidgortega Date: Sat, 17 Oct 2020 23:59:54 +0200 Subject: [PATCH 21/26] gitlab uploads and github_token --- .github/workflows/publish.yml | 1 + bin/cml-publish.js | 3 +++ bin/cml-publish.test.js | 20 +------------------- bin/cml-send-comment.js | 3 +++ bin/cml-send-github-check.js | 3 +++ bin/cml-send-github-check.test.js | 16 +--------------- src/cml.js | 11 ++++++----- 7 files changed, 18 insertions(+), 39 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 59c0f6eff..6af0f9f4b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -3,6 +3,7 @@ name: "Publish CML dockers" on: [push, pull_request] env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} TEST_GITHUB_TOKEN: ${{ secrets.TEST_GITHUB_TOKEN }} TEST_GITHUB_REPO: ${{ secrets.TEST_GITHUB_REPO }} TEST_GITHUB_SHA: ${{ secrets.TEST_GITHUB_SHA }} diff --git a/bin/cml-publish.js b/bin/cml-publish.js index 7e2337472..f8e408e29 100644 --- a/bin/cml-publish.js +++ b/bin/cml-publish.js @@ -54,6 +54,9 @@ const argv = yargs 'token', 'Personal access token to be used. If not specified in extracted from ENV repo_token or GITLAB_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; diff --git a/bin/cml-publish.test.js b/bin/cml-publish.test.js index 3a965fe67..a5c704797 100644 --- a/bin/cml-publish.test.js +++ b/bin/cml-publish.test.js @@ -7,25 +7,7 @@ describe('CML e2e', () => { test('cml-publish -h', async () => { const output = await exec(`echo none | node ./bin/cml-publish.js -h`); - expect(output).toMatchInlineSnapshot(` - "Usage: cml-publish.js - - 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. - [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 in - extracted from ENV repo_token or GITLAB_TOKEN. - -h Show help [boolean]" - `); + expect(output).toMatchInlineSnapshot(); }); test('cml-publish assets/logo.png --md', async () => { diff --git a/bin/cml-send-comment.js b/bin/cml-send-comment.js index 5c78935e4..66210db41 100644 --- a/bin/cml-send-comment.js +++ b/bin/cml-send-comment.js @@ -37,6 +37,9 @@ const argv = yargs 'token', 'Personal access token to be used. If not specified in extracted from ENV repo_token.' ) + .default('driver') + .choices('driver', ['github', 'gitlab']) + .describe('driver', 'If not specify it infers it from the ENV.') .help('h') .demand(1).argv; diff --git a/bin/cml-send-github-check.js b/bin/cml-send-github-check.js index aa3a4705c..ce064ef34 100644 --- a/bin/cml-send-github-check.js +++ b/bin/cml-send-github-check.js @@ -45,6 +45,9 @@ const argv = yargs 'token', 'Personal access token to be used. If not specified in extracted from ENV repo_token.' ) + .default('driver') + .choices('driver', ['github', 'gitlab']) + .describe('driver', 'If not specify it infers it from the ENV.') .help('h') .demand(1).argv; diff --git a/bin/cml-send-github-check.test.js b/bin/cml-send-github-check.test.js index bbbcc0ccd..3b36cc3bc 100644 --- a/bin/cml-send-github-check.test.js +++ b/bin/cml-send-github-check.test.js @@ -35,20 +35,6 @@ describe('CML e2e', () => { test('cml-send-github-check -h', async () => { const output = await exec(`node ./bin/cml-send-github-check.js -h`); - expect(output).toMatchInlineSnapshot(` - "Usage: cml-send-github-check.js - - Options: - --version Show version number [boolean] - --head-sha Commit sha where the comment will appear. Defaults to HEAD. - --title Sets title of the check. [default: \\"CML Report\\"] - --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 in extracted - from ENV repo_token. - -h Show help [boolean] - --conclusion[choices: \\"success\\", \\"failure\\", \\"neutral\\", \\"cancelled\\", \\"skipped\\", - \\"timed_out\\"] [default: Sets the conclusion status of the check.]" - `); + expect(output).toMatchInlineSnapshot(); }); }); diff --git a/src/cml.js b/src/cml.js index cc8780d57..6ca088608 100644 --- a/src/cml.js +++ b/src/cml.js @@ -18,10 +18,11 @@ class CML { const { repo } = opts; const { GITHUB_REPOSITORY, CI_PROJECT_URL } = process.env; - if (GITHUB_REPOSITORY || (repo && repo.startsWith('https://github.com'))) - return 'github'; - if (CI_PROJECT_URL || (repo && repo.startsWith('https://gitlab.com'))) - return 'gitlab'; + if (repo && repo.startsWith('https://github.com')) return 'github'; + if (repo && repo.startsWith('https://gitlab.com')) return 'gitlab'; + + if (GITHUB_REPOSITORY) return 'github'; + if (CI_PROJECT_URL) return 'gitlab'; }; const { driver = env_driver(), repo, token } = opts; @@ -46,7 +47,7 @@ class CML { let mime, uri; if (gitlab_uploads) { - const client = get_client(this); + const client = get_client({ ...this, driver: 'gitlab' }); ({ mime, uri } = await client.publish(opts)); } else { ({ mime, uri } = await upload(opts)); From 8735350083736b45186b30c9b87e7c2192e3263c Mon Sep 17 00:00:00 2001 From: davidgortega Date: Sun, 18 Oct 2020 00:07:48 +0200 Subject: [PATCH 22/26] snapshots --- bin/cml-publish.test.js | 22 +++++++++++++++++++++- bin/cml-send-comment.test.js | 2 ++ bin/cml-send-github-check.test.js | 18 +++++++++++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/bin/cml-publish.test.js b/bin/cml-publish.test.js index a5c704797..0537b6bd6 100644 --- a/bin/cml-publish.test.js +++ b/bin/cml-publish.test.js @@ -7,7 +7,27 @@ describe('CML e2e', () => { test('cml-publish -h', async () => { const output = await exec(`echo none | node ./bin/cml-publish.js -h`); - expect(output).toMatchInlineSnapshot(); + expect(output).toMatchInlineSnapshot(` + "Usage: cml-publish.js + + 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. + [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 in + 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]" + `); }); test('cml-publish assets/logo.png --md', async () => { diff --git a/bin/cml-send-comment.test.js b/bin/cml-send-comment.test.js index de083d5a2..89f2fe66d 100644 --- a/bin/cml-send-comment.test.js +++ b/bin/cml-send-comment.test.js @@ -27,6 +27,8 @@ describe('Comment integration tests', () => { from the CI ENV. --token Personal access token to be used. If not specified in extracted from ENV repo_token. + --driver If not specify it infers it from the ENV. + [choices: \\"github\\", \\"gitlab\\"] -h Show help [boolean]" `); }); diff --git a/bin/cml-send-github-check.test.js b/bin/cml-send-github-check.test.js index 3b36cc3bc..91405a6da 100644 --- a/bin/cml-send-github-check.test.js +++ b/bin/cml-send-github-check.test.js @@ -35,6 +35,22 @@ describe('CML e2e', () => { test('cml-send-github-check -h', async () => { const output = await exec(`node ./bin/cml-send-github-check.js -h`); - expect(output).toMatchInlineSnapshot(); + expect(output).toMatchInlineSnapshot(` + "Usage: cml-send-github-check.js + + Options: + --version Show version number [boolean] + --head-sha Commit sha where the comment will appear. Defaults to HEAD. + --title Sets title of the check. [default: \\"CML Report\\"] + --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 in extracted + from ENV repo_token. + --driver If not specify it infers it from the ENV. + [choices: \\"github\\", \\"gitlab\\"] + -h Show help [boolean] + --conclusion[choices: \\"success\\", \\"failure\\", \\"neutral\\", \\"cancelled\\", \\"skipped\\", + \\"timed_out\\"] [default: Sets the conclusion status of the check.]" + `); }); }); From f23765de0c2a45d3d1cfb2e0420ef5f26e8bb2e0 Mon Sep 17 00:00:00 2001 From: davidgortega Date: Tue, 20 Oct 2020 18:31:18 +0200 Subject: [PATCH 23/26] log env --- src/GithubClient.test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/GithubClient.test.js b/src/GithubClient.test.js index d7fce4966..ddccfce32 100644 --- a/src/GithubClient.test.js +++ b/src/GithubClient.test.js @@ -50,6 +50,8 @@ describe('Enviromental tests', () => { process.env.repo_token = TOKEN; process.env.GITHUB_SHA = SHA; process.env.GITHUB_REPOSITORY = new URL(REPO).pathname.substring(1); + + console.log(process.env); }); afterAll(() => { @@ -59,7 +61,6 @@ describe('Enviromental tests', () => { test('Env', async () => { const client = new GithubClient({}); - expect(client.env_is_pr()).toBe(false); expect(client.env_head_sha()).toBe(SHA); expect(client.env_repo()).toBe(REPO); expect(client.env_token()).toBe(TOKEN); From 7b2f0a0bccf332255db5fbcff79956a46a305e92 Mon Sep 17 00:00:00 2001 From: davidgortega Date: Tue, 20 Oct 2020 18:33:28 +0200 Subject: [PATCH 24/26] log env --- src/GithubClient.test.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/GithubClient.test.js b/src/GithubClient.test.js index ddccfce32..ac73b026c 100644 --- a/src/GithubClient.test.js +++ b/src/GithubClient.test.js @@ -50,8 +50,6 @@ describe('Enviromental tests', () => { process.env.repo_token = TOKEN; process.env.GITHUB_SHA = SHA; process.env.GITHUB_REPOSITORY = new URL(REPO).pathname.substring(1); - - console.log(process.env); }); afterAll(() => { @@ -75,6 +73,7 @@ describe('Enviromental tests', () => { }); test('Comment', async () => { + console.log(process.env); const client = new GithubClient({}); const report = '## Test comment'; From abdce430d7d50fe01dc5976a0fa9761b4cda23d7 Mon Sep 17 00:00:00 2001 From: davidgortega Date: Tue, 20 Oct 2020 19:56:07 +0200 Subject: [PATCH 25/26] update also github.context --- src/GithubClient.test.js | 6 ++++++ src/GitlabClient.test.js | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/GithubClient.test.js b/src/GithubClient.test.js index ac73b026c..762415e3d 100644 --- a/src/GithubClient.test.js +++ b/src/GithubClient.test.js @@ -1,6 +1,7 @@ jest.setTimeout(20000); const GithubClient = require('./GithubClient'); +const github = require('@actions/github'); const { TEST_GITHUB_TOKEN: TOKEN, @@ -49,6 +50,11 @@ describe('Enviromental tests', () => { process.env = {}; process.env.repo_token = TOKEN; process.env.GITHUB_SHA = SHA; + + try { + github.context.payload.pull_request.head.sha = SHA; + } catch (err) {} + process.env.GITHUB_REPOSITORY = new URL(REPO).pathname.substring(1); }); diff --git a/src/GitlabClient.test.js b/src/GitlabClient.test.js index 3d25ea8ed..2714af9eb 100644 --- a/src/GitlabClient.test.js +++ b/src/GitlabClient.test.js @@ -64,7 +64,6 @@ describe('Enviromental tests', () => { test('Env', async () => { const client = new GitlabClient(); - expect(client.env_is_pr()).toBe(false); expect(client.env_head_sha()).toBe(SHA); expect(client.env_repo()).toBe(REPO); expect(client.env_token()).toBe(TOKEN); From ce0424916f3b55e7f584605ed3332053067507f9 Mon Sep 17 00:00:00 2001 From: DavidGOrtega Date: Wed, 21 Oct 2020 17:17:54 +0200 Subject: [PATCH 26/26] No log --- src/GithubClient.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/GithubClient.test.js b/src/GithubClient.test.js index 762415e3d..eb05fdf1d 100644 --- a/src/GithubClient.test.js +++ b/src/GithubClient.test.js @@ -79,7 +79,6 @@ describe('Enviromental tests', () => { }); test('Comment', async () => { - console.log(process.env); const client = new GithubClient({}); const report = '## Test comment';