@datadog/datadog-ci 1.2.0 → 1.3.0-alpha
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/junit/__tests__/upload.test.js +15 -1
- package/dist/commands/junit/api.js +3 -0
- package/dist/commands/junit/interfaces.d.ts +1 -0
- package/dist/commands/junit/upload.d.ts +1 -0
- package/dist/commands/junit/upload.js +12 -0
- package/dist/commands/lambda/__tests__/functions/commons.test.js +22 -10
- package/dist/commands/lambda/functions/commons.js +4 -1
- package/package.json +1 -1
|
@@ -172,6 +172,20 @@ describe('upload', () => {
|
|
|
172
172
|
key2: 'value2',
|
|
173
173
|
});
|
|
174
174
|
}));
|
|
175
|
+
test('should set logsEnabled for each file', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
176
|
+
process.env.DD_CIVISIBILITY_LOGS_ENABLED = 'true';
|
|
177
|
+
const context = createMockContext();
|
|
178
|
+
const command = new upload_1.UploadJUnitXMLCommand();
|
|
179
|
+
const [firstFile, secondFile] = yield command['getMatchingJUnitXMLFiles'].call({
|
|
180
|
+
basePaths: ['./src/commands/junit/__tests__/fixtures'],
|
|
181
|
+
config: {},
|
|
182
|
+
context,
|
|
183
|
+
logs: true,
|
|
184
|
+
service: 'service',
|
|
185
|
+
});
|
|
186
|
+
expect(firstFile.logsEnabled).toBe(true);
|
|
187
|
+
expect(secondFile.logsEnabled).toBe(true);
|
|
188
|
+
}));
|
|
175
189
|
});
|
|
176
190
|
});
|
|
177
191
|
describe('execute', () => {
|
|
@@ -179,7 +193,7 @@ describe('execute', () => {
|
|
|
179
193
|
const cli = makeCli();
|
|
180
194
|
const context = createMockContext();
|
|
181
195
|
process.env = { DATADOG_API_KEY: 'PLACEHOLDER' };
|
|
182
|
-
const code = yield cli.run(['junit', 'upload', '--service', 'test-service', '--dry-run', ...paths], context);
|
|
196
|
+
const code = yield cli.run(['junit', 'upload', '--service', 'test-service', '--dry-run', '--logs', ...paths], context);
|
|
183
197
|
return { context, code };
|
|
184
198
|
});
|
|
185
199
|
test('relative path with double dots', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -39,6 +39,9 @@ const uploadJUnitXML = (request) => (jUnitXML, write) => __awaiter(void 0, void
|
|
|
39
39
|
fileName = 'default_file_name';
|
|
40
40
|
}
|
|
41
41
|
const spanTags = Object.assign(Object.assign({ service: jUnitXML.service }, jUnitXML.spanTags), { '_dd.cireport_version': '2' });
|
|
42
|
+
if (jUnitXML.logsEnabled) {
|
|
43
|
+
spanTags['_dd.junitxml_logs'] = 'true';
|
|
44
|
+
}
|
|
42
45
|
form.append('event', JSON.stringify(spanTags), { filename: 'event.json' });
|
|
43
46
|
let uniqueFileName = `${fileName}-${jUnitXML.service}-${spanTags[tags_1.GIT_SHA]}`;
|
|
44
47
|
if (spanTags[tags_1.CI_PIPELINE_URL]) {
|
|
@@ -51,6 +51,7 @@ class UploadJUnitXMLCommand extends clipanion_1.Command {
|
|
|
51
51
|
envVarTags: process.env.DD_TAGS,
|
|
52
52
|
};
|
|
53
53
|
this.dryRun = false;
|
|
54
|
+
this.logs = false;
|
|
54
55
|
this.maxConcurrency = 20;
|
|
55
56
|
}
|
|
56
57
|
execute() {
|
|
@@ -69,6 +70,11 @@ class UploadJUnitXMLCommand extends clipanion_1.Command {
|
|
|
69
70
|
if (!this.config.env) {
|
|
70
71
|
this.config.env = this.env;
|
|
71
72
|
}
|
|
73
|
+
if (!this.logs &&
|
|
74
|
+
process.env.DD_CIVISIBILITY_LOGS_ENABLED &&
|
|
75
|
+
!['false', '0'].includes(process.env.DD_CIVISIBILITY_LOGS_ENABLED.toLowerCase())) {
|
|
76
|
+
this.logs = true;
|
|
77
|
+
}
|
|
72
78
|
const api = this.getApiHelper();
|
|
73
79
|
// Normalizing the basePath to resolve .. and .
|
|
74
80
|
// Always using the posix version to avoid \ on Windows.
|
|
@@ -113,6 +119,7 @@ class UploadJUnitXMLCommand extends clipanion_1.Command {
|
|
|
113
119
|
return true;
|
|
114
120
|
});
|
|
115
121
|
return validUniqueFiles.map((jUnitXMLFilePath) => ({
|
|
122
|
+
logsEnabled: this.logs,
|
|
116
123
|
service: this.service,
|
|
117
124
|
spanTags,
|
|
118
125
|
xmlPath: jUnitXMLFilePath,
|
|
@@ -168,6 +175,10 @@ UploadJUnitXMLCommand.usage = clipanion_1.Command.Usage({
|
|
|
168
175
|
'Upload all jUnit XML test report files in current directory to the datadoghq.eu site',
|
|
169
176
|
'DATADOG_SITE=datadoghq.eu datadog-ci junit upload --service my-service .',
|
|
170
177
|
],
|
|
178
|
+
[
|
|
179
|
+
'Upload all jUnit XML test report files in current directory while also collecting logs',
|
|
180
|
+
'datadog-ci junit upload --service my-service --logs .',
|
|
181
|
+
],
|
|
171
182
|
],
|
|
172
183
|
});
|
|
173
184
|
UploadJUnitXMLCommand.addPath('junit', 'upload');
|
|
@@ -177,3 +188,4 @@ UploadJUnitXMLCommand.addOption('dryRun', clipanion_1.Command.Boolean('--dry-run
|
|
|
177
188
|
UploadJUnitXMLCommand.addOption('tags', clipanion_1.Command.Array('--tags'));
|
|
178
189
|
UploadJUnitXMLCommand.addOption('basePaths', clipanion_1.Command.Rest({ required: 1 }));
|
|
179
190
|
UploadJUnitXMLCommand.addOption('maxConcurrency', clipanion_1.Command.String('--max-concurrency'));
|
|
191
|
+
UploadJUnitXMLCommand.addOption('logs', clipanion_1.Command.Boolean('--logs'));
|
|
@@ -10,8 +10,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
/* tslint:disable:no-string-literal */
|
|
13
|
-
jest.mock('aws-sdk');
|
|
14
13
|
const aws_sdk_1 = require("aws-sdk");
|
|
14
|
+
jest.mock('aws-sdk');
|
|
15
|
+
const aws_sdk_2 = require("aws-sdk");
|
|
15
16
|
const constants_1 = require("../../constants");
|
|
16
17
|
const commons_1 = require("../../functions/commons");
|
|
17
18
|
const instrument_1 = require("../../instrument");
|
|
@@ -149,7 +150,7 @@ describe('commons', () => {
|
|
|
149
150
|
describe('findLatestLayerVersion', () => {
|
|
150
151
|
test('finds latests version for Python39', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
151
152
|
const layer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Python39`;
|
|
152
|
-
|
|
153
|
+
aws_sdk_2.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}, {
|
|
153
154
|
[`${layer}:1`]: {
|
|
154
155
|
LayerVersionArn: `${layer}:1`,
|
|
155
156
|
Version: 1,
|
|
@@ -187,7 +188,7 @@ describe('commons', () => {
|
|
|
187
188
|
}));
|
|
188
189
|
test('finds latests version for Node14', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
189
190
|
const layer = `arn:aws:lambda:us-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node14-x`;
|
|
190
|
-
|
|
191
|
+
aws_sdk_2.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}, {
|
|
191
192
|
[`${layer}:1`]: {
|
|
192
193
|
LayerVersionArn: `${layer}:1`,
|
|
193
194
|
Version: 1,
|
|
@@ -221,7 +222,7 @@ describe('commons', () => {
|
|
|
221
222
|
}));
|
|
222
223
|
test('returns 0 when no layer can be found', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
223
224
|
;
|
|
224
|
-
|
|
225
|
+
aws_sdk_2.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}, {}));
|
|
225
226
|
const runtime = 'python3.7';
|
|
226
227
|
const region = 'us-east-1';
|
|
227
228
|
const expectedLatestVersion = 0;
|
|
@@ -238,17 +239,28 @@ describe('commons', () => {
|
|
|
238
239
|
afterAll(() => {
|
|
239
240
|
process.env = OLD_ENV;
|
|
240
241
|
});
|
|
241
|
-
test('returns true when
|
|
242
|
+
test('returns true when only AWS_SECRET_ACCESS_KEY env var is set and `~/.aws/credentials` are missing', () => {
|
|
242
243
|
process.env[constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR] = 'SOME-AWS-SECRET-ACCESS-KEY';
|
|
243
|
-
|
|
244
|
-
//
|
|
245
|
-
|
|
244
|
+
aws_sdk_1.config.credentials = undefined;
|
|
245
|
+
expect(commons_1.isMissingAWSCredentials()).toBe(true); // We return true since AWS_ACCESS_KEY_ID_ENV_VAR is missing
|
|
246
|
+
});
|
|
247
|
+
test('returns true when only AWS_ACCESS_KEY_ID environment variable is set and `~/.aws/credentials` are missing', () => {
|
|
246
248
|
process.env[constants_1.AWS_ACCESS_KEY_ID_ENV_VAR] = 'SOME-AWS-ACCESS-KEY-ID';
|
|
247
|
-
|
|
249
|
+
aws_sdk_1.config.credentials = undefined;
|
|
250
|
+
expect(commons_1.isMissingAWSCredentials()).toBe(true); // We return true since AWS_SECRET_ACCESS_KEY_ENV_VAR is missing
|
|
248
251
|
});
|
|
249
|
-
test('returns false when AWS credentials are set', () => {
|
|
252
|
+
test('returns false when AWS credentials via environment variables are set', () => {
|
|
250
253
|
process.env[constants_1.AWS_ACCESS_KEY_ID_ENV_VAR] = 'SOME-AWS-ACCESS-KEY-ID';
|
|
251
254
|
process.env[constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR] = 'SOME-AWS-SECRET-ACCESS-KEY';
|
|
255
|
+
aws_sdk_1.config.credentials = { foo: 'bar' };
|
|
256
|
+
expect(commons_1.isMissingAWSCredentials()).toBe(false);
|
|
257
|
+
});
|
|
258
|
+
test('returns true when both environment variables and `~/.aws/credentials` are missing', () => {
|
|
259
|
+
aws_sdk_1.config.credentials = undefined;
|
|
260
|
+
expect(commons_1.isMissingAWSCredentials()).toBe(true);
|
|
261
|
+
});
|
|
262
|
+
test('returns false when AWS credentials via `~/.aws/credentials` are set', () => {
|
|
263
|
+
aws_sdk_1.config.credentials = { foo: 'bar' };
|
|
252
264
|
expect(commons_1.isMissingAWSCredentials()).toBe(false);
|
|
253
265
|
});
|
|
254
266
|
});
|
|
@@ -155,7 +155,10 @@ const findLatestLayerVersion = (layer, region) => __awaiter(void 0, void 0, void
|
|
|
155
155
|
return latestVersion;
|
|
156
156
|
});
|
|
157
157
|
exports.findLatestLayerVersion = findLatestLayerVersion;
|
|
158
|
-
const isMissingAWSCredentials = () =>
|
|
158
|
+
const isMissingAWSCredentials = () =>
|
|
159
|
+
// If env vars and aws_sdk_config.credentials are not set return true otherwise return false
|
|
160
|
+
(process.env[constants_1.AWS_ACCESS_KEY_ID_ENV_VAR] === undefined || process.env[constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR] === undefined) &&
|
|
161
|
+
!aws_sdk_1.config.credentials;
|
|
159
162
|
exports.isMissingAWSCredentials = isMissingAWSCredentials;
|
|
160
163
|
const isMissingDatadogSiteEnvVar = () => {
|
|
161
164
|
const site = process.env[constants_1.CI_SITE_ENV_VAR];
|