@datadog/datadog-ci 0.18.0 → 0.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/git-metadata/__tests__/git.test.js +44 -2
- package/dist/commands/git-metadata/__tests__/library.test.d.ts +1 -0
- package/dist/commands/git-metadata/__tests__/library.test.js +82 -0
- package/dist/commands/git-metadata/git.d.ts +1 -2
- package/dist/commands/git-metadata/git.js +13 -25
- package/dist/commands/git-metadata/index.d.ts +1 -0
- package/dist/commands/git-metadata/index.js +13 -0
- package/dist/commands/git-metadata/library.d.ts +6 -0
- package/dist/commands/git-metadata/library.js +68 -0
- package/dist/commands/git-metadata/upload.d.ts +1 -2
- package/dist/commands/git-metadata/upload.js +31 -27
- package/dist/commands/lambda/__tests__/instrument.test.js +1 -1
- package/dist/commands/lambda/instrument.js +1 -1
- package/dist/commands/synthetics/__tests__/utils.test.js +26 -0
- package/dist/commands/synthetics/crypto.d.ts +2 -1
- package/dist/commands/synthetics/interfaces.d.ts +4 -1
- package/dist/commands/synthetics/utils.d.ts +1 -0
- package/dist/commands/synthetics/utils.js +8 -4
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/package.json +1 -1
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
2
21
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
22
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
23
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -9,6 +28,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
28
|
});
|
|
10
29
|
};
|
|
11
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
const simpleGit = __importStar(require("simple-git"));
|
|
12
32
|
const git_1 = require("../git");
|
|
13
33
|
const createMockSimpleGit = (conf) => ({
|
|
14
34
|
getRemotes: (_) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -84,7 +104,7 @@ describe('git', () => {
|
|
|
84
104
|
remotes: [{ name: 'first', refs: { push: 'https://git-repo' } }],
|
|
85
105
|
trackedFiles: ['myfile.js'],
|
|
86
106
|
});
|
|
87
|
-
const commitInfo = yield git_1.getCommitInfo(mock
|
|
107
|
+
const commitInfo = yield git_1.getCommitInfo(mock);
|
|
88
108
|
expect(commitInfo).toBeDefined();
|
|
89
109
|
expect(commitInfo.hash).toBe('abcd');
|
|
90
110
|
expect(commitInfo.trackedFiles).toStrictEqual(['myfile.js']);
|
|
@@ -95,11 +115,33 @@ describe('git', () => {
|
|
|
95
115
|
hash: 'abcd',
|
|
96
116
|
trackedFiles: ['myfile.js'],
|
|
97
117
|
});
|
|
98
|
-
const commitInfo = yield git_1.getCommitInfo(mock,
|
|
118
|
+
const commitInfo = yield git_1.getCommitInfo(mock, 'https://overridden');
|
|
99
119
|
expect(commitInfo).toBeDefined();
|
|
100
120
|
expect(commitInfo.hash).toBe('abcd');
|
|
101
121
|
expect(commitInfo.trackedFiles).toStrictEqual(['myfile.js']);
|
|
102
122
|
expect(commitInfo.remote).toBe('https://overridden');
|
|
103
123
|
}));
|
|
104
124
|
});
|
|
125
|
+
describe('newSimpleGit', () => {
|
|
126
|
+
test('should throw an error if git is not installed', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
127
|
+
jest.spyOn(simpleGit, 'gitP').mockImplementation(() => {
|
|
128
|
+
throw Error('gitp error');
|
|
129
|
+
});
|
|
130
|
+
yield expect(git_1.newSimpleGit()).rejects.toThrow('gitp error');
|
|
131
|
+
}));
|
|
132
|
+
test('should throw an error if revparse throws an error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
133
|
+
const mock = createMockSimpleGit({});
|
|
134
|
+
jest.spyOn(simpleGit, 'gitP').mockReturnValue(mock);
|
|
135
|
+
jest.spyOn(mock, 'revparse').mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
136
|
+
throw Error('revparse error');
|
|
137
|
+
}));
|
|
138
|
+
yield expect(git_1.newSimpleGit()).rejects.toThrow('revparse error');
|
|
139
|
+
}));
|
|
140
|
+
test('should not throw any errors', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
141
|
+
const mock = createMockSimpleGit({});
|
|
142
|
+
jest.spyOn(simpleGit, 'gitP').mockReturnValue(mock);
|
|
143
|
+
jest.spyOn(mock, 'revparse').mockResolvedValue('1234');
|
|
144
|
+
yield expect(git_1.newSimpleGit()).resolves.not.toThrow();
|
|
145
|
+
}));
|
|
146
|
+
});
|
|
105
147
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
const apikey = __importStar(require("../../../helpers/apikey"));
|
|
32
|
+
const upload = __importStar(require("../../../helpers/upload"));
|
|
33
|
+
const git = __importStar(require("../git"));
|
|
34
|
+
const interfaces_1 = require("../interfaces");
|
|
35
|
+
const library_1 = require("../library");
|
|
36
|
+
describe('library', () => {
|
|
37
|
+
describe('isGitRepo', () => {
|
|
38
|
+
test('should return false if checkIsRepo fails', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
const simpleGitClient = {
|
|
40
|
+
checkIsRepo: () => {
|
|
41
|
+
throw Error();
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
jest.spyOn(git, 'newSimpleGit').mockResolvedValue(simpleGitClient);
|
|
45
|
+
yield expect(library_1.isGitRepo()).resolves.toEqual(false);
|
|
46
|
+
}));
|
|
47
|
+
test('should return false git is not installed', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
48
|
+
jest.spyOn(git, 'newSimpleGit').mockImplementation(() => {
|
|
49
|
+
throw new Error('git is not installed');
|
|
50
|
+
});
|
|
51
|
+
yield expect(library_1.isGitRepo()).resolves.toEqual(false);
|
|
52
|
+
}));
|
|
53
|
+
test('should return true if datadog API key is set, git is installed, and we are in a repo', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
+
const simpleGitClient = { checkIsRepo: () => true };
|
|
55
|
+
jest.spyOn(git, 'newSimpleGit').mockResolvedValue(simpleGitClient);
|
|
56
|
+
yield expect(library_1.isGitRepo()).resolves.toEqual(true);
|
|
57
|
+
}));
|
|
58
|
+
});
|
|
59
|
+
describe('addSourceCodeIntegration', () => {
|
|
60
|
+
test('source code integration fails if simpleGitOrFail throws an exception', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
|
+
jest.spyOn(git, 'newSimpleGit').mockImplementation(() => {
|
|
62
|
+
throw new Error('git is not installed');
|
|
63
|
+
});
|
|
64
|
+
jest.spyOn(apikey, 'newApiKeyValidator').mockReturnValue({});
|
|
65
|
+
yield expect(library_1.uploadGitCommitHash('dummy', 'fake.site')).rejects.toThrowError('git is not installed');
|
|
66
|
+
}));
|
|
67
|
+
test('source code integration returns the correct hash', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
+
const simpleGitClient = { checkIsRepo: () => true };
|
|
69
|
+
jest.spyOn(git, 'newSimpleGit').mockResolvedValue(simpleGitClient);
|
|
70
|
+
jest.spyOn(git, 'getCommitInfo').mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return new interfaces_1.CommitInfo('hash', 'url', ['file1', 'file2']); }));
|
|
71
|
+
jest.spyOn(upload, 'upload').mockReturnValue((a, b) => {
|
|
72
|
+
{
|
|
73
|
+
return new Promise((resolve) => {
|
|
74
|
+
resolve(upload.UploadStatus.Success);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
jest.spyOn(apikey, 'newApiKeyValidator').mockReturnValue({});
|
|
79
|
+
expect(yield library_1.uploadGitCommitHash('dummy', 'fake.site')).toBe('hash');
|
|
80
|
+
}));
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import * as simpleGit from 'simple-git';
|
|
2
|
-
import { Writable } from 'stream';
|
|
3
2
|
import { CommitInfo } from './interfaces';
|
|
4
3
|
export declare const newSimpleGit: () => Promise<simpleGit.SimpleGit>;
|
|
5
4
|
export declare const gitRemote: (git: simpleGit.SimpleGit) => Promise<string>;
|
|
6
5
|
export declare const stripCredentials: (remote: string) => string;
|
|
7
6
|
export declare const gitTrackedFiles: (git: simpleGit.SimpleGit) => Promise<string[]>;
|
|
8
|
-
export declare const getCommitInfo: (git: simpleGit.SimpleGit,
|
|
7
|
+
export declare const getCommitInfo: (git: simpleGit.SimpleGit, repositoryURL?: string | undefined) => Promise<CommitInfo>;
|
|
@@ -31,7 +31,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
31
31
|
exports.getCommitInfo = exports.gitTrackedFiles = exports.stripCredentials = exports.gitRemote = exports.newSimpleGit = void 0;
|
|
32
32
|
const simpleGit = __importStar(require("simple-git"));
|
|
33
33
|
const url_1 = require("url");
|
|
34
|
-
const renderer_1 = require("./renderer");
|
|
35
34
|
const interfaces_1 = require("./interfaces");
|
|
36
35
|
// Returns a configured SimpleGit.
|
|
37
36
|
const newSimpleGit = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -40,16 +39,11 @@ const newSimpleGit = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
40
39
|
binary: 'git',
|
|
41
40
|
maxConcurrentProcesses: 1,
|
|
42
41
|
};
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
options.baseDir = root;
|
|
49
|
-
}
|
|
50
|
-
catch (_a) {
|
|
51
|
-
// Ignore exception as it will fail if we are not inside a git repository.
|
|
52
|
-
}
|
|
42
|
+
// Attempt to set the baseDir to the root of the repository so the 'git ls-files' command
|
|
43
|
+
// returns the tracked files paths relative to the root of the repository.
|
|
44
|
+
const git = simpleGit.gitP(options);
|
|
45
|
+
const root = yield git.revparse('--show-toplevel');
|
|
46
|
+
options.baseDir = root;
|
|
53
47
|
return simpleGit.gitP(options);
|
|
54
48
|
});
|
|
55
49
|
exports.newSimpleGit = newSimpleGit;
|
|
@@ -91,27 +85,21 @@ const gitTrackedFiles = (git) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
91
85
|
});
|
|
92
86
|
exports.gitTrackedFiles = gitTrackedFiles;
|
|
93
87
|
// Returns the current hash, remote URL and tracked files paths.
|
|
94
|
-
const getCommitInfo = (git,
|
|
88
|
+
const getCommitInfo = (git, repositoryURL) => __awaiter(void 0, void 0, void 0, function* () {
|
|
95
89
|
// Invoke git commands to retrieve the remote, hash and tracked files.
|
|
96
90
|
// We're using Promise.all instead of Promive.allSettled since we want to fail early if
|
|
97
91
|
// any of the promises fails.
|
|
98
92
|
let remote;
|
|
99
93
|
let hash;
|
|
100
94
|
let trackedFiles;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
remote = repositoryURL;
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
;
|
|
109
|
-
[remote, hash, trackedFiles] = yield Promise.all([exports.gitRemote(git), gitHash(git), exports.gitTrackedFiles(git)]);
|
|
110
|
-
}
|
|
95
|
+
if (repositoryURL) {
|
|
96
|
+
;
|
|
97
|
+
[hash, trackedFiles] = yield Promise.all([gitHash(git), exports.gitTrackedFiles(git)]);
|
|
98
|
+
remote = repositoryURL;
|
|
111
99
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
100
|
+
else {
|
|
101
|
+
;
|
|
102
|
+
[remote, hash, trackedFiles] = yield Promise.all([exports.gitRemote(git), gitHash(git), exports.gitTrackedFiles(git)]);
|
|
115
103
|
}
|
|
116
104
|
return new interfaces_1.CommitInfo(hash, remote, trackedFiles);
|
|
117
105
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './library';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./library"), exports);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { RequestBuilder } from '../../helpers/interfaces';
|
|
2
|
+
import { UploadOptions, UploadStatus } from '../../helpers/upload';
|
|
3
|
+
import { CommitInfo } from './interfaces';
|
|
4
|
+
export declare const isGitRepo: () => Promise<boolean>;
|
|
5
|
+
export declare const uploadGitCommitHash: (apiKey: string, datadogSite: string) => Promise<string>;
|
|
6
|
+
export declare const uploadRepository: (requestBuilder: RequestBuilder, libraryVersion: string) => (commitInfo: CommitInfo, opts: UploadOptions) => Promise<UploadStatus>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.uploadRepository = exports.uploadGitCommitHash = exports.isGitRepo = void 0;
|
|
13
|
+
const apikey_1 = require("../../helpers/apikey");
|
|
14
|
+
const upload_1 = require("../../helpers/upload");
|
|
15
|
+
const utils_1 = require("../../helpers/utils");
|
|
16
|
+
const git_1 = require("./git");
|
|
17
|
+
const isGitRepo = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
try {
|
|
19
|
+
const simpleGit = yield git_1.newSimpleGit();
|
|
20
|
+
const isRepo = simpleGit.checkIsRepo();
|
|
21
|
+
return isRepo;
|
|
22
|
+
}
|
|
23
|
+
catch (_a) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
exports.isGitRepo = isGitRepo;
|
|
28
|
+
const uploadGitCommitHash = (apiKey, datadogSite) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
+
const apiKeyValidator = apikey_1.newApiKeyValidator({
|
|
30
|
+
apiKey,
|
|
31
|
+
datadogSite,
|
|
32
|
+
});
|
|
33
|
+
const simpleGit = yield git_1.newSimpleGit();
|
|
34
|
+
const payload = yield git_1.getCommitInfo(simpleGit);
|
|
35
|
+
const version = require('../../../package.json').version;
|
|
36
|
+
const requestBuilder = utils_1.getRequestBuilder({
|
|
37
|
+
apiKey,
|
|
38
|
+
baseUrl: 'https://sourcemap-intake.' + datadogSite,
|
|
39
|
+
headers: new Map([
|
|
40
|
+
['DD-EVP-ORIGIN', 'datadog-ci sci'],
|
|
41
|
+
['DD-EVP-ORIGIN-VERSION', version],
|
|
42
|
+
]),
|
|
43
|
+
overrideUrl: 'api/v2/srcmap',
|
|
44
|
+
});
|
|
45
|
+
const status = yield exports.uploadRepository(requestBuilder, version)(payload, {
|
|
46
|
+
apiKeyValidator,
|
|
47
|
+
onError: (e) => {
|
|
48
|
+
throw e;
|
|
49
|
+
},
|
|
50
|
+
onRetry: () => {
|
|
51
|
+
// Do nothing
|
|
52
|
+
},
|
|
53
|
+
onUpload: () => {
|
|
54
|
+
return;
|
|
55
|
+
},
|
|
56
|
+
retries: 5,
|
|
57
|
+
});
|
|
58
|
+
if (status !== upload_1.UploadStatus.Success) {
|
|
59
|
+
throw new Error('Error uploading commit information.');
|
|
60
|
+
}
|
|
61
|
+
return payload.hash;
|
|
62
|
+
});
|
|
63
|
+
exports.uploadGitCommitHash = uploadGitCommitHash;
|
|
64
|
+
const uploadRepository = (requestBuilder, libraryVersion) => (commitInfo, opts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
+
const payload = commitInfo.asMultipartPayload(libraryVersion);
|
|
66
|
+
return upload_1.upload(requestBuilder)(payload, opts);
|
|
67
|
+
});
|
|
68
|
+
exports.uploadRepository = uploadRepository;
|
|
@@ -23,6 +23,7 @@ const upload_1 = require("../../helpers/upload");
|
|
|
23
23
|
const utils_1 = require("../../helpers/utils");
|
|
24
24
|
const api_1 = require("./api");
|
|
25
25
|
const git_1 = require("./git");
|
|
26
|
+
const library_1 = require("./library");
|
|
26
27
|
const renderer_1 = require("./renderer");
|
|
27
28
|
class UploadCommand extends clipanion_1.Command {
|
|
28
29
|
constructor() {
|
|
@@ -49,28 +50,40 @@ class UploadCommand extends clipanion_1.Command {
|
|
|
49
50
|
datadogSite: api_1.datadogSite,
|
|
50
51
|
metricsLogger: metricsLogger.logger,
|
|
51
52
|
});
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
let payload;
|
|
54
|
+
try {
|
|
55
|
+
payload = yield git_1.getCommitInfo(yield git_1.newSimpleGit(), this.repositoryURL);
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
if (e instanceof Error) {
|
|
59
|
+
this.context.stdout.write(renderer_1.renderFailedUpload(e.message));
|
|
60
|
+
}
|
|
61
|
+
return;
|
|
55
62
|
}
|
|
56
63
|
this.context.stdout.write(renderer_1.renderCommandInfo(payload));
|
|
64
|
+
let status;
|
|
57
65
|
try {
|
|
58
66
|
const requestBuilder = this.getRequestBuilder();
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
if (this.dryRun) {
|
|
68
|
+
status = upload_1.UploadStatus.Success;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
status = yield library_1.uploadRepository(requestBuilder, this.cliVersion)(payload, {
|
|
72
|
+
apiKeyValidator,
|
|
73
|
+
onError: (e) => {
|
|
74
|
+
this.context.stdout.write(renderer_1.renderFailedUpload(e.message));
|
|
75
|
+
metricsLogger.logger.increment('failed', 1);
|
|
76
|
+
},
|
|
77
|
+
onRetry: (e, attempt) => {
|
|
78
|
+
this.context.stdout.write(renderer_1.renderRetriedUpload(e.message, attempt));
|
|
79
|
+
metricsLogger.logger.increment('retries', 1);
|
|
80
|
+
},
|
|
81
|
+
onUpload: () => {
|
|
82
|
+
return;
|
|
83
|
+
},
|
|
84
|
+
retries: 5,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
74
87
|
metricsLogger.logger.increment('success', 1);
|
|
75
88
|
const totalTime = (Date.now() - initialTime) / 1000;
|
|
76
89
|
if (status !== upload_1.UploadStatus.Success) {
|
|
@@ -113,15 +126,6 @@ class UploadCommand extends clipanion_1.Command {
|
|
|
113
126
|
overrideUrl: 'api/v2/srcmap',
|
|
114
127
|
});
|
|
115
128
|
}
|
|
116
|
-
uploadRepository(requestBuilder) {
|
|
117
|
-
return (commitInfo, opts) => __awaiter(this, void 0, void 0, function* () {
|
|
118
|
-
const payload = commitInfo.asMultipartPayload(this.cliVersion);
|
|
119
|
-
if (this.dryRun) {
|
|
120
|
-
return upload_1.UploadStatus.Success;
|
|
121
|
-
}
|
|
122
|
-
return upload_1.upload(requestBuilder)(payload, opts);
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
129
|
}
|
|
126
130
|
exports.UploadCommand = UploadCommand;
|
|
127
131
|
UploadCommand.usage = clipanion_1.Command.Usage({
|
|
@@ -369,7 +369,7 @@ TagResource -> arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world
|
|
|
369
369
|
'0.1',
|
|
370
370
|
], context);
|
|
371
371
|
const output = context.stdout.toString();
|
|
372
|
-
expect(output).toMatch(/.*
|
|
372
|
+
expect(output.replace('\n', '')).toMatch(/.*Error: Couldn't get local git status.*/);
|
|
373
373
|
}));
|
|
374
374
|
test('instrumenting with source code integrations fails if DATADOG_API_KEY is not provided', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
375
375
|
;
|
|
@@ -185,7 +185,7 @@ class InstrumentCommand extends clipanion_1.Command {
|
|
|
185
185
|
getCurrentGitStatus() {
|
|
186
186
|
return __awaiter(this, void 0, void 0, function* () {
|
|
187
187
|
const simpleGit = yield git_1.newSimpleGit();
|
|
188
|
-
const gitCommitInfo = yield git_1.getCommitInfo(simpleGit
|
|
188
|
+
const gitCommitInfo = yield git_1.getCommitInfo(simpleGit);
|
|
189
189
|
if (gitCommitInfo === undefined) {
|
|
190
190
|
throw new Error('Git commit info is not defined');
|
|
191
191
|
}
|
|
@@ -36,6 +36,7 @@ jest.mock('fs');
|
|
|
36
36
|
const fs = __importStar(require("fs"));
|
|
37
37
|
const axios_1 = __importDefault(require("axios"));
|
|
38
38
|
const glob_1 = __importDefault(require("glob"));
|
|
39
|
+
const ciHelpers = __importStar(require("../../../helpers/ci"));
|
|
39
40
|
const api_1 = require("../api");
|
|
40
41
|
const interfaces_1 = require("../interfaces");
|
|
41
42
|
const utils = __importStar(require("../utils"));
|
|
@@ -82,6 +83,31 @@ describe('utils', () => {
|
|
|
82
83
|
const output = yield utils.runTests(api, [{ public_id: fakeId, executionRule: interfaces_1.ExecutionRule.NON_BLOCKING }]);
|
|
83
84
|
expect(output).toEqual(fakeTrigger);
|
|
84
85
|
}));
|
|
86
|
+
test('runTests sends batch metadata', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
87
|
+
jest.spyOn(ciHelpers, 'getCIMetadata').mockImplementation(() => undefined);
|
|
88
|
+
const payloadMetadataSpy = jest.fn();
|
|
89
|
+
const axiosMock = jest.spyOn(axios_1.default, 'create');
|
|
90
|
+
axiosMock.mockImplementation((() => (e) => {
|
|
91
|
+
payloadMetadataSpy(e.data.metadata);
|
|
92
|
+
if (e.url === '/synthetics/tests/trigger/ci') {
|
|
93
|
+
return { data: fakeTrigger };
|
|
94
|
+
}
|
|
95
|
+
}));
|
|
96
|
+
yield utils.runTests(api, [{ public_id: fakeId, executionRule: interfaces_1.ExecutionRule.NON_BLOCKING }]);
|
|
97
|
+
expect(payloadMetadataSpy).toHaveBeenCalledWith({
|
|
98
|
+
ci: { job: {}, pipeline: {}, provider: {}, stage: {} },
|
|
99
|
+
git: { commit: { author: {}, committer: {} } },
|
|
100
|
+
trigger_app: 'npm_package',
|
|
101
|
+
});
|
|
102
|
+
const metadata = {
|
|
103
|
+
ci: { job: { name: 'job' }, pipeline: {}, provider: { name: 'jest' }, stage: {} },
|
|
104
|
+
git: { commit: { author: {}, committer: {}, message: 'test' } },
|
|
105
|
+
};
|
|
106
|
+
jest.spyOn(ciHelpers, 'getCIMetadata').mockImplementation(() => metadata);
|
|
107
|
+
utils.setCiTriggerApp('unit_test');
|
|
108
|
+
yield utils.runTests(api, [{ public_id: fakeId, executionRule: interfaces_1.ExecutionRule.NON_BLOCKING }]);
|
|
109
|
+
expect(payloadMetadataSpy).toHaveBeenCalledWith(Object.assign(Object.assign({}, metadata), { trigger_app: 'unit_test' }));
|
|
110
|
+
}));
|
|
85
111
|
test('should run test with publicId from url', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
86
112
|
const axiosMock = jest.spyOn(axios_1.default, 'create');
|
|
87
113
|
axiosMock.mockImplementation((() => (e) => {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { ParsedKey } from 'ssh2-streams';
|
|
1
2
|
export declare const generateOpenSSHKeys: () => {
|
|
2
3
|
privateKey: string;
|
|
3
4
|
publicKey: string;
|
|
4
5
|
};
|
|
5
|
-
export declare const parseSSHKey: (key: string) =>
|
|
6
|
+
export declare const parseSSHKey: (key: string) => ParsedKey;
|
|
@@ -252,9 +252,12 @@ export interface ConfigOverride {
|
|
|
252
252
|
};
|
|
253
253
|
}
|
|
254
254
|
export interface Payload {
|
|
255
|
-
metadata?:
|
|
255
|
+
metadata?: SyntheticsMetadata;
|
|
256
256
|
tests: TestPayload[];
|
|
257
257
|
}
|
|
258
|
+
export declare type SyntheticsMetadata = Metadata & {
|
|
259
|
+
trigger_app: string;
|
|
260
|
+
};
|
|
258
261
|
export interface TestPayload extends ConfigOverride {
|
|
259
262
|
executionRule: ExecutionRule;
|
|
260
263
|
public_id: string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { APIHelper, ConfigOverride, ExecutionRule, InternalTest, MainReporter, PollResult, Reporter, Result, Suite, Summary, TestPayload, Trigger, TriggerConfig, TriggerResponse, TriggerResult } from './interfaces';
|
|
2
2
|
import { Tunnel } from './tunnel';
|
|
3
3
|
export declare const handleConfig: (test: InternalTest, publicId: string, reporter: MainReporter, config?: ConfigOverride | undefined) => TestPayload;
|
|
4
|
+
export declare const setCiTriggerApp: (source: string) => void;
|
|
4
5
|
export declare const getExecutionRule: (test: InternalTest, configOverride?: ConfigOverride | undefined) => ExecutionRule;
|
|
5
6
|
export declare const getStrictestExecutionRule: (configRule: ExecutionRule, testRule?: ExecutionRule | undefined) => ExecutionRule;
|
|
6
7
|
export declare const isCriticalError: (result: Result) => boolean;
|
|
@@ -31,7 +31,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
31
31
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
32
|
};
|
|
33
33
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
exports.parseVariablesFromCli = exports.retry = exports.runTests = exports.getTestsToTrigger = exports.getReporter = exports.getResultDuration = exports.createSummary = exports.createTriggerResultMap = exports.waitForResults = exports.wait = exports.getSuites = exports.hasTestSucceeded = exports.hasResultPassed = exports.isCriticalError = exports.getStrictestExecutionRule = exports.getExecutionRule = exports.handleConfig = void 0;
|
|
34
|
+
exports.parseVariablesFromCli = exports.retry = exports.runTests = exports.getTestsToTrigger = exports.getReporter = exports.getResultDuration = exports.createSummary = exports.createTriggerResultMap = exports.waitForResults = exports.wait = exports.getSuites = exports.hasTestSucceeded = exports.hasResultPassed = exports.isCriticalError = exports.getStrictestExecutionRule = exports.getExecutionRule = exports.setCiTriggerApp = exports.handleConfig = void 0;
|
|
35
35
|
const fs = __importStar(require("fs"));
|
|
36
36
|
const path = __importStar(require("path"));
|
|
37
37
|
const url_1 = require("url");
|
|
@@ -47,6 +47,7 @@ const PUBLIC_ID_REGEX = /^[\d\w]{3}-[\d\w]{3}-[\d\w]{3}$/;
|
|
|
47
47
|
const SUBDOMAIN_REGEX = /(.*?)\.(?=[^\/]*\..{2,5})/;
|
|
48
48
|
const TEMPLATE_REGEX = /{{\s*([^{}]*?)\s*}}/g;
|
|
49
49
|
const template = (st, context) => st.replace(TEMPLATE_REGEX, (match, p1) => (p1 in context ? context[p1] : match));
|
|
50
|
+
let ciTriggerApp = 'npm_package';
|
|
50
51
|
const handleConfig = (test, publicId, reporter, config) => {
|
|
51
52
|
const executionRule = exports.getExecutionRule(test, config);
|
|
52
53
|
let handledConfig = {
|
|
@@ -83,6 +84,10 @@ const handleConfig = (test, publicId, reporter, config) => {
|
|
|
83
84
|
return handledConfig;
|
|
84
85
|
};
|
|
85
86
|
exports.handleConfig = handleConfig;
|
|
87
|
+
const setCiTriggerApp = (source) => {
|
|
88
|
+
ciTriggerApp = source;
|
|
89
|
+
};
|
|
90
|
+
exports.setCiTriggerApp = setCiTriggerApp;
|
|
86
91
|
const parseUrlVariables = (url, reporter) => {
|
|
87
92
|
const context = Object.assign(Object.assign({}, process.env), { URL: url });
|
|
88
93
|
let objUrl;
|
|
@@ -408,9 +413,8 @@ exports.getTestsToTrigger = getTestsToTrigger;
|
|
|
408
413
|
const runTests = (api, testsToTrigger) => __awaiter(void 0, void 0, void 0, function* () {
|
|
409
414
|
const payload = { tests: testsToTrigger };
|
|
410
415
|
const ciMetadata = ci_1.getCIMetadata();
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
}
|
|
416
|
+
const syntheticsMetadata = Object.assign(Object.assign({ ci: { job: {}, pipeline: {}, provider: {}, stage: {} }, git: { commit: { author: {}, committer: {} } } }, ciMetadata), { trigger_app: ciTriggerApp });
|
|
417
|
+
payload.metadata = syntheticsMetadata;
|
|
414
418
|
try {
|
|
415
419
|
return yield api.triggerTests(payload);
|
|
416
420
|
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -19,7 +19,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.synthetics = exports.utils = void 0;
|
|
22
|
+
exports.gitMetadata = exports.synthetics = exports.utils = void 0;
|
|
23
|
+
const gitMetadata = __importStar(require("./commands/git-metadata"));
|
|
24
|
+
exports.gitMetadata = gitMetadata;
|
|
23
25
|
const synthetics = __importStar(require("./commands/synthetics"));
|
|
24
26
|
exports.synthetics = synthetics;
|
|
25
27
|
const utils = __importStar(require("./helpers/utils"));
|