@datadog/datadog-ci-plugin-terraform 5.20.1 → 5.21.0

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/bundle.js CHANGED
@@ -10914,7 +10914,7 @@ var require_glob = /* @__PURE__ */ __commonJSMin(((exports) => {
10914
10914
  var require_package$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
10915
10915
  module.exports = {
10916
10916
  "name": "@datadog/datadog-ci-base",
10917
- "version": "5.20.1",
10917
+ "version": "5.21.0",
10918
10918
  "description": "Base package for Datadog CI",
10919
10919
  "license": "Apache-2.0",
10920
10920
  "keywords": ["datadog", "datadog-ci"],
@@ -11042,13 +11042,14 @@ var require_package$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
11042
11042
  //#region ../base/dist/constants.js
11043
11043
  var require_constants$10 = /* @__PURE__ */ __commonJSMin(((exports) => {
11044
11044
  Object.defineProperty(exports, "__esModule", { value: true });
11045
- exports.METHOD_POST = exports.CONTENT_TYPE_VALUE_JSON = exports.CONTENT_TYPE_VALUE_PROTOBUF = exports.CONTENT_TYPE_HEADER = exports.SKIP_VERSION_BANNER_ENV_VAR = exports.LOG_FORMAT_ENV_VAR = exports.FIPS_IGNORE_ERROR_ENV_VAR = exports.FIPS_ENV_VAR = exports.DATADOG_SITES = exports.DATADOG_SITE_US2_GOV = exports.DATADOG_SITE_GOV = exports.DATADOG_SITE_AP2 = exports.DATADOG_SITE_AP1 = exports.DATADOG_SITE_US5 = exports.DATADOG_SITE_US3 = exports.DATADOG_SITE_EU1 = exports.DATADOG_SITE_US1 = void 0;
11045
+ exports.METHOD_POST = exports.CONTENT_TYPE_VALUE_JSON = exports.CONTENT_TYPE_VALUE_PROTOBUF = exports.CONTENT_TYPE_HEADER = exports.SKIP_VERSION_BANNER_ENV_VAR = exports.LOG_FORMAT_ENV_VAR = exports.FIPS_IGNORE_ERROR_ENV_VAR = exports.FIPS_ENV_VAR = exports.DATADOG_SITES = exports.DATADOG_SITE_US2_GOV = exports.DATADOG_SITE_GOV = exports.DATADOG_SITE_UK1 = exports.DATADOG_SITE_AP2 = exports.DATADOG_SITE_AP1 = exports.DATADOG_SITE_US5 = exports.DATADOG_SITE_US3 = exports.DATADOG_SITE_EU1 = exports.DATADOG_SITE_US1 = void 0;
11046
11046
  exports.DATADOG_SITE_US1 = "datadoghq.com";
11047
11047
  exports.DATADOG_SITE_EU1 = "datadoghq.eu";
11048
11048
  exports.DATADOG_SITE_US3 = "us3.datadoghq.com";
11049
11049
  exports.DATADOG_SITE_US5 = "us5.datadoghq.com";
11050
11050
  exports.DATADOG_SITE_AP1 = "ap1.datadoghq.com";
11051
11051
  exports.DATADOG_SITE_AP2 = "ap2.datadoghq.com";
11052
+ exports.DATADOG_SITE_UK1 = "uk1.datadoghq.com";
11052
11053
  exports.DATADOG_SITE_GOV = "ddog-gov.com";
11053
11054
  exports.DATADOG_SITE_US2_GOV = "us2.ddog-gov.com";
11054
11055
  exports.DATADOG_SITES = [
@@ -11058,6 +11059,7 @@ var require_constants$10 = /* @__PURE__ */ __commonJSMin(((exports) => {
11058
11059
  exports.DATADOG_SITE_US5,
11059
11060
  exports.DATADOG_SITE_AP1,
11060
11061
  exports.DATADOG_SITE_AP2,
11062
+ exports.DATADOG_SITE_UK1,
11061
11063
  exports.DATADOG_SITE_GOV,
11062
11064
  exports.DATADOG_SITE_US2_GOV
11063
11065
  ];
@@ -64713,11 +64715,38 @@ var require_tags = /* @__PURE__ */ __commonJSMin(((exports) => {
64713
64715
  //#endregion
64714
64716
  //#region ../base/dist/helpers/ci.js
64715
64717
  var require_ci = /* @__PURE__ */ __commonJSMin(((exports) => {
64718
+ var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
64719
+ function adopt(value) {
64720
+ return value instanceof P ? value : new P(function(resolve) {
64721
+ resolve(value);
64722
+ });
64723
+ }
64724
+ return new (P || (P = Promise))(function(resolve, reject) {
64725
+ function fulfilled(value) {
64726
+ try {
64727
+ step(generator.next(value));
64728
+ } catch (e) {
64729
+ reject(e);
64730
+ }
64731
+ }
64732
+ function rejected(value) {
64733
+ try {
64734
+ step(generator["throw"](value));
64735
+ } catch (e) {
64736
+ reject(e);
64737
+ }
64738
+ }
64739
+ function step(result) {
64740
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
64741
+ }
64742
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
64743
+ });
64744
+ };
64716
64745
  var __importDefault = exports && exports.__importDefault || function(mod) {
64717
64746
  return mod && mod.__esModule ? mod : { "default": mod };
64718
64747
  };
64719
64748
  Object.defineProperty(exports, "__esModule", { value: true });
64720
- exports.getGithubJobIDFromLogs = exports.getGithubStepInfoFromLogs = exports.enrichCIEnvFromGithubLogs = exports.getGithubJobNameFromLogs = exports.isGithubWindowsRunner = exports.shouldGetGithubJobID = exports.shouldGetGithubJobDisplayName = exports.isInteractive = exports.getCIProvider = exports.isCI = exports.getCIEnv = exports.getCIMetadata = exports.getCISpanTags = exports.githubWellKnownDiagnosticDirPatternsWin = exports.githubWellKnownDiagnosticDirPatternsUnix = exports.githubWellKnownDiagnosticDirsWin = exports.githubWellKnownDiagnosticDirsUnix = exports.validateLevel = exports.LEVEL_TO_NUMBER = exports.VALID_LEVELS = exports.CI_LEVELS = exports.envDDGithubStepIndex = exports.envDDGithubJobName = exports.CI_ENGINES = void 0;
64749
+ exports.getGithubJobIDFromLogs = exports.getGithubStepInfoFromLogs = exports.processLevels = exports.enrichCIEnvFromGithubLogs = exports.getGithubJobNameFromLogs = exports.createGithubLogCache = exports.isGithubWindowsRunner = exports.shouldGetGithubJobID = exports.shouldGetGithubJobDisplayName = exports.isInteractive = exports.getCIProvider = exports.isCI = exports.getCIEnv = exports.getCIMetadata = exports.getCISpanTags = exports.githubWellKnownDiagnosticDirPatternsWin = exports.githubWellKnownDiagnosticDirPatternsUnix = exports.githubWellKnownDiagnosticDirsWin = exports.githubWellKnownDiagnosticDirsUnix = exports.parseLevels = exports.validateLevel = exports.LEVEL_TO_NUMBER = exports.VALID_LEVELS = exports.CI_LEVELS = exports.envDDGithubStepIndex = exports.envDDGithubJobName = exports.CI_ENGINES = void 0;
64721
64750
  const fs_1$2 = __importDefault(require("fs"));
64722
64751
  const chalk_1 = __importDefault(require_source());
64723
64752
  const upath_1 = __importDefault(require_upath());
@@ -64775,6 +64804,26 @@ var require_ci = /* @__PURE__ */ __commonJSMin(((exports) => {
64775
64804
  if (level === exports.CI_LEVELS.STEP && provider !== exports.CI_ENGINES.GITHUB) return `Level '${exports.CI_LEVELS.STEP}' is only supported for provider [${exports.CI_ENGINES.GITHUB}]`;
64776
64805
  };
64777
64806
  exports.validateLevel = validateLevel;
64807
+ /**
64808
+ * Parses an additive, comma-separated `--level` value (e.g. "pipeline,stage").
64809
+ * Trims each member, drops empties, dedupes, sorts by span depth, and validates
64810
+ * every member (known value + provider support). Returns the parsed levels or,
64811
+ * if anything is invalid or empty, a single aggregated error message.
64812
+ */
64813
+ const parseLevels = (input) => {
64814
+ const unique = uniq((input !== null && input !== void 0 ? input : "").split(",").map((p) => p.trim()).filter((p) => p.length > 0));
64815
+ if (unique.length === 0) return {
64816
+ levels: [],
64817
+ error: `Level must be one of [${exports.VALID_LEVELS.join(", ")}]`
64818
+ };
64819
+ const errors = uniq(unique.map((p) => (0, exports.validateLevel)(p)).filter((e) => Boolean(e)));
64820
+ if (errors.length > 0) return {
64821
+ levels: [],
64822
+ error: errors.join("; ")
64823
+ };
64824
+ return { levels: unique.sort((a, b) => exports.LEVEL_TO_NUMBER[a] - exports.LEVEL_TO_NUMBER[b]) };
64825
+ };
64826
+ exports.parseLevels = parseLevels;
64778
64827
  exports.githubWellKnownDiagnosticDirsUnix = ["/home/runner/actions-runner/_diag", "/opt/actions-runner/_diag"];
64779
64828
  exports.githubWellKnownDiagnosticDirsWin = ["C:/actions-runner/_diag"];
64780
64829
  exports.githubWellKnownDiagnosticDirPatternsUnix = ["/home/runner/actions-runner/*/_diag", "/home/runner/actions-runner/*/*/_diag"];
@@ -65092,7 +65141,7 @@ var require_ci = /* @__PURE__ */ __commonJSMin(((exports) => {
65092
65141
  }
65093
65142
  }
65094
65143
  if (env.BITBUCKET_COMMIT) {
65095
- const { BITBUCKET_REPO_FULL_NAME, BITBUCKET_BUILD_NUMBER, BITBUCKET_BRANCH, BITBUCKET_COMMIT, BITBUCKET_GIT_SSH_ORIGIN, BITBUCKET_GIT_HTTP_ORIGIN, BITBUCKET_TAG, BITBUCKET_PIPELINE_UUID, BITBUCKET_PR_ID, BITBUCKET_PR_DESTINATION_BRANCH, BITBUCKET_CLONE_DIR } = env;
65144
+ const { BITBUCKET_REPO_FULL_NAME, BITBUCKET_BUILD_NUMBER, BITBUCKET_BRANCH, BITBUCKET_COMMIT, BITBUCKET_GIT_SSH_ORIGIN, BITBUCKET_GIT_HTTP_ORIGIN, BITBUCKET_TAG, BITBUCKET_PIPELINE_UUID, BITBUCKET_PR_ID, BITBUCKET_PR_DESTINATION_BRANCH, BITBUCKET_PR_DESTINATION_COMMIT, BITBUCKET_CLONE_DIR } = env;
65096
65145
  const url = `https://bitbucket.org/${BITBUCKET_REPO_FULL_NAME}/addon/pipelines/home#!/results/${BITBUCKET_BUILD_NUMBER}`;
65097
65146
  tags = {
65098
65147
  [tags_1.CI_PROVIDER_NAME]: exports.CI_ENGINES.BITBUCKET,
@@ -65110,6 +65159,7 @@ var require_ci = /* @__PURE__ */ __commonJSMin(((exports) => {
65110
65159
  if (BITBUCKET_PR_ID) {
65111
65160
  tags[tags_1.PR_NUMBER] = BITBUCKET_PR_ID;
65112
65161
  tags[tags_1.GIT_PULL_REQUEST_BASE_BRANCH] = BITBUCKET_PR_DESTINATION_BRANCH;
65162
+ if (BITBUCKET_PR_DESTINATION_COMMIT) tags[tags_1.GIT_PULL_REQUEST_BASE_BRANCH_SHA] = BITBUCKET_PR_DESTINATION_COMMIT;
65113
65163
  }
65114
65164
  }
65115
65165
  if (env.CF_BUILD_ID) {
@@ -65419,7 +65469,32 @@ var require_ci = /* @__PURE__ */ __commonJSMin(((exports) => {
65419
65469
  return os.toLowerCase() === "windows";
65420
65470
  };
65421
65471
  exports.isGithubWindowsRunner = isGithubWindowsRunner;
65422
- const getGithubWorkerLogFiles = (context) => {
65472
+ const createGithubLogCache = () => ({
65473
+ workerLogFilesResolved: false,
65474
+ workerLogFiles: void 0,
65475
+ targetLogFilesResolved: false,
65476
+ targetLogFiles: [],
65477
+ fileContents: /* @__PURE__ */ new Map()
65478
+ });
65479
+ exports.createGithubLogCache = createGithubLogCache;
65480
+ /** Reads a diagnostic log file, serving from (and populating) `cache` when provided. */
65481
+ const readLogFile = (filePath, cache) => {
65482
+ const cached = cache === null || cache === void 0 ? void 0 : cache.fileContents.get(filePath);
65483
+ if (cached !== void 0) return cached;
65484
+ const content = fs_1$2.default.readFileSync(filePath, "utf-8");
65485
+ cache === null || cache === void 0 || cache.fileContents.set(filePath, content);
65486
+ return content;
65487
+ };
65488
+ const getGithubWorkerLogFiles = (context, cache) => {
65489
+ if (cache === null || cache === void 0 ? void 0 : cache.workerLogFilesResolved) return cache.workerLogFiles;
65490
+ const result = computeGithubWorkerLogFiles(context);
65491
+ if (cache) {
65492
+ cache.workerLogFilesResolved = true;
65493
+ cache.workerLogFiles = result;
65494
+ }
65495
+ return result;
65496
+ };
65497
+ const computeGithubWorkerLogFiles = (context) => {
65423
65498
  let foundDiagDir = "";
65424
65499
  let workerLogFiles = [];
65425
65500
  let wellKnownDirs = expandDiagnosticDirCandidates([
@@ -65476,13 +65551,21 @@ var require_ci = /* @__PURE__ */ __commonJSMin(((exports) => {
65476
65551
  * which on a single-job runner is immediate, and on a multi-runner is the current
65477
65552
  * job's (most recent) log.
65478
65553
  */
65479
- const getTargetWorkerLogFiles = (context, foundDiagDir, workerLogFiles) => {
65554
+ const getTargetWorkerLogFiles = (context, foundDiagDir, workerLogFiles, cache) => {
65555
+ if (cache === null || cache === void 0 ? void 0 : cache.targetLogFilesResolved) return cache.targetLogFiles;
65556
+ const result = computeTargetWorkerLogFiles(context, foundDiagDir, workerLogFiles, cache);
65557
+ if (cache) {
65558
+ cache.targetLogFilesResolved = true;
65559
+ cache.targetLogFiles = result;
65560
+ }
65561
+ return result;
65562
+ };
65563
+ const computeTargetWorkerLogFiles = (context, foundDiagDir, workerLogFiles, cache) => {
65480
65564
  const sortedNewestFirst = [...workerLogFiles].sort().reverse();
65481
65565
  const orchestrationId = process.env.ACTIONS_ORCHESTRATION_ID;
65482
65566
  if (orchestrationId) {
65483
65567
  for (const logFile of sortedNewestFirst) {
65484
- const filePath = upath_1.default.join(foundDiagDir, logFile);
65485
- const content = fs_1$2.default.readFileSync(filePath, "utf-8");
65568
+ const content = readLogFile(upath_1.default.join(foundDiagDir, logFile), cache);
65486
65569
  if (content.includes("\"system.orchestrationId\":") && content.includes(`"${orchestrationId}"`)) {
65487
65570
  context.stdout.write(`Found Worker log via system.orchestrationId for ${orchestrationId}: ${logFile}\n`);
65488
65571
  return [logFile];
@@ -65492,11 +65575,10 @@ var require_ci = /* @__PURE__ */ __commonJSMin(((exports) => {
65492
65575
  }
65493
65576
  return sortedNewestFirst;
65494
65577
  };
65495
- const getGithubJobAttributeFromLogFiles = (context, foundDiagDir, workerLogFiles, jobAttributeRegex) => {
65496
- const logsToCheck = getTargetWorkerLogFiles(context, foundDiagDir, workerLogFiles);
65578
+ const getGithubJobAttributeFromLogFiles = (context, foundDiagDir, workerLogFiles, jobAttributeRegex, cache) => {
65579
+ const logsToCheck = getTargetWorkerLogFiles(context, foundDiagDir, workerLogFiles, cache);
65497
65580
  for (const logFile of logsToCheck) {
65498
- const filePath = upath_1.default.join(foundDiagDir, logFile);
65499
- const match = fs_1$2.default.readFileSync(filePath, "utf-8").match(jobAttributeRegex);
65581
+ const match = readLogFile(upath_1.default.join(foundDiagDir, logFile), cache).match(jobAttributeRegex);
65500
65582
  if (match && match[1]) return unescapeJsonString(match[1]);
65501
65583
  }
65502
65584
  };
@@ -65516,13 +65598,13 @@ var require_ci = /* @__PURE__ */ __commonJSMin(((exports) => {
65516
65598
  *
65517
65599
  * @returns The job display name, or undefined if not found
65518
65600
  */
65519
- const getGithubJobNameFromLogs = (context) => {
65601
+ const getGithubJobNameFromLogs = (context, cache) => {
65520
65602
  if (!(0, exports.shouldGetGithubJobDisplayName)()) return;
65521
65603
  context.stdout.write("Determining GitHub job name\n");
65522
- const result = getGithubWorkerLogFiles(context);
65604
+ const result = getGithubWorkerLogFiles(context, cache);
65523
65605
  if (!result) return;
65524
65606
  const [foundDiagDir, workerLogFiles] = result;
65525
- const jobDisplayName = getGithubJobAttributeFromLogFiles(context, foundDiagDir, workerLogFiles, githubJobDisplayNameRegex);
65607
+ const jobDisplayName = getGithubJobAttributeFromLogFiles(context, foundDiagDir, workerLogFiles, githubJobDisplayNameRegex, cache);
65526
65608
  if (!jobDisplayName) context.stderr.write(`${chalk_1.default.yellow.bold("[WARNING]")} could not find "jobDisplayName" attribute in GitHub diagnostic logs`);
65527
65609
  else {
65528
65610
  context.stdout.write(`Successfully extracted job name: ${jobDisplayName}\n`);
@@ -65536,16 +65618,16 @@ var require_ci = /* @__PURE__ */ __commonJSMin(((exports) => {
65536
65618
  * - job: extracts job display name
65537
65619
  * - pipeline/stage: no-op
65538
65620
  */
65539
- const enrichCIEnvFromGithubLogs = (context, level, ciEnv) => {
65621
+ const enrichCIEnvFromGithubLogs = (context, level, ciEnv, cache) => {
65540
65622
  switch (level) {
65541
65623
  case exports.CI_LEVELS.STEP: {
65542
- const stepInfo = (0, exports.getGithubStepInfoFromLogs)(context);
65624
+ const stepInfo = (0, exports.getGithubStepInfoFromLogs)(context, cache);
65543
65625
  if (!ciEnv[exports.envDDGithubJobName]) ciEnv[exports.envDDGithubJobName] = stepInfo.jobDisplayName;
65544
65626
  ciEnv[exports.envDDGithubStepIndex] = String(stepInfo.stepIndex);
65545
65627
  break;
65546
65628
  }
65547
65629
  case exports.CI_LEVELS.JOB: {
65548
- const jobName = (0, exports.getGithubJobNameFromLogs)(context);
65630
+ const jobName = (0, exports.getGithubJobNameFromLogs)(context, cache);
65549
65631
  if (jobName) ciEnv[exports.envDDGithubJobName] = jobName;
65550
65632
  break;
65551
65633
  }
@@ -65554,6 +65636,48 @@ var require_ci = /* @__PURE__ */ __commonJSMin(((exports) => {
65554
65636
  };
65555
65637
  exports.enrichCIEnvFromGithubLogs = enrichCIEnvFromGithubLogs;
65556
65638
  /**
65639
+ * Sends the same payload to each requested CI level, one request per level.
65640
+ *
65641
+ * Shared by the `tag` and `measure` commands. Each level is enriched on its own
65642
+ * copy of `ciEnv` (so e.g. the step index never leaks into the job request).
65643
+ *
65644
+ * Failure handling mirrors the original single-level behavior:
65645
+ * - A setup/config error — a missing API key, or GitHub diagnostic logs that
65646
+ * cannot be located — is thrown and propagates to the caller's outer catch,
65647
+ * making it fatal regardless of `--no-fail`. The thrown error is annotated
65648
+ * with the failing level so the report says which one broke.
65649
+ * - A request that completes but reports a non-zero status sets the returned
65650
+ * flag and the loop continues; the caller decides whether `--no-fail` turns
65651
+ * it into a success.
65652
+ *
65653
+ * A single `GithubLogCache` lives for the duration of the loop so the GitHub
65654
+ * diagnostic logs are located and read at most once even when several levels
65655
+ * need them (e.g. `--level job,step`).
65656
+ *
65657
+ * Returns `true` if any level reported a non-zero status. Callers own the
65658
+ * `--no-fail`/success messaging and exit code based on this flag.
65659
+ */
65660
+ const processLevels = (context, levels, ciEnv, sendForLevel) => __awaiter(void 0, void 0, void 0, function* () {
65661
+ const cache = (0, exports.createGithubLogCache)();
65662
+ let anyFailed = false;
65663
+ for (const level of levels) {
65664
+ let exitStatus;
65665
+ try {
65666
+ const levelEnv = Object.assign({}, ciEnv);
65667
+ (0, exports.enrichCIEnvFromGithubLogs)(context, level, levelEnv, cache);
65668
+ exitStatus = yield sendForLevel(levelEnv, exports.LEVEL_TO_NUMBER[level]);
65669
+ } catch (error) {
65670
+ throw new Error(`level '${level}': ${error.message}`);
65671
+ }
65672
+ if (exitStatus !== 0) {
65673
+ anyFailed = true;
65674
+ context.stderr.write(`${chalk_1.default.red.bold("[ERROR]")} failed to send for level '${level}'\n`);
65675
+ }
65676
+ }
65677
+ return anyFailed;
65678
+ });
65679
+ exports.processLevels = processLevels;
65680
+ /**
65557
65681
  * Extracts the job display name and step index from GitHub Actions diagnostic logs.
65558
65682
  *
65559
65683
  * To avoid parsing the full Job message JSON (~26KB), we:
@@ -65561,18 +65685,17 @@ var require_ci = /* @__PURE__ */ __commonJSMin(((exports) => {
65561
65685
  * 2. Extract only the `"steps": [...]` array from the Job message via bracket-depth tracking
65562
65686
  * 3. Parse just that array and match `contextName` against `GITHUB_ACTION`
65563
65687
  */
65564
- const getGithubStepInfoFromLogs = (context) => {
65688
+ const getGithubStepInfoFromLogs = (context, cache) => {
65565
65689
  if ((0, exports.getCIProvider)() !== exports.CI_ENGINES.GITHUB) throw new Error("Step level is only supported for GitHub Actions");
65566
65690
  const githubAction = process.env.GITHUB_ACTION;
65567
65691
  if (!githubAction) throw new Error("GITHUB_ACTION environment variable is not set, cannot determine step index");
65568
65692
  context.stdout.write("Determining GitHub step info from diagnostic logs\n");
65569
- const result = getGithubWorkerLogFiles(context);
65693
+ const result = getGithubWorkerLogFiles(context, cache);
65570
65694
  if (!result) throw new Error("Could not find GitHub diagnostic log files, cannot determine step index");
65571
65695
  const [foundDiagDir, workerLogFiles] = result;
65572
- const logsToCheck = getTargetWorkerLogFiles(context, foundDiagDir, workerLogFiles);
65696
+ const logsToCheck = getTargetWorkerLogFiles(context, foundDiagDir, workerLogFiles, cache);
65573
65697
  for (const logFile of logsToCheck) {
65574
- const filePath = upath_1.default.join(foundDiagDir, logFile);
65575
- const content = fs_1$2.default.readFileSync(filePath, "utf-8");
65698
+ const content = readLogFile(upath_1.default.join(foundDiagDir, logFile), cache);
65576
65699
  const displayNameMatch = content.match(githubJobDisplayNameRegex);
65577
65700
  if (!displayNameMatch || !displayNameMatch[1]) continue;
65578
65701
  const jobDisplayName = unescapeJsonString(displayNameMatch[1]);