From 6febcf41dd33c29df9556de1576e31d229fadd72 Mon Sep 17 00:00:00 2001 From: JB Pinalie <2850825+jybp@users.noreply.github.com> Date: Mon, 8 Feb 2021 15:27:54 +0100 Subject: [PATCH 1/7] .mjs.map --- src/commands/sourcemaps/upload.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/sourcemaps/upload.ts b/src/commands/sourcemaps/upload.ts index f6bc91ae3..740dde816 100644 --- a/src/commands/sourcemaps/upload.ts +++ b/src/commands/sourcemaps/upload.ts @@ -114,7 +114,7 @@ export class UploadCommand extends Command { } private getMatchingSourcemapFiles(): Payload[] { - const sourcemapFiles = glob.sync(buildPath(this.basePath!, '**/*.js.map')) + const sourcemapFiles = glob.sync(buildPath(this.basePath!, '**/*js.map')) return sourcemapFiles.map((sourcemapPath) => { const minifiedFilePath = getMinifiedFilePath(sourcemapPath) From 277945f4899d73f005cafff5b156a7bf0f4c9578 Mon Sep 17 00:00:00 2001 From: JB Pinalie <2850825+jybp@users.noreply.github.com> Date: Wed, 10 Feb 2021 18:01:46 +0100 Subject: [PATCH 2/7] Add mjs test case --- src/commands/sourcemaps/__tests__/mjs/common.mjs | 0 .../sourcemaps/__tests__/mjs/common.mjs.map | 0 src/commands/sourcemaps/__tests__/upload.test.ts | 16 ++++++++++++++++ 3 files changed, 16 insertions(+) create mode 100644 src/commands/sourcemaps/__tests__/mjs/common.mjs create mode 100644 src/commands/sourcemaps/__tests__/mjs/common.mjs.map diff --git a/src/commands/sourcemaps/__tests__/mjs/common.mjs b/src/commands/sourcemaps/__tests__/mjs/common.mjs new file mode 100644 index 000000000..e69de29bb diff --git a/src/commands/sourcemaps/__tests__/mjs/common.mjs.map b/src/commands/sourcemaps/__tests__/mjs/common.mjs.map new file mode 100644 index 000000000..e69de29bb diff --git a/src/commands/sourcemaps/__tests__/upload.test.ts b/src/commands/sourcemaps/__tests__/upload.test.ts index d5fb7a977..d294fc49d 100644 --- a/src/commands/sourcemaps/__tests__/upload.test.ts +++ b/src/commands/sourcemaps/__tests__/upload.test.ts @@ -154,6 +154,22 @@ describe('execute', () => { version: '1234', }) }) + + test('using the mjs extension', async () => { + const {context, code} = await runCLI('./src/commands/sourcemaps/__tests__/mjs') + const output = context.stdout.toString().split(os.EOL) + expect(code).toBe(0) + checkConsoleOutput(output, { + basePath: 'src/commands/sourcemaps/__tests__/mjs', + concurrency: 20, + jsFilesURLs: ['https://static.com/js/common.mjs'], + minifiedPathPrefix: 'https://static.com/js', + projectPath: '', + service: 'test-service', + sourcemapsPaths: ['src/commands/sourcemaps/__tests__/mjs/common.mjs.map'], + version: '1234', + }) + }) }) const makeCli = () => { From d5b4ccfe9324bcf4a0be072c1c23cc09bf31cb6c Mon Sep 17 00:00:00 2001 From: Mathieu Rousse Date: Thu, 11 Feb 2021 12:07:28 +0100 Subject: [PATCH 3/7] [ci] use immutable installs to detect outdated yarn.lock --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 51c53eb29..c2994085b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: uses: actions/setup-node@v1 with: node-version: '12.x' - - run: yarn install + - run: yarn install --immutable - run: yarn build - run: yarn prettier-check - run: yarn lint From f8dd627206276c72c12e9fb90561874405c26efe Mon Sep 17 00:00:00 2001 From: JB Pinalie <2850825+jybp@users.noreply.github.com> Date: Mon, 15 Feb 2021 11:46:47 +0100 Subject: [PATCH 4/7] Add git fields --- src/commands/sourcemaps/api.ts | 10 ++++++++-- src/commands/sourcemaps/interfaces.ts | 4 +++- src/commands/sourcemaps/upload.ts | 4 +++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/commands/sourcemaps/api.ts b/src/commands/sourcemaps/api.ts index ce9af0720..584f2ec05 100644 --- a/src/commands/sourcemaps/api.ts +++ b/src/commands/sourcemaps/api.ts @@ -26,8 +26,14 @@ export const uploadSourcemap = (request: (args: AxiosRequestConfig) => AxiosProm form.append('minified_url', sourcemap.minifiedUrl) form.append('project_path', sourcemap.projectPath) form.append('type', 'js_sourcemap') - if (sourcemap.repository) { - form.append('repository', sourcemap.repository, {filename: 'repository', contentType: 'application/json'}) + if (sourcemap.repositoryPayload) { + form.append('repository', sourcemap.repositoryPayload, {filename: 'repository', contentType: 'application/json'}) + } + if (sourcemap.repositoryURL) { + form.append('git_repository_url', sourcemap.repositoryURL) + } + if (sourcemap.commitSha) { + form.append('git_commit_sha', sourcemap.commitSha) } return request({ diff --git a/src/commands/sourcemaps/interfaces.ts b/src/commands/sourcemaps/interfaces.ts index 251f21998..9d0e57aba 100644 --- a/src/commands/sourcemaps/interfaces.ts +++ b/src/commands/sourcemaps/interfaces.ts @@ -7,7 +7,9 @@ export interface Payload { minifiedUrl: string overwrite?: boolean projectPath: string - repository?: string + repositoryPayload?: string + repositoryURL?: string + commitSha?: string service: string sourcemapPath: string version: string diff --git a/src/commands/sourcemaps/upload.ts b/src/commands/sourcemaps/upload.ts index 5973d1ca2..fc41450d8 100644 --- a/src/commands/sourcemaps/upload.ts +++ b/src/commands/sourcemaps/upload.ts @@ -117,7 +117,9 @@ export class UploadCommand extends Command { } await Promise.all( payloads.map(async (payload) => { - payload.repository = this.getRepositoryPayload(repositoryData, payload.sourcemapPath) + payload.repositoryPayload = this.getRepositoryPayload(repositoryData, payload.sourcemapPath) + payload.repositoryURL = repositoryData.remote + payload.commitSha = repositoryData.hash }) ) } From 1141bfb8944890752860afa485028e876bfcc026 Mon Sep 17 00:00:00 2001 From: Ronan Pelliard Date: Mon, 15 Feb 2021 12:30:58 +0100 Subject: [PATCH 5/7] v0.10.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2518be5c5..2817833fc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@datadog/datadog-ci", - "version": "0.10.2", + "version": "0.10.3", "description": "Run datadog actions from the CI.", "main": "dist/index.js", "repository": "https://github.com/DataDog/datadog-ci", From c1ffb9821a98321361c8a151ac9993f2db0659c7 Mon Sep 17 00:00:00 2001 From: JB Pinalie <2850825+jybp@users.noreply.github.com> Date: Mon, 15 Feb 2021 12:45:44 +0100 Subject: [PATCH 6/7] Add test cases --- .../__tests__/fixtures-empty/empty.min.js | 0 .../__tests__/fixtures-empty/empty.min.js.map | 3 ++ .../sourcemaps/__tests__/upload.test.ts | 41 +++++++++++++++++++ src/commands/sourcemaps/api.ts | 12 +++--- src/commands/sourcemaps/interfaces.ts | 6 +-- src/commands/sourcemaps/upload.ts | 6 +-- 6 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 src/commands/sourcemaps/__tests__/fixtures-empty/empty.min.js create mode 100644 src/commands/sourcemaps/__tests__/fixtures-empty/empty.min.js.map diff --git a/src/commands/sourcemaps/__tests__/fixtures-empty/empty.min.js b/src/commands/sourcemaps/__tests__/fixtures-empty/empty.min.js new file mode 100644 index 000000000..e69de29bb diff --git a/src/commands/sourcemaps/__tests__/fixtures-empty/empty.min.js.map b/src/commands/sourcemaps/__tests__/fixtures-empty/empty.min.js.map new file mode 100644 index 000000000..bbd59ea51 --- /dev/null +++ b/src/commands/sourcemaps/__tests__/fixtures-empty/empty.min.js.map @@ -0,0 +1,3 @@ +{ + "sources": [] +} \ No newline at end of file diff --git a/src/commands/sourcemaps/__tests__/upload.test.ts b/src/commands/sourcemaps/__tests__/upload.test.ts index d5fb7a977..a9bb226ac 100644 --- a/src/commands/sourcemaps/__tests__/upload.test.ts +++ b/src/commands/sourcemaps/__tests__/upload.test.ts @@ -2,6 +2,7 @@ import os from 'os' import {Cli} from 'clipanion/lib/advanced' +import {Payload} from '../interfaces' import {UploadCommand} from '../upload' describe('upload', () => { @@ -81,6 +82,46 @@ describe('upload', () => { expect(write.mock.calls[0][0]).toContain('DATADOG_API_KEY') }) }) + + describe('addRepositoryDataToPayloads', () => { + test('repository url and commit still defined without payload', async () => { + const command = new UploadCommand() + const write = jest.fn() + command.context = {stdout: {write}} as any + const payloads = new Array({ + cliVersion: '0.0.1', + minifiedFilePath: 'src/commands/sourcemaps/__tests__/fixtures-empty/empty.min.js', + minifiedUrl: 'http://example/empty.min.js', + projectPath: '', + service: 'svc', + sourcemapPath: 'src/commands/sourcemaps/__tests__/fixtures-empty/empty.min.js.map', + version: '1.2.3', + }) + await command['addRepositoryDataToPayloads'](payloads) + expect(payloads[0].gitRepositoryURL).toBeDefined() + expect(payloads[0].gitCommitSha).toHaveLength(40) + expect(payloads[0].gitRepositoryPayload).toBeUndefined() + }) + + test('should include payload', async () => { + const command = new UploadCommand() + const write = jest.fn() + command.context = {stdout: {write}} as any + const payloads = new Array({ + cliVersion: '0.0.1', + minifiedFilePath: 'src/commands/sourcemaps/__tests__/fixtures/common.min.js', + minifiedUrl: 'http://example/common.min.js', + projectPath: '', + service: 'svc', + sourcemapPath: 'src/commands/sourcemaps/__tests__/fixtures/common.min.js.map', + version: '1.2.3', + }) + await command['addRepositoryDataToPayloads'](payloads) + expect(payloads[0].gitRepositoryURL).toBeDefined() + expect(payloads[0].gitCommitSha).toHaveLength(40) + expect(payloads[0].gitRepositoryPayload).toBeDefined() + }) + }) }) describe('execute', () => { diff --git a/src/commands/sourcemaps/api.ts b/src/commands/sourcemaps/api.ts index 584f2ec05..aa472b8ad 100644 --- a/src/commands/sourcemaps/api.ts +++ b/src/commands/sourcemaps/api.ts @@ -26,14 +26,14 @@ export const uploadSourcemap = (request: (args: AxiosRequestConfig) => AxiosProm form.append('minified_url', sourcemap.minifiedUrl) form.append('project_path', sourcemap.projectPath) form.append('type', 'js_sourcemap') - if (sourcemap.repositoryPayload) { - form.append('repository', sourcemap.repositoryPayload, {filename: 'repository', contentType: 'application/json'}) + if (sourcemap.gitRepositoryPayload) { + form.append('repository', sourcemap.gitRepositoryPayload, {filename: 'repository', contentType: 'application/json'}) } - if (sourcemap.repositoryURL) { - form.append('git_repository_url', sourcemap.repositoryURL) + if (sourcemap.gitRepositoryURL) { + form.append('git_repository_url', sourcemap.gitRepositoryURL) } - if (sourcemap.commitSha) { - form.append('git_commit_sha', sourcemap.commitSha) + if (sourcemap.gitCommitSha) { + form.append('git_commit_sha', sourcemap.gitCommitSha) } return request({ diff --git a/src/commands/sourcemaps/interfaces.ts b/src/commands/sourcemaps/interfaces.ts index 9d0e57aba..36d6fa97d 100644 --- a/src/commands/sourcemaps/interfaces.ts +++ b/src/commands/sourcemaps/interfaces.ts @@ -3,13 +3,13 @@ import {Writable} from 'stream' export interface Payload { cliVersion: string + gitCommitSha?: string + gitRepositoryPayload?: string + gitRepositoryURL?: string minifiedFilePath: string minifiedUrl: string overwrite?: boolean projectPath: string - repositoryPayload?: string - repositoryURL?: string - commitSha?: string service: string sourcemapPath: string version: string diff --git a/src/commands/sourcemaps/upload.ts b/src/commands/sourcemaps/upload.ts index fc41450d8..39cb88fa0 100644 --- a/src/commands/sourcemaps/upload.ts +++ b/src/commands/sourcemaps/upload.ts @@ -117,9 +117,9 @@ export class UploadCommand extends Command { } await Promise.all( payloads.map(async (payload) => { - payload.repositoryPayload = this.getRepositoryPayload(repositoryData, payload.sourcemapPath) - payload.repositoryURL = repositoryData.remote - payload.commitSha = repositoryData.hash + payload.gitRepositoryPayload = this.getRepositoryPayload(repositoryData, payload.sourcemapPath) + payload.gitRepositoryURL = repositoryData.remote + payload.gitCommitSha = repositoryData.hash }) ) } From 9d252a2e2c5ef90579e282a83004918f3193d5fd Mon Sep 17 00:00:00 2001 From: JB Pinalie <2850825+jybp@users.noreply.github.com> Date: Mon, 15 Feb 2021 17:53:55 +0100 Subject: [PATCH 7/7] Run yarn --- yarn.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn.lock b/yarn.lock index aa7bdd713..a617ea480 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4909,7 +4909,7 @@ signal-exit@^3.0.0, signal-exit@^3.0.2: resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d" integrity sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0= -simple-git@^2.31.0: +simple-git@2.31.0: version "2.31.0" resolved "https://registry.yarnpkg.com/simple-git/-/simple-git-2.31.0.tgz#3e5954c1e36c76fb382c08eaa2749a206db9f613" integrity sha512-/+rmE7dYZMbRAfEmn8EUIOwlM2G7UdzpkC60KF86YAfXGnmGtsPrKsym0hKvLBdFLLW019C+aZld1+6iIVy5xA==