diff --git a/.eslintrc.json b/.eslintrc.json index d6c4f22..bdb1176 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -13,6 +13,7 @@ } }, "rules": { + "@typescript-eslint/no-base-to-string": "error", "camelcase": "error", "i18n-text/no-en": "off", "@typescript-eslint/no-shadow": "error", diff --git a/dist/index.d.ts b/dist/index.d.ts index dbed9c1..2eceae5 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -117,7 +117,7 @@ type ActionOptions = { fetchStyle: FetchSuffixStyle; legacySourcePrefix?: string; requireNix: NixRequirementHandling; - diagnosticsUrl?: URL | null; + diagnosticsSuffix?: string; }; declare abstract class DetSysAction { nixStoreTrust: NixStoreTrust; @@ -133,6 +133,7 @@ declare abstract class DetSysAction { private facts; private events; private identity; + private idsHost; private determineExecutionPhase; constructor(actionOptions: ActionOptions); /** @@ -158,7 +159,7 @@ declare abstract class DetSysAction { execute(): void; getTemporaryName(): string; addFact(key: string, value: string | boolean): void; - getDiagnosticsUrl(): URL | undefined; + getDiagnosticsUrl(): Promise; getUniqueId(): string; getCorrelationHashes(): AnonymizedCorrelationHashes; recordEvent(eventName: string, context?: Record): void; diff --git a/dist/index.js b/dist/index.js index 9572a84..a90070c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -83,9 +83,9 @@ async function readAsyncOsReleaseFile(fileList, options) { ${fileData}`); } break; - } catch (error2) { + } catch (error3) { if (options.debug) { - console.error(error2); + console.error(error3); } } } @@ -107,9 +107,9 @@ function readSyncOsreleaseFile(releaseFileList, options) { ${fileData}`); } break; - } catch (error2) { + } catch (error3) { if (options.debug) { - console.error(error2); + console.error(error3); } } } @@ -301,6 +301,192 @@ function hashEnvironmentVariables(prefix, variables) { return `${prefix}-${hash.digest("hex")}`; } +// src/errors.ts +function stringifyError(e) { + if (e instanceof Error) { + return e.message; + } else if (typeof e === "string") { + return e; + } else { + return JSON.stringify(e); + } +} + +// src/ids-host.ts +import * as actionsCore3 from "@actions/core"; +import { resolveSrv } from "node:dns/promises"; +var DEFAULT_LOOKUP = "_detsys_ids._tcp.install.determinate.systems."; +var ALLOWED_SUFFIXES = [ + ".install.determinate.systems", + ".install.detsys.dev" +]; +var DEFAULT_IDS_HOST = "https://install.determinate.systems"; +var LOOKUP = process.env["IDS_LOOKUP"] ?? DEFAULT_LOOKUP; +var IdsHost = class { + constructor(idsProjectName, diagnosticsSuffix, runtimeDiagnosticsUrl) { + this.idsProjectName = idsProjectName; + this.diagnosticsSuffix = diagnosticsSuffix; + this.runtimeDiagnosticsUrl = runtimeDiagnosticsUrl; + } + markCurrentHostBroken() { + this.prioritizedURLs?.shift(); + } + setPrioritizedUrls(urls) { + this.prioritizedURLs = urls; + } + async getRootUrl() { + const idsHost = process.env["IDS_HOST"]; + if (idsHost !== void 0) { + try { + return new URL(idsHost); + } catch (err) { + actionsCore3.error( + `IDS_HOST environment variable is not a valid URL. Ignoring. ${stringifyError(err)}` + ); + } + } + let url = void 0; + try { + const urls = await this.getUrlsByPreference(); + url = urls[0]; + } catch (err) { + actionsCore3.error( + `Error collecting IDS URLs by preference: ${stringifyError(err)}` + ); + } + if (url === void 0) { + url = new URL(DEFAULT_IDS_HOST); + } + return new URL(url); + } + async getDiagnosticsUrl() { + if (this.runtimeDiagnosticsUrl === "") { + return void 0; + } + if (this.runtimeDiagnosticsUrl !== "-" && this.runtimeDiagnosticsUrl !== void 0) { + try { + return new URL(this.runtimeDiagnosticsUrl); + } catch (err) { + actionsCore3.info( + `User-provided diagnostic endpoint ignored: not a valid URL: ${stringifyError(err)}` + ); + } + } + try { + const diagnosticUrl = await this.getRootUrl(); + diagnosticUrl.pathname += this.idsProjectName; + diagnosticUrl.pathname += "/"; + diagnosticUrl.pathname += this.diagnosticsSuffix || "diagnostics"; + return diagnosticUrl; + } catch (err) { + actionsCore3.info( + `Generated diagnostic endpoint ignored, and diagnostics are disabled: not a valid URL: ${stringifyError(err)}` + ); + return void 0; + } + } + async getUrlsByPreference() { + if (this.prioritizedURLs === void 0) { + this.prioritizedURLs = orderRecordsByPriorityWeight( + await discoverServiceRecords() + ).flatMap((record) => recordToUrl(record) || []); + } + return this.prioritizedURLs; + } +}; +function recordToUrl(record) { + const urlStr = `https://${record.name}:${record.port}`; + try { + return new URL(urlStr); + } catch (err) { + actionsCore3.debug( + `Record ${JSON.stringify(record)} produced an invalid URL: ${urlStr} (${err})` + ); + return void 0; + } +} +async function discoverServiceRecords() { + return await discoverServicesStub(resolveSrv(LOOKUP), 1e3); +} +async function discoverServicesStub(lookup, timeout) { + const defaultFallback = new Promise( + (resolve, _reject) => { + setTimeout(resolve, timeout, []); + } + ); + let records; + try { + records = await Promise.race([lookup, defaultFallback]); + } catch (reason) { + actionsCore3.debug(`Error resolving SRV records: ${stringifyError(reason)}`); + records = []; + } + const acceptableRecords = records.filter((record) => { + for (const suffix of ALLOWED_SUFFIXES) { + if (record.name.endsWith(suffix)) { + return true; + } + } + actionsCore3.debug( + `Unacceptable domain due to an invalid suffix: ${record.name}` + ); + return false; + }); + if (acceptableRecords.length === 0) { + actionsCore3.debug(`No records found for ${LOOKUP}`); + } else { + actionsCore3.debug( + `Resolved ${LOOKUP} to ${JSON.stringify(acceptableRecords)}` + ); + } + return acceptableRecords; +} +function orderRecordsByPriorityWeight(records) { + const byPriorityWeight = /* @__PURE__ */ new Map(); + for (const record of records) { + const existing = byPriorityWeight.get(record.priority); + if (existing) { + existing.push(record); + } else { + byPriorityWeight.set(record.priority, [record]); + } + } + const prioritizedRecords = []; + const keys = Array.from(byPriorityWeight.keys()).sort( + (a, b) => a - b + ); + for (const priority of keys) { + const recordsByPrio = byPriorityWeight.get(priority); + if (recordsByPrio === void 0) { + continue; + } + prioritizedRecords.push(...weightedRandom(recordsByPrio)); + } + return prioritizedRecords; +} +function weightedRandom(records) { + const scratchRecords = records.slice(); + const result = []; + while (scratchRecords.length > 0) { + const weights = []; + { + for (let i = 0; i < scratchRecords.length; i++) { + weights.push( + scratchRecords[i].weight + (i > 0 ? scratchRecords[i - 1].weight : 0) + ); + } + } + const point = Math.random() * weights[weights.length - 1]; + for (let selectedIndex = 0; selectedIndex < weights.length; selectedIndex++) { + if (weights[selectedIndex] > point) { + result.push(scratchRecords.splice(selectedIndex, 1)[0]); + break; + } + } + } + return result; +} + // src/inputs.ts var inputs_exports = {}; __export(inputs_exports, { @@ -314,9 +500,9 @@ __export(inputs_exports, { getStringOrUndefined: () => getStringOrUndefined, handleString: () => handleString }); -import * as actionsCore3 from "@actions/core"; +import * as actionsCore4 from "@actions/core"; var getBool = (name) => { - return actionsCore3.getBooleanInput(name); + return actionsCore4.getBooleanInput(name); }; var getArrayOfStrings = (name, separator) => { const original = getString(name); @@ -339,7 +525,7 @@ var handleString = (input, separator) => { return trimmed.split(sepChar).map((s) => s.trim()); }; var getMultilineStringOrNull = (name) => { - const value = actionsCore3.getMultilineInput(name); + const value = actionsCore4.getMultilineInput(name); if (value.length === 0) { return null; } else { @@ -347,7 +533,7 @@ var getMultilineStringOrNull = (name) => { } }; var getNumberOrNull = (name) => { - const value = actionsCore3.getInput(name); + const value = actionsCore4.getInput(name); if (value === "") { return null; } else { @@ -355,10 +541,10 @@ var getNumberOrNull = (name) => { } }; var getString = (name) => { - return actionsCore3.getInput(name); + return actionsCore4.getInput(name); }; var getStringOrNull = (name) => { - const value = actionsCore3.getInput(name); + const value = actionsCore4.getInput(name); if (value === "") { return null; } else { @@ -366,7 +552,7 @@ var getStringOrNull = (name) => { } }; var getStringOrUndefined = (name) => { - const value = actionsCore3.getInput(name); + const value = actionsCore4.getInput(name); if (value === "") { return void 0; } else { @@ -380,14 +566,14 @@ __export(platform_exports, { getArchOs: () => getArchOs, getNixPlatform: () => getNixPlatform }); -import * as actionsCore4 from "@actions/core"; +import * as actionsCore5 from "@actions/core"; function getArchOs() { const envArch = process.env.RUNNER_ARCH; const envOs = process.env.RUNNER_OS; if (envArch && envOs) { return `${envArch}-${envOs}`; } else { - actionsCore4.error( + actionsCore5.error( `Can't identify the platform: RUNNER_ARCH or RUNNER_OS undefined (${envArch}-${envOs})` ); throw new Error("RUNNER_ARCH and/or RUNNER_OS is not defined"); @@ -404,7 +590,7 @@ function getNixPlatform(archOs) { if (mappedTo) { return mappedTo; } else { - actionsCore4.error( + actionsCore5.error( `ArchOs (${archOs}) doesn't map to a supported Nix platform.` ); throw new Error( @@ -414,7 +600,7 @@ function getNixPlatform(archOs) { } // src/sourcedef.ts -import * as actionsCore5 from "@actions/core"; +import * as actionsCore6 from "@actions/core"; function constructSourceParameters(legacyPrefix) { return { path: noisilyGetInput("path", legacyPrefix), @@ -432,12 +618,12 @@ function noisilyGetInput(suffix, legacyPrefix) { } const legacyInput = getStringOrUndefined(`${legacyPrefix}-${suffix}`); if (preferredInput && legacyInput) { - actionsCore5.warning( + actionsCore6.warning( `The supported option source-${suffix} and the legacy option ${legacyPrefix}-${suffix} are both set. Preferring source-${suffix}. Please stop setting ${legacyPrefix}-${suffix}.` ); return preferredInput; } else if (legacyInput) { - actionsCore5.warning( + actionsCore6.warning( `The legacy option ${legacyPrefix}-${suffix} is set. Please migrate to source-${suffix}.` ); return legacyInput; @@ -448,7 +634,7 @@ function noisilyGetInput(suffix, legacyPrefix) { // src/index.ts import * as actionsCache from "@actions/cache"; -import * as actionsCore6 from "@actions/core"; +import * as actionsCore7 from "@actions/core"; import * as actionsExec from "@actions/exec"; import got from "got"; import { exec as exec3 } from "node:child_process"; @@ -461,21 +647,6 @@ import * as path from "node:path"; import { pipeline } from "node:stream/promises"; import { promisify as promisify2 } from "node:util"; import { gzip } from "node:zlib"; - -// src/errors.ts -function stringifyError(e) { - if (e instanceof Error) { - return e.message; - } else if (typeof e === "string") { - return e; - } else { - return JSON.stringify(e); - } -} - -// src/index.ts -var DEFAULT_IDS_HOST = "https://install.determinate.systems"; -var IDS_HOST = process.env["IDS_HOST"] ?? DEFAULT_IDS_HOST; var EVENT_EXCEPTION = "exception"; var EVENT_ARTIFACT_CACHE_HIT = "artifact_cache_hit"; var EVENT_ARTIFACT_CACHE_MISS = "artifact_cache_miss"; @@ -499,9 +670,9 @@ var STATE_NOT_FOUND = "not-found"; var DIAGNOSTIC_ENDPOINT_TIMEOUT_MS = 3e4; var DetSysAction = class { determineExecutionPhase() { - const currentPhase = actionsCore6.getState(STATE_KEY_EXECUTION_PHASE); + const currentPhase = actionsCore7.getState(STATE_KEY_EXECUTION_PHASE); if (currentPhase === "") { - actionsCore6.saveState(STATE_KEY_EXECUTION_PHASE, "post"); + actionsCore7.saveState(STATE_KEY_EXECUTION_PHASE, "post"); return "main"; } else { return "post"; @@ -509,6 +680,13 @@ var DetSysAction = class { } constructor(actionOptions) { this.actionOptions = makeOptionsConfident(actionOptions); + this.idsHost = new IdsHost( + this.actionOptions.idsProjectName, + actionOptions.diagnosticsSuffix, + // Note: we don't use actionsCore.getInput('diagnostic-endpoint') on purpose: + // getInput silently converts absent data to an empty string. + process.env["INPUT_DIAGNOSTIC-ENDPOINT"] + ); this.exceptionAttachments = /* @__PURE__ */ new Map(); this.nixStoreTrust = "unknown"; this.strictMode = getBool("_internal-strict-mode"); @@ -520,9 +698,9 @@ var DetSysAction = class { }, hooks: { beforeRetry: [ - (error2, retryCount) => { - actionsCore6.info( - `Retrying after error ${error2.code}, retry #: ${retryCount}` + (error3, retryCount) => { + actionsCore7.info( + `Retrying after error ${error3.code}, retry #: ${retryCount}` ); } ] @@ -561,7 +739,7 @@ var DetSysAction = class { this.addFact(FACT_OS_VERSION, details.version); } }).catch((e) => { - actionsCore6.debug( + actionsCore7.debug( `Failure getting platform details: ${stringifyError2(e)}` ); }); @@ -599,8 +777,8 @@ var DetSysAction = class { * Execute the Action as defined. */ execute() { - this.executeAsync().catch((error2) => { - console.log(error2); + this.executeAsync().catch((error3) => { + console.log(error3); process.exitCode = 1; }); } @@ -611,8 +789,8 @@ var DetSysAction = class { addFact(key, value) { this.facts[key] = value; } - getDiagnosticsUrl() { - return this.actionOptions.diagnosticsUrl; + async getDiagnosticsUrl() { + return await this.idsHost.getDiagnosticsUrl(); } getUniqueId() { return this.identity.run_differentiator || process.env.RUNNER_TRACKING_ID || randomUUID(); @@ -682,9 +860,9 @@ var DetSysAction = class { const reportable = stringifyError2(e); this.addFact(FACT_FINAL_EXCEPTION, reportable); if (this.isPost) { - actionsCore6.warning(reportable); + actionsCore7.warning(reportable); } else { - actionsCore6.setFailed(reportable); + actionsCore7.setFailed(reportable); } const doGzip = promisify2(gzip); const exceptionContext = /* @__PURE__ */ new Map(); @@ -718,15 +896,15 @@ var DetSysAction = class { async fetchArtifact() { const sourceBinary = getStringOrNull("source-binary"); if (sourceBinary !== null && sourceBinary !== "") { - actionsCore6.debug(`Using the provided source binary at ${sourceBinary}`); + actionsCore7.debug(`Using the provided source binary at ${sourceBinary}`); return sourceBinary; } - actionsCore6.startGroup( + actionsCore7.startGroup( `Downloading ${this.actionOptions.name} for ${this.architectureFetchSuffix}` ); try { - actionsCore6.info(`Fetching from ${this.getSourceUrl()}`); - const correlatedUrl = this.getSourceUrl(); + actionsCore7.info(`Fetching from ${await this.getSourceUrl()}`); + const correlatedUrl = await this.getSourceUrl(); correlatedUrl.searchParams.set("ci", "github"); correlatedUrl.searchParams.set( "correlation", @@ -736,18 +914,18 @@ var DetSysAction = class { if (versionCheckup.headers.etag) { const v = versionCheckup.headers.etag; this.addFact(FACT_SOURCE_URL_ETAG, v); - actionsCore6.debug( - `Checking the tool cache for ${this.getSourceUrl()} at ${v}` + actionsCore7.debug( + `Checking the tool cache for ${await this.getSourceUrl()} at ${v}` ); const cached = await this.getCachedVersion(v); if (cached) { this.facts[FACT_ARTIFACT_FETCHED_FROM_CACHE] = true; - actionsCore6.debug(`Tool cache hit.`); + actionsCore7.debug(`Tool cache hit.`); return cached; } } this.facts[FACT_ARTIFACT_FETCHED_FROM_CACHE] = false; - actionsCore6.debug( + actionsCore7.debug( `No match from the cache, re-fetching from the redirect: ${versionCheckup.url}` ); const destFile = this.getTemporaryName(); @@ -764,12 +942,12 @@ var DetSysAction = class { try { await this.saveCachedVersion(v, destFile); } catch (e) { - actionsCore6.debug(`Error caching the artifact: ${stringifyError2(e)}`); + actionsCore7.debug(`Error caching the artifact: ${stringifyError2(e)}`); } } return destFile; } finally { - actionsCore6.endGroup(); + actionsCore7.endGroup(); } } /** @@ -778,20 +956,20 @@ var DetSysAction = class { */ failOnError(msg) { if (this.strictMode) { - actionsCore6.setFailed(`strict mode failure: ${msg}`); + actionsCore7.setFailed(`strict mode failure: ${msg}`); } } async complete() { this.recordEvent(`complete_${this.executionPhase}`); await this.submitEvents(); } - getSourceUrl() { + async getSourceUrl() { const p = this.sourceParameters; if (p.url) { this.addFact(FACT_SOURCE_URL, p.url); return new URL(p.url); } - const fetchUrl = new URL(IDS_HOST); + const fetchUrl = await this.idsHost.getRootUrl(); fetchUrl.pathname += this.actionOptions.idsProjectName; if (p.tag) { fetchUrl.pathname += `/tag/${p.tag}`; @@ -867,28 +1045,28 @@ var DetSysAction = class { const candidateNix = path.join(location, "nix"); try { await fs2.access(candidateNix, fs2.constants.X_OK); - actionsCore6.debug(`Found Nix at ${candidateNix}`); + actionsCore7.debug(`Found Nix at ${candidateNix}`); nixLocation = candidateNix; break; } catch { - actionsCore6.debug(`Nix not at ${candidateNix}`); + actionsCore7.debug(`Nix not at ${candidateNix}`); } } this.addFact(FACT_NIX_LOCATION, nixLocation || ""); if (this.actionOptions.requireNix === "ignore") { return true; } - const currentNotFoundState = actionsCore6.getState(STATE_KEY_NIX_NOT_FOUND); + const currentNotFoundState = actionsCore7.getState(STATE_KEY_NIX_NOT_FOUND); if (currentNotFoundState === STATE_NOT_FOUND) { return false; } if (nixLocation !== void 0) { return true; } - actionsCore6.saveState(STATE_KEY_NIX_NOT_FOUND, STATE_NOT_FOUND); + actionsCore7.saveState(STATE_KEY_NIX_NOT_FOUND, STATE_NOT_FOUND); switch (this.actionOptions.requireNix) { case "fail": - actionsCore6.setFailed( + actionsCore7.setFailed( [ "This action can only be used when Nix is installed.", "Add `- uses: DeterminateSystems/nix-installer-action@main` earlier in your workflow." @@ -896,7 +1074,7 @@ var DetSysAction = class { ); break; case "warn": - actionsCore6.warning( + actionsCore7.warning( [ "This action is in no-op mode because Nix is not installed.", "Add `- uses: DeterminateSystems/nix-installer-action@main` earlier in your workflow." @@ -947,11 +1125,12 @@ var DetSysAction = class { } } async submitEvents() { - if (this.actionOptions.diagnosticsUrl === void 0) { - actionsCore6.debug( + const diagnosticsUrl = await this.idsHost.getDiagnosticsUrl(); + if (diagnosticsUrl === void 0) { + actionsCore7.debug( "Diagnostics are disabled. Not sending the following events:" ); - actionsCore6.debug(JSON.stringify(this.events, void 0, 2)); + actionsCore7.debug(JSON.stringify(this.events, void 0, 2)); return; } const batch = { @@ -960,22 +1139,38 @@ var DetSysAction = class { events: this.events }; try { - await this.client.post(this.actionOptions.diagnosticsUrl, { + await this.client.post(diagnosticsUrl, { json: batch, timeout: { request: DIAGNOSTIC_ENDPOINT_TIMEOUT_MS } }); } catch (e) { - actionsCore6.debug( + actionsCore7.debug( `Error submitting diagnostics event: ${stringifyError2(e)}` ); + this.idsHost.markCurrentHostBroken(); + const secondaryDiagnosticsUrl = await this.idsHost.getDiagnosticsUrl(); + if (secondaryDiagnosticsUrl !== void 0) { + try { + await this.client.post(secondaryDiagnosticsUrl, { + json: batch, + timeout: { + request: DIAGNOSTIC_ENDPOINT_TIMEOUT_MS + } + }); + } catch (err) { + actionsCore7.debug( + `Error submitting diagnostics event to secondary host (${secondaryDiagnosticsUrl}): ${stringifyError2(err)}` + ); + } + } } this.events = []; } }; -function stringifyError2(error2) { - return error2 instanceof Error || typeof error2 == "string" ? error2.toString() : JSON.stringify(error2); +function stringifyError2(error3) { + return error3 instanceof Error || typeof error3 == "string" ? error3.toString() : JSON.stringify(error3); } function makeOptionsConfident(actionOptions) { const idsProjectName = actionOptions.idsProjectName ?? actionOptions.name; @@ -985,72 +1180,12 @@ function makeOptionsConfident(actionOptions) { eventPrefix: actionOptions.eventPrefix || "action:", fetchStyle: actionOptions.fetchStyle, legacySourcePrefix: actionOptions.legacySourcePrefix, - requireNix: actionOptions.requireNix, - diagnosticsUrl: determineDiagnosticsUrl( - idsProjectName, - actionOptions.diagnosticsUrl - ) + requireNix: actionOptions.requireNix }; - actionsCore6.debug("idslib options:"); - actionsCore6.debug(JSON.stringify(finalOpts, void 0, 2)); + actionsCore7.debug("idslib options:"); + actionsCore7.debug(JSON.stringify(finalOpts, void 0, 2)); return finalOpts; } -function determineDiagnosticsUrl(idsProjectName, urlOption) { - if (urlOption === null) { - return void 0; - } - if (urlOption !== void 0) { - return urlOption; - } - { - const providedDiagnosticEndpoint = process.env["INPUT_DIAGNOSTIC-ENDPOINT"]; - if (providedDiagnosticEndpoint === "") { - return void 0; - } - if (providedDiagnosticEndpoint !== void 0) { - try { - return mungeDiagnosticEndpoint(new URL(providedDiagnosticEndpoint)); - } catch (e) { - actionsCore6.info( - `User-provided diagnostic endpoint ignored: not a valid URL: ${stringifyError2(e)}` - ); - } - } - } - try { - const diagnosticUrl = new URL(IDS_HOST); - diagnosticUrl.pathname += idsProjectName; - diagnosticUrl.pathname += "/diagnostics"; - return diagnosticUrl; - } catch (e) { - actionsCore6.info( - `Generated diagnostic endpoint ignored: not a valid URL: ${stringifyError2(e)}` - ); - } - return void 0; -} -function mungeDiagnosticEndpoint(inputUrl) { - if (DEFAULT_IDS_HOST === IDS_HOST) { - return inputUrl; - } - try { - const defaultIdsHost = new URL(DEFAULT_IDS_HOST); - const currentIdsHost = new URL(IDS_HOST); - if (inputUrl.origin !== defaultIdsHost.origin) { - return inputUrl; - } - inputUrl.protocol = currentIdsHost.protocol; - inputUrl.host = currentIdsHost.host; - inputUrl.username = currentIdsHost.username; - inputUrl.password = currentIdsHost.password; - return inputUrl; - } catch (e) { - actionsCore6.info( - `Default or overridden IDS host isn't a valid URL: ${stringifyError2(e)}` - ); - } - return inputUrl; -} export { DetSysAction, inputs_exports as inputs, diff --git a/dist/index.js.map b/dist/index.js.map index 7b2d229..a185180 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"sources":["../package.json","../src/linux-release-info.ts","../src/actions-core-platform.ts","../src/correlation.ts","../src/inputs.ts","../src/platform.ts","../src/sourcedef.ts","../src/index.ts","../src/errors.ts"],"sourcesContent":["{\n \"name\": \"detsys-ts\",\n \"version\": \"1.0.0\",\n \"description\": \"TypeScript goodies for DetSys projects\",\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"type\": \"module\",\n \"scripts\": {\n \"build\": \"tsup\",\n \"check-fmt\": \"prettier --check .\",\n \"format\": \"prettier --write .\",\n \"lint\": \"eslint src/**/*.ts --ignore-pattern *.test.ts\",\n \"docs\": \"typedoc src/index.ts\",\n \"test\": \"vitest --watch false\",\n \"test-dev\": \"vitest\",\n \"all\": \"rm -rf dist && pnpm run format && pnpm run lint && pnpm run build\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/DeterminateSystems/detsys-ts.git\"\n },\n \"keywords\": [],\n \"author\": \"\",\n \"license\": \"MIT\",\n \"bugs\": {\n \"url\": \"https://github.com/DeterminateSystems/detsys-ts/issues\"\n },\n \"homepage\": \"https://github.com/DeterminateSystems/detsys-ts#readme\",\n \"dependencies\": {\n \"@actions/cache\": \"^3.2.4\",\n \"@actions/core\": \"^1.10.1\",\n \"@actions/exec\": \"^1.1.1\",\n \"got\": \"^14.2.1\"\n },\n \"devDependencies\": {\n \"@trivago/prettier-plugin-sort-imports\": \"^4.3.0\",\n \"@types/node\": \"^20.12.7\",\n \"@typescript-eslint/eslint-plugin\": \"^7.6.0\",\n \"eslint\": \"^8.57.0\",\n \"eslint-import-resolver-typescript\": \"^3.6.1\",\n \"eslint-plugin-github\": \"^4.10.2\",\n \"eslint-plugin-import\": \"^2.29.1\",\n \"eslint-plugin-prettier\": \"^5.1.3\",\n \"prettier\": \"^3.2.5\",\n \"tsup\": \"^8.0.2\",\n \"typedoc\": \"^0.25.13\",\n \"typescript\": \"^5.4.5\",\n \"vitest\": \"^1.5.2\"\n }\n}\n","/*!\n * linux-release-info\n * Get Linux release info (distribution name, version, arch, release, etc.)\n * from '/etc/os-release' or '/usr/lib/os-release' files and from native os\n * module. On Windows and Darwin platforms it only returns common node os module\n * info (platform, hostname, release, and arch)\n *\n * Licensed under MIT\n * Copyright (c) 2018-2020 [Samuel Carreira]\n */\n// NOTE: we depend on this directly to get around some un-fun issues with mixing CommonJS\n// and ESM in the bundle. We've modified the original logic to improve things like typing\n// and fixing ESLint issues. Originally drawn from:\n// https://github.com/samuelcarreira/linux-release-info/blob/84a91aa5442b47900da03020c590507545d3dc74/src/index.ts\nimport * as fs from \"node:fs\";\nimport * as os from \"node:os\";\nimport { promisify } from \"node:util\";\n\nconst readFileAsync = promisify(fs.readFile);\n\nexport interface LinuxReleaseInfoOptions {\n /**\n * read mode, possible values: 'async' and 'sync'\n *\n * @default 'async'\n */\n mode?: \"async\" | \"sync\";\n /**\n * custom complete file path with os info default null/none\n * if not provided the system will search on the '/etc/os-release'\n * and '/usr/lib/os-release' files\n *\n * @default null\n */\n customFile?: string | null | undefined;\n /**\n * if true, show console debug messages\n *\n * @default false\n */\n debug?: boolean;\n}\n\nconst linuxReleaseInfoOptionsDefaults: LinuxReleaseInfoOptions = {\n mode: \"async\",\n customFile: null,\n debug: false,\n};\n\n/**\n * Get OS release info from 'os-release' file and from native os module\n * on Windows or Darwin it only returns common os module info\n * (uses native fs module)\n * @returns {object} info from the current os\n */\nexport function releaseInfo(infoOptions: LinuxReleaseInfoOptions): object {\n const options = { ...linuxReleaseInfoOptionsDefaults, ...infoOptions };\n\n const searchOsReleaseFileList: string[] = osReleaseFileList(\n options.customFile,\n );\n\n if (os.type() !== \"Linux\") {\n if (options.mode === \"sync\") {\n return getOsInfo();\n } else {\n return Promise.resolve(getOsInfo());\n }\n }\n\n if (options.mode === \"sync\") {\n return readSyncOsreleaseFile(searchOsReleaseFileList, options);\n } else {\n return Promise.resolve(\n readAsyncOsReleaseFile(searchOsReleaseFileList, options),\n );\n }\n}\n\n/**\n * Format file data: convert data to object keys/values\n *\n * @param {object} sourceData Source object to be appended\n * @param {string} srcParseData Input file data to be parsed\n * @returns {object} Formated object\n */\nfunction formatFileData(sourceData: OsInfo, srcParseData: string): OsInfo {\n const lines: string[] = srcParseData.split(\"\\n\");\n\n for (const line of lines) {\n const lineData = line.split(\"=\");\n\n if (lineData.length === 2) {\n lineData[1] = lineData[1].replace(/[\"'\\r]/gi, \"\"); // remove quotes and return character\n\n Object.defineProperty(sourceData, lineData[0].toLowerCase(), {\n value: lineData[1],\n writable: true,\n enumerable: true,\n configurable: true,\n });\n }\n }\n\n return sourceData;\n}\n\n/**\n * Export a list of os-release files\n *\n * @param {string} customFile optional custom complete filepath\n * @returns {array} list of os-release files\n */\nfunction osReleaseFileList(customFile: string | null | undefined): string[] {\n const DEFAULT_OS_RELEASE_FILES = [\"/etc/os-release\", \"/usr/lib/os-release\"];\n\n if (!customFile) {\n return DEFAULT_OS_RELEASE_FILES;\n } else {\n return Array(customFile);\n }\n}\n\n/**\n * Operating system info.\n */\ntype OsInfo = {\n type: string;\n platform: string;\n hostname: string;\n arch: string;\n release: string;\n};\n\n/**\n * Get OS Basic Info\n * (uses node 'os' native module)\n *\n * @returns {OsInfo} os basic info\n */\nfunction getOsInfo(): OsInfo {\n return {\n type: os.type(),\n platform: os.platform(),\n hostname: os.hostname(),\n arch: os.arch(),\n release: os.release(),\n };\n}\n\n/* Helper functions */\n\nasync function readAsyncOsReleaseFile(\n fileList: string[],\n options: LinuxReleaseInfoOptions,\n): Promise {\n let fileData = null;\n\n for (const osReleaseFile of fileList) {\n try {\n if (options.debug) {\n /* eslint-disable no-console */\n console.log(`Trying to read '${osReleaseFile}'...`);\n }\n\n fileData = await readFileAsync(osReleaseFile, \"binary\");\n\n if (options.debug) {\n console.log(`Read data:\\n${fileData}`);\n }\n\n break;\n } catch (error) {\n if (options.debug) {\n console.error(error);\n }\n }\n }\n\n if (fileData === null) {\n throw new Error(\"Cannot read os-release file!\");\n //return getOsInfo();\n }\n\n return formatFileData(getOsInfo(), fileData);\n}\n\nfunction readSyncOsreleaseFile(\n releaseFileList: string[],\n options: LinuxReleaseInfoOptions,\n): OsInfo {\n let fileData = null;\n\n for (const osReleaseFile of releaseFileList) {\n try {\n if (options.debug) {\n console.log(`Trying to read '${osReleaseFile}'...`);\n }\n\n fileData = fs.readFileSync(osReleaseFile, \"binary\");\n\n if (options.debug) {\n console.log(`Read data:\\n${fileData}`);\n }\n\n break;\n } catch (error) {\n if (options.debug) {\n console.error(error);\n }\n }\n }\n\n if (fileData === null) {\n throw new Error(\"Cannot read os-release file!\");\n //return getOsInfo();\n }\n\n return formatFileData(getOsInfo(), fileData);\n}\n","// MIT, mostly lifted from https://github.com/actions/toolkit/blob/5a736647a123ecf8582376bdaee833fbae5b3847/packages/core/src/platform.ts\n// since it isn't in @actions/core 1.10.1 which is their current release as 2024-04-19.\n// Changes: Replaced the lsb_release call in Linux with `linux-release-info` to parse the os-release file directly.\nimport { releaseInfo } from \"./linux-release-info.js\";\nimport * as actionsCore from \"@actions/core\";\nimport * as exec from \"@actions/exec\";\nimport os from \"os\";\n\n/**\n * The name and version of the Action runner's system.\n */\ntype SystemInfo = {\n name: string;\n version: string;\n};\n\n/**\n * Get the name and version of the current Windows system.\n */\nconst getWindowsInfo = async (): Promise => {\n const { stdout: version } = await exec.getExecOutput(\n 'powershell -command \"(Get-CimInstance -ClassName Win32_OperatingSystem).Version\"',\n undefined,\n {\n silent: true,\n },\n );\n\n const { stdout: name } = await exec.getExecOutput(\n 'powershell -command \"(Get-CimInstance -ClassName Win32_OperatingSystem).Caption\"',\n undefined,\n {\n silent: true,\n },\n );\n\n return {\n name: name.trim(),\n version: version.trim(),\n };\n};\n\n/**\n * Get the name and version of the current macOS system.\n */\nconst getMacOsInfo = async (): Promise => {\n const { stdout } = await exec.getExecOutput(\"sw_vers\", undefined, {\n silent: true,\n });\n\n const version = stdout.match(/ProductVersion:\\s*(.+)/)?.[1] ?? \"\";\n const name = stdout.match(/ProductName:\\s*(.+)/)?.[1] ?? \"\";\n\n return {\n name,\n version,\n };\n};\n\n/**\n * Get the name and version of the current Linux system.\n */\nconst getLinuxInfo = async (): Promise => {\n let data: object = {};\n\n try {\n data = releaseInfo({ mode: \"sync\" });\n actionsCore.debug(`Identified release info: ${JSON.stringify(data)}`);\n } catch (e) {\n actionsCore.debug(`Error collecting release info: ${e}`);\n }\n\n return {\n name: getPropertyViaWithDefault(\n data,\n [\"id\", \"name\", \"pretty_name\", \"id_like\"],\n \"unknown\",\n ),\n version: getPropertyViaWithDefault(\n data,\n [\"version_id\", \"version\", \"version_codename\"],\n \"unknown\",\n ),\n };\n};\n\nfunction getPropertyViaWithDefault(\n data: object,\n names: Property[],\n defaultValue: T,\n): T {\n for (const name of names) {\n const ret: T = getPropertyWithDefault(data, name, defaultValue);\n\n if (ret !== defaultValue) {\n return ret;\n }\n }\n\n return defaultValue;\n}\n\nfunction getPropertyWithDefault(\n data: object,\n name: Property,\n defaultValue: T,\n): T {\n if (!data.hasOwnProperty(name)) {\n return defaultValue;\n }\n\n const value = (data as { [K in Property]: T })[name];\n\n // NB. this check won't work for object instances\n if (typeof value !== typeof defaultValue) {\n return defaultValue;\n }\n\n return value;\n}\n\n/**\n * The Action runner's platform.\n */\nexport const platform = os.platform();\n\n/**\n * The Action runner's architecture.\n */\nexport const arch = os.arch();\n\n/**\n * Whether the Action runner is a Windows system.\n */\nexport const isWindows = platform === \"win32\";\n\n/**\n * Whether the Action runner is a macOS system.\n */\nexport const isMacOS = platform === \"darwin\";\n\n/**\n * Whether the Action runner is a Linux system.\n */\nexport const isLinux = platform === \"linux\";\n\n/**\n * System-level information about the current host (platform, architecture, etc.).\n */\ntype SystemDetails = {\n name: string;\n platform: string;\n arch: string;\n version: string;\n isWindows: boolean;\n isMacOS: boolean;\n isLinux: boolean;\n};\n\n/**\n * Get system-level information about the current host (platform, architecture, etc.).\n */\nexport async function getDetails(): Promise {\n return {\n ...(await (isWindows\n ? getWindowsInfo()\n : isMacOS\n ? getMacOsInfo()\n : getLinuxInfo())),\n platform,\n arch,\n isWindows,\n isMacOS,\n isLinux,\n };\n}\n","import * as actionsCore from \"@actions/core\";\nimport { createHash } from \"node:crypto\";\n\nconst OPTIONAL_VARIABLES = [\"INVOCATION_ID\"];\n\n// JSON sent to server\n/* eslint-disable camelcase */\nexport type AnonymizedCorrelationHashes = {\n correlation_source: string;\n repository?: string;\n run?: string;\n run_differentiator?: string;\n workflow?: string;\n groups: Record;\n};\n\nexport function identify(projectName: string): AnonymizedCorrelationHashes {\n const ident = {\n correlation_source: \"github-actions\",\n\n repository: hashEnvironmentVariables(\"GHR\", [\n \"GITHUB_SERVER_URL\",\n \"GITHUB_REPOSITORY_OWNER\",\n \"GITHUB_REPOSITORY_OWNER_ID\",\n \"GITHUB_REPOSITORY\",\n \"GITHUB_REPOSITORY_ID\",\n ]),\n workflow: hashEnvironmentVariables(\"GHW\", [\n \"GITHUB_SERVER_URL\",\n \"GITHUB_REPOSITORY_OWNER\",\n \"GITHUB_REPOSITORY_OWNER_ID\",\n \"GITHUB_REPOSITORY\",\n \"GITHUB_REPOSITORY_ID\",\n \"GITHUB_WORKFLOW\",\n ]),\n job: hashEnvironmentVariables(\"GHWJ\", [\n \"GITHUB_SERVER_URL\",\n \"GITHUB_REPOSITORY_OWNER\",\n \"GITHUB_REPOSITORY_OWNER_ID\",\n \"GITHUB_REPOSITORY\",\n \"GITHUB_REPOSITORY_ID\",\n \"GITHUB_WORKFLOW\",\n \"GITHUB_JOB\",\n ]),\n run: hashEnvironmentVariables(\"GHWJR\", [\n \"GITHUB_SERVER_URL\",\n \"GITHUB_REPOSITORY_OWNER\",\n \"GITHUB_REPOSITORY_OWNER_ID\",\n \"GITHUB_REPOSITORY\",\n \"GITHUB_REPOSITORY_ID\",\n \"GITHUB_WORKFLOW\",\n \"GITHUB_JOB\",\n \"GITHUB_RUN_ID\",\n ]),\n run_differentiator: hashEnvironmentVariables(\"GHWJA\", [\n \"GITHUB_SERVER_URL\",\n \"GITHUB_REPOSITORY_OWNER\",\n \"GITHUB_REPOSITORY_OWNER_ID\",\n \"GITHUB_REPOSITORY\",\n \"GITHUB_REPOSITORY_ID\",\n \"GITHUB_WORKFLOW\",\n \"GITHUB_JOB\",\n \"GITHUB_RUN_ID\",\n \"GITHUB_RUN_NUMBER\",\n \"GITHUB_RUN_ATTEMPT\",\n \"INVOCATION_ID\",\n ]),\n groups: {\n ci: \"github-actions\",\n project: projectName,\n github_organization: hashEnvironmentVariables(\"GHO\", [\n \"GITHUB_SERVER_URL\",\n \"GITHUB_REPOSITORY_OWNER\",\n \"GITHUB_REPOSITORY_OWNER_ID\",\n ]),\n },\n };\n\n actionsCore.debug(\"Correlation data:\");\n actionsCore.debug(JSON.stringify(ident, null, 2));\n\n return ident;\n}\n\nfunction hashEnvironmentVariables(\n prefix: string,\n variables: string[],\n): undefined | string {\n const hash = createHash(\"sha256\");\n\n for (const varName of variables) {\n let value = process.env[varName];\n\n if (value === undefined) {\n if (OPTIONAL_VARIABLES.includes(varName)) {\n actionsCore.debug(\n `Optional environment variable not set: ${varName} -- substituting with the variable name`,\n );\n value = varName;\n } else {\n actionsCore.debug(\n `Environment variable not set: ${varName} -- can't generate the requested identity`,\n );\n return undefined;\n }\n }\n\n hash.update(value);\n hash.update(\"\\0\");\n }\n\n return `${prefix}-${hash.digest(\"hex\")}`;\n}\n","/**\n * @packageDocumentation\n * Helpers for getting values from an Action's configuration.\n */\nimport * as actionsCore from \"@actions/core\";\n\n/**\n * Get a Boolean input from the Action's configuration by name.\n */\nconst getBool = (name: string): boolean => {\n return actionsCore.getBooleanInput(name);\n};\n\n/**\n * The character used to separate values in the input string.\n */\nexport type Separator = \"space\" | \"comma\";\n\n/**\n * Convert a comma-separated string input into an array of strings. If `comma` is selected,\n * all whitespace is removed from the string before converting to an array.\n */\nconst getArrayOfStrings = (name: string, separator: Separator): string[] => {\n const original = getString(name);\n return handleString(original, separator);\n};\n\n/**\n * Convert a string input into an array of strings or `null` if no value is set.\n */\nconst getArrayOfStringsOrNull = (\n name: string,\n separator: Separator,\n): string[] | null => {\n const original = getStringOrNull(name);\n if (original === null) {\n return null;\n } else {\n return handleString(original, separator);\n }\n};\n\n// Split out this function for use in testing\nexport const handleString = (input: string, separator: Separator): string[] => {\n const sepChar = separator === \"comma\" ? \",\" : /\\s+/;\n const trimmed = input.trim(); // Remove whitespace at the beginning and end\n if (trimmed === \"\") {\n return [];\n }\n\n return trimmed.split(sepChar).map((s: string) => s.trim());\n};\n\n/**\n * Get a multi-line string input from the Action's configuration by name or return `null` if not set.\n */\nconst getMultilineStringOrNull = (name: string): string[] | null => {\n const value = actionsCore.getMultilineInput(name);\n if (value.length === 0) {\n return null;\n } else {\n return value;\n }\n};\n\n/**\n * Get a number input from the Action's configuration by name or return `null` if not set.\n */\nconst getNumberOrNull = (name: string): number | null => {\n const value = actionsCore.getInput(name);\n if (value === \"\") {\n return null;\n } else {\n return Number(value);\n }\n};\n\n/**\n * Get a string input from the Action's configuration.\n */\nconst getString = (name: string): string => {\n return actionsCore.getInput(name);\n};\n\n/**\n * Get a string input from the Action's configuration by name or return `null` if not set.\n */\nconst getStringOrNull = (name: string): string | null => {\n const value = actionsCore.getInput(name);\n if (value === \"\") {\n return null;\n } else {\n return value;\n }\n};\n\n/**\n * Get a string input from the Action's configuration by name or return `undefined` if not set.\n */\nconst getStringOrUndefined = (name: string): string | undefined => {\n const value = actionsCore.getInput(name);\n if (value === \"\") {\n return undefined;\n } else {\n return value;\n }\n};\n\nexport {\n getBool,\n getArrayOfStrings,\n getArrayOfStringsOrNull,\n getMultilineStringOrNull,\n getNumberOrNull,\n getString,\n getStringOrNull,\n getStringOrUndefined,\n};\n","/**\n * @packageDocumentation\n * Helpers for determining system attributes of the current runner.\n */\nimport * as actionsCore from \"@actions/core\";\n\n/**\n * Get the current architecture plus OS. Examples include `X64-Linux` and `ARM64-macOS`.\n */\nexport function getArchOs(): string {\n const envArch = process.env.RUNNER_ARCH;\n const envOs = process.env.RUNNER_OS;\n\n if (envArch && envOs) {\n return `${envArch}-${envOs}`;\n } else {\n actionsCore.error(\n `Can't identify the platform: RUNNER_ARCH or RUNNER_OS undefined (${envArch}-${envOs})`,\n );\n throw new Error(\"RUNNER_ARCH and/or RUNNER_OS is not defined\");\n }\n}\n\n/**\n * Get the current Nix system. Examples include `x86_64-linux` and `aarch64-darwin`.\n */\nexport function getNixPlatform(archOs: string): string {\n const archOsMap: Map = new Map([\n [\"X64-macOS\", \"x86_64-darwin\"],\n [\"ARM64-macOS\", \"aarch64-darwin\"],\n [\"X64-Linux\", \"x86_64-linux\"],\n [\"ARM64-Linux\", \"aarch64-linux\"],\n ]);\n\n const mappedTo = archOsMap.get(archOs);\n if (mappedTo) {\n return mappedTo;\n } else {\n actionsCore.error(\n `ArchOs (${archOs}) doesn't map to a supported Nix platform.`,\n );\n throw new Error(\n `Cannot convert ArchOs (${archOs}) to a supported Nix platform.`,\n );\n }\n}\n","import { getStringOrUndefined } from \"./inputs.js\";\nimport * as actionsCore from \"@actions/core\";\n\nexport type SourceDef = {\n path?: string;\n url?: string;\n tag?: string;\n pr?: string;\n branch?: string;\n revision?: string;\n};\n\nexport function constructSourceParameters(legacyPrefix?: string): SourceDef {\n return {\n path: noisilyGetInput(\"path\", legacyPrefix),\n url: noisilyGetInput(\"url\", legacyPrefix),\n tag: noisilyGetInput(\"tag\", legacyPrefix),\n pr: noisilyGetInput(\"pr\", legacyPrefix),\n branch: noisilyGetInput(\"branch\", legacyPrefix),\n revision: noisilyGetInput(\"revision\", legacyPrefix),\n };\n}\n\nfunction noisilyGetInput(\n suffix: string,\n legacyPrefix: string | undefined,\n): string | undefined {\n const preferredInput = getStringOrUndefined(`source-${suffix}`);\n\n if (!legacyPrefix) {\n return preferredInput;\n }\n\n // Remaining is for handling cases where the legacy prefix\n // should be examined.\n const legacyInput = getStringOrUndefined(`${legacyPrefix}-${suffix}`);\n\n if (preferredInput && legacyInput) {\n actionsCore.warning(\n `The supported option source-${suffix} and the legacy option ${legacyPrefix}-${suffix} are both set. Preferring source-${suffix}. Please stop setting ${legacyPrefix}-${suffix}.`,\n );\n return preferredInput;\n } else if (legacyInput) {\n actionsCore.warning(\n `The legacy option ${legacyPrefix}-${suffix} is set. Please migrate to source-${suffix}.`,\n );\n return legacyInput;\n } else {\n return preferredInput;\n }\n}\n","/**\n * @packageDocumentation\n * Determinate Systems' TypeScript library for creating GitHub Actions logic.\n */\nimport { version as pkgVersion } from \"../package.json\";\nimport * as ghActionsCorePlatform from \"./actions-core-platform.js\";\nimport * as correlation from \"./correlation.js\";\nimport { getBool, getStringOrNull } from \"./inputs.js\";\nimport * as platform from \"./platform.js\";\nimport { SourceDef, constructSourceParameters } from \"./sourcedef.js\";\nimport * as actionsCache from \"@actions/cache\";\nimport * as actionsCore from \"@actions/core\";\nimport * as actionsExec from \"@actions/exec\";\nimport got, { Got } from \"got\";\nimport { exec } from \"node:child_process\";\nimport { UUID, randomUUID } from \"node:crypto\";\nimport { PathLike, createWriteStream, readFileSync } from \"node:fs\";\nimport fs, { chmod, copyFile, mkdir } from \"node:fs/promises\";\nimport * as os from \"node:os\";\nimport { tmpdir } from \"node:os\";\nimport * as path from \"node:path\";\nimport { pipeline } from \"node:stream/promises\";\nimport { promisify } from \"node:util\";\nimport { gzip } from \"node:zlib\";\n\nconst DEFAULT_IDS_HOST = \"https://install.determinate.systems\";\nconst IDS_HOST = process.env[\"IDS_HOST\"] ?? DEFAULT_IDS_HOST;\n\nconst EVENT_EXCEPTION = \"exception\";\nconst EVENT_ARTIFACT_CACHE_HIT = \"artifact_cache_hit\";\nconst EVENT_ARTIFACT_CACHE_MISS = \"artifact_cache_miss\";\nconst EVENT_ARTIFACT_CACHE_PERSIST = \"artifact_cache_persist\";\nconst EVENT_PREFLIGHT_REQUIRE_NIX_DENIED = \"preflight-require-nix-denied\";\n\nconst FACT_ARTIFACT_FETCHED_FROM_CACHE = \"artifact_fetched_from_cache\";\nconst FACT_ENDED_WITH_EXCEPTION = \"ended_with_exception\";\nconst FACT_FINAL_EXCEPTION = \"final_exception\";\nconst FACT_OS = \"$os\";\nconst FACT_OS_VERSION = \"$os_version\";\nconst FACT_SOURCE_URL = \"source_url\";\nconst FACT_SOURCE_URL_ETAG = \"source_url_etag\";\n\nconst FACT_NIX_LOCATION = \"nix_location\";\nconst FACT_NIX_STORE_TRUST = \"nix_store_trusted\";\nconst FACT_NIX_STORE_VERSION = \"nix_store_version\";\nconst FACT_NIX_STORE_CHECK_METHOD = \"nix_store_check_method\";\nconst FACT_NIX_STORE_CHECK_ERROR = \"nix_store_check_error\";\n\nconst STATE_KEY_EXECUTION_PHASE = \"detsys_action_execution_phase\";\nconst STATE_KEY_NIX_NOT_FOUND = \"detsys_action_nix_not_found\";\nconst STATE_NOT_FOUND = \"not-found\";\n\nconst DIAGNOSTIC_ENDPOINT_TIMEOUT_MS = 30_000; // 30 seconds in milliseconds\n\n/**\n * An enum for describing different \"fetch suffixes\" for i.d.s.\n *\n * - `nix-style` means that system names like `x86_64-linux` and `aarch64-darwin` are used\n * - `gh-env-style` means that names like `X64-Linux` and `ARM64-macOS` are used\n * - `universal` means that the suffix is the static `universal` (for non-system-specific things)\n */\nexport type FetchSuffixStyle = \"nix-style\" | \"gh-env-style\" | \"universal\";\n\n/**\n * GitHub Actions has two possible execution phases: `main` and `post`.\n */\nexport type ExecutionPhase = \"main\" | \"post\";\n\n/**\n * How to handle whether Nix is currently installed on the runner.\n *\n * - `fail` means that the workflow fails if Nix isn't installed\n * - `warn` means that a warning is logged if Nix isn't installed\n * - `ignore` means that Nix will not be checked\n */\nexport type NixRequirementHandling = \"fail\" | \"warn\" | \"ignore\";\n\n/**\n * Whether the Nix store on the runner is trusted.\n *\n * - `trusted` means yes\n * - `untrusted` means no\n * - `unknown` means that the status couldn't be determined\n *\n * This is determined via the output of `nix store info --json`.\n */\nexport type NixStoreTrust = \"trusted\" | \"untrusted\" | \"unknown\";\n\nexport type ActionOptions = {\n // Name of the project generally, and the name of the binary on disk.\n name: string;\n\n // Defaults to `name`, Corresponds to the ProjectHost entry on i.d.s.\n idsProjectName?: string;\n\n // Defaults to `action:`\n eventPrefix?: string;\n\n // The \"architecture\" URL component expected by I.D.S. for the ProjectHost.\n fetchStyle: FetchSuffixStyle;\n\n // IdsToolbox assumes the GitHub Action exposes source overrides, like branch/pr/etc. to be named `source-*`.\n // This prefix adds a fallback name, prefixed by `${legacySourcePrefix}-`.\n // Users who configure legacySourcePrefix will get warnings asking them to change to `source-*`.\n legacySourcePrefix?: string;\n\n // Check if Nix is installed before running this action.\n // If Nix isn't installed, this action will not fail, and will instead do nothing.\n // The action will emit a user-visible warning instructing them to install Nix.\n requireNix: NixRequirementHandling;\n\n // The URL to send diagnostics events to.\n // Specifically:\n // * `undefined` -> Attempt to read the `diagnostic-enpdoint` action input, and calculate the default diagnostics URL for IDS from there.\n // * `null` -> Disable sending diagnostics altogether.\n // * URL(...) -> Send diagnostics to this other URL instead\n diagnosticsUrl?: URL | null;\n};\n\n// A confident version of Options, where defaults have been resolved into final values\ntype ConfidentActionOptions = {\n name: string;\n idsProjectName: string;\n eventPrefix: string;\n fetchStyle: FetchSuffixStyle;\n legacySourcePrefix?: string;\n requireNix: NixRequirementHandling;\n diagnosticsUrl?: URL;\n};\n\ntype DiagnosticEvent = {\n event_name: string;\n correlation: correlation.AnonymizedCorrelationHashes;\n facts: Record;\n context: Record;\n timestamp: Date;\n uuid: UUID;\n};\n\nexport abstract class DetSysAction {\n nixStoreTrust: NixStoreTrust;\n\n private actionOptions: ConfidentActionOptions;\n private strictMode: boolean;\n private client: Got;\n private exceptionAttachments: Map;\n private archOs: string;\n private executionPhase: ExecutionPhase;\n private nixSystem: string;\n private architectureFetchSuffix: string;\n private sourceParameters: SourceDef;\n private facts: Record;\n private events: DiagnosticEvent[];\n private identity: correlation.AnonymizedCorrelationHashes;\n\n private determineExecutionPhase(): ExecutionPhase {\n const currentPhase = actionsCore.getState(STATE_KEY_EXECUTION_PHASE);\n if (currentPhase === \"\") {\n actionsCore.saveState(STATE_KEY_EXECUTION_PHASE, \"post\");\n return \"main\";\n } else {\n return \"post\";\n }\n }\n\n constructor(actionOptions: ActionOptions) {\n this.actionOptions = makeOptionsConfident(actionOptions);\n this.exceptionAttachments = new Map();\n this.nixStoreTrust = \"unknown\";\n this.strictMode = getBool(\"_internal-strict-mode\");\n\n this.events = [];\n this.client = got.extend({\n retry: {\n limit: 3,\n methods: [\"GET\", \"HEAD\"],\n },\n hooks: {\n beforeRetry: [\n (error, retryCount) => {\n actionsCore.info(\n `Retrying after error ${error.code}, retry #: ${retryCount}`,\n );\n },\n ],\n },\n });\n\n // JSON sent to server\n /* eslint-disable camelcase */\n this.facts = {\n $lib: \"idslib\",\n $lib_version: pkgVersion,\n project: this.actionOptions.name,\n ids_project: this.actionOptions.idsProjectName,\n };\n\n const params = [\n [\"github_action_ref\", \"GITHUB_ACTION_REF\"],\n [\"github_action_repository\", \"GITHUB_ACTION_REPOSITORY\"],\n [\"github_event_name\", \"GITHUB_EVENT_NAME\"],\n [\"$os\", \"RUNNER_OS\"],\n [\"arch\", \"RUNNER_ARCH\"],\n ];\n for (const [target, env] of params) {\n const value = process.env[env];\n if (value) {\n this.facts[target] = value;\n }\n }\n\n this.identity = correlation.identify(this.actionOptions.name);\n this.archOs = platform.getArchOs();\n this.nixSystem = platform.getNixPlatform(this.archOs);\n\n this.facts.arch_os = this.archOs;\n this.facts.nix_system = this.nixSystem;\n\n {\n ghActionsCorePlatform\n .getDetails()\n // eslint-disable-next-line github/no-then\n .then((details) => {\n if (details.name !== \"unknown\") {\n this.addFact(FACT_OS, details.name);\n }\n if (details.version !== \"unknown\") {\n this.addFact(FACT_OS_VERSION, details.version);\n }\n })\n // eslint-disable-next-line github/no-then\n .catch((e: unknown) => {\n actionsCore.debug(\n `Failure getting platform details: ${stringifyError(e)}`,\n );\n });\n }\n\n this.executionPhase = this.determineExecutionPhase();\n this.facts.execution_phase = this.executionPhase;\n\n if (this.actionOptions.fetchStyle === \"gh-env-style\") {\n this.architectureFetchSuffix = this.archOs;\n } else if (this.actionOptions.fetchStyle === \"nix-style\") {\n this.architectureFetchSuffix = this.nixSystem;\n } else if (this.actionOptions.fetchStyle === \"universal\") {\n this.architectureFetchSuffix = \"universal\";\n } else {\n throw new Error(\n `fetchStyle ${this.actionOptions.fetchStyle} is not a valid style`,\n );\n }\n\n this.sourceParameters = constructSourceParameters(\n this.actionOptions.legacySourcePrefix,\n );\n\n this.recordEvent(`begin_${this.executionPhase}`);\n }\n\n /**\n * Attach a file to the diagnostics data in error conditions.\n *\n * The file at `location` doesn't need to exist when stapleFile is called.\n *\n * If the file doesn't exist or is unreadable when trying to staple the attachments, the JS error will be stored in a context value at `staple_failure_{name}`.\n * If the file is readable, the file's contents will be stored in a context value at `staple_value_{name}`.\n */\n stapleFile(name: string, location: string): void {\n this.exceptionAttachments.set(name, location);\n }\n\n /**\n * The main execution phase.\n */\n abstract main(): Promise;\n\n /**\n * The post execution phase.\n */\n abstract post(): Promise;\n\n /**\n * Execute the Action as defined.\n */\n execute(): void {\n // eslint-disable-next-line github/no-then\n this.executeAsync().catch((error: Error) => {\n // eslint-disable-next-line no-console\n console.log(error);\n process.exitCode = 1;\n });\n }\n\n getTemporaryName(): string {\n const tmpDir = process.env[\"RUNNER_TEMP\"] || tmpdir();\n return path.join(tmpDir, `${this.actionOptions.name}-${randomUUID()}`);\n }\n\n addFact(key: string, value: string | boolean): void {\n this.facts[key] = value;\n }\n\n getDiagnosticsUrl(): URL | undefined {\n return this.actionOptions.diagnosticsUrl;\n }\n\n getUniqueId(): string {\n return (\n this.identity.run_differentiator ||\n process.env.RUNNER_TRACKING_ID ||\n randomUUID()\n );\n }\n\n getCorrelationHashes(): correlation.AnonymizedCorrelationHashes {\n return this.identity;\n }\n\n recordEvent(eventName: string, context: Record = {}): void {\n this.events.push({\n event_name: `${this.actionOptions.eventPrefix}${eventName}`,\n context,\n correlation: this.identity,\n facts: this.facts,\n timestamp: new Date(),\n uuid: randomUUID(),\n });\n }\n\n /**\n * Unpacks the closure returned by `fetchArtifact()`, imports the\n * contents into the Nix store, and returns the path of the executable at\n * `/nix/store/STORE_PATH/bin/${bin}`.\n */\n async unpackClosure(bin: string): Promise {\n const artifact = await this.fetchArtifact();\n const { stdout } = await promisify(exec)(\n `cat \"${artifact}\" | xz -d | nix-store --import`,\n );\n const paths = stdout.split(os.EOL);\n const lastPath = paths.at(-2);\n return `${lastPath}/bin/${bin}`;\n }\n\n /**\n * Fetches the executable at the URL determined by the `source-*` inputs and\n * other facts, `chmod`s it, and returns the path to the executable on disk.\n */\n async fetchExecutable(): Promise {\n const binaryPath = await this.fetchArtifact();\n await chmod(binaryPath, fs.constants.S_IXUSR | fs.constants.S_IXGRP);\n return binaryPath;\n }\n\n private get isMain(): boolean {\n return this.executionPhase === \"main\";\n }\n\n private get isPost(): boolean {\n return this.executionPhase === \"post\";\n }\n\n private async executeAsync(): Promise {\n try {\n process.env.DETSYS_CORRELATION = JSON.stringify(\n this.getCorrelationHashes(),\n );\n\n if (!(await this.preflightRequireNix())) {\n this.recordEvent(EVENT_PREFLIGHT_REQUIRE_NIX_DENIED);\n return;\n } else {\n await this.preflightNixStoreInfo();\n this.addFact(FACT_NIX_STORE_TRUST, this.nixStoreTrust);\n }\n\n if (this.isMain) {\n await this.main();\n } else if (this.isPost) {\n await this.post();\n }\n this.addFact(FACT_ENDED_WITH_EXCEPTION, false);\n } catch (e: unknown) {\n this.addFact(FACT_ENDED_WITH_EXCEPTION, true);\n\n const reportable = stringifyError(e);\n\n this.addFact(FACT_FINAL_EXCEPTION, reportable);\n\n if (this.isPost) {\n actionsCore.warning(reportable);\n } else {\n actionsCore.setFailed(reportable);\n }\n\n const doGzip = promisify(gzip);\n\n const exceptionContext: Map = new Map();\n for (const [attachmentLabel, filePath] of this.exceptionAttachments) {\n try {\n const logText = readFileSync(filePath);\n const buf = await doGzip(logText);\n exceptionContext.set(\n `staple_value_${attachmentLabel}`,\n buf.toString(\"base64\"),\n );\n } catch (innerError: unknown) {\n exceptionContext.set(\n `staple_failure_${attachmentLabel}`,\n stringifyError(innerError),\n );\n }\n }\n\n this.recordEvent(EVENT_EXCEPTION, Object.fromEntries(exceptionContext));\n } finally {\n await this.complete();\n }\n }\n\n /**\n * Fetch an artifact, such as a tarball, from the location determined by the\n * `source-*` inputs. If `source-binary` is specified, this will return a path\n * to a binary on disk; otherwise, the artifact will be downloaded from the\n * URL determined by the other `source-*` inputs (`source-url`, `source-pr`,\n * etc.).\n */\n private async fetchArtifact(): Promise {\n const sourceBinary = getStringOrNull(\"source-binary\");\n\n // If source-binary is set, use that. Otherwise fall back to the source-* parameters.\n if (sourceBinary !== null && sourceBinary !== \"\") {\n actionsCore.debug(`Using the provided source binary at ${sourceBinary}`);\n return sourceBinary;\n }\n\n actionsCore.startGroup(\n `Downloading ${this.actionOptions.name} for ${this.architectureFetchSuffix}`,\n );\n\n try {\n actionsCore.info(`Fetching from ${this.getSourceUrl()}`);\n\n const correlatedUrl = this.getSourceUrl();\n correlatedUrl.searchParams.set(\"ci\", \"github\");\n correlatedUrl.searchParams.set(\n \"correlation\",\n JSON.stringify(this.identity),\n );\n\n const versionCheckup = await this.client.head(correlatedUrl);\n if (versionCheckup.headers.etag) {\n const v = versionCheckup.headers.etag;\n this.addFact(FACT_SOURCE_URL_ETAG, v);\n\n actionsCore.debug(\n `Checking the tool cache for ${this.getSourceUrl()} at ${v}`,\n );\n const cached = await this.getCachedVersion(v);\n if (cached) {\n this.facts[FACT_ARTIFACT_FETCHED_FROM_CACHE] = true;\n actionsCore.debug(`Tool cache hit.`);\n return cached;\n }\n }\n\n this.facts[FACT_ARTIFACT_FETCHED_FROM_CACHE] = false;\n\n actionsCore.debug(\n `No match from the cache, re-fetching from the redirect: ${versionCheckup.url}`,\n );\n\n const destFile = this.getTemporaryName();\n const fetchStream = this.client.stream(versionCheckup.url);\n\n await pipeline(\n fetchStream,\n createWriteStream(destFile, {\n encoding: \"binary\",\n mode: 0o755,\n }),\n );\n\n if (fetchStream.response?.headers.etag) {\n const v = fetchStream.response.headers.etag;\n\n try {\n await this.saveCachedVersion(v, destFile);\n } catch (e: unknown) {\n actionsCore.debug(`Error caching the artifact: ${stringifyError(e)}`);\n }\n }\n\n return destFile;\n } finally {\n actionsCore.endGroup();\n }\n }\n\n /**\n * A helper function for failing on error only if strict mode is enabled.\n * This is intended only for CI environments testing Actions themselves.\n */\n failOnError(msg: string): void {\n if (this.strictMode) {\n actionsCore.setFailed(`strict mode failure: ${msg}`);\n }\n }\n\n private async complete(): Promise {\n this.recordEvent(`complete_${this.executionPhase}`);\n await this.submitEvents();\n }\n\n private getSourceUrl(): URL {\n const p = this.sourceParameters;\n\n if (p.url) {\n this.addFact(FACT_SOURCE_URL, p.url);\n return new URL(p.url);\n }\n\n const fetchUrl = new URL(IDS_HOST);\n fetchUrl.pathname += this.actionOptions.idsProjectName;\n\n if (p.tag) {\n fetchUrl.pathname += `/tag/${p.tag}`;\n } else if (p.pr) {\n fetchUrl.pathname += `/pr/${p.pr}`;\n } else if (p.branch) {\n fetchUrl.pathname += `/branch/${p.branch}`;\n } else if (p.revision) {\n fetchUrl.pathname += `/rev/${p.revision}`;\n } else {\n fetchUrl.pathname += `/stable`;\n }\n\n fetchUrl.pathname += `/${this.architectureFetchSuffix}`;\n\n this.addFact(FACT_SOURCE_URL, fetchUrl.toString());\n\n return fetchUrl;\n }\n\n private cacheKey(version: string): string {\n const cleanedVersion = version.replace(/[^a-zA-Z0-9-+.]/g, \"\");\n return `determinatesystem-${this.actionOptions.name}-${this.architectureFetchSuffix}-${cleanedVersion}`;\n }\n\n private async getCachedVersion(version: string): Promise {\n const startCwd = process.cwd();\n\n try {\n const tempDir = this.getTemporaryName();\n await mkdir(tempDir);\n process.chdir(tempDir);\n\n // extremely evil shit right here:\n process.env.GITHUB_WORKSPACE_BACKUP = process.env.GITHUB_WORKSPACE;\n delete process.env.GITHUB_WORKSPACE;\n\n if (\n await actionsCache.restoreCache(\n [this.actionOptions.name],\n this.cacheKey(version),\n [],\n undefined,\n true,\n )\n ) {\n this.recordEvent(EVENT_ARTIFACT_CACHE_HIT);\n return `${tempDir}/${this.actionOptions.name}`;\n }\n\n this.recordEvent(EVENT_ARTIFACT_CACHE_MISS);\n return undefined;\n } finally {\n process.env.GITHUB_WORKSPACE = process.env.GITHUB_WORKSPACE_BACKUP;\n delete process.env.GITHUB_WORKSPACE_BACKUP;\n process.chdir(startCwd);\n }\n }\n\n private async saveCachedVersion(\n version: string,\n toolPath: string,\n ): Promise {\n const startCwd = process.cwd();\n\n try {\n const tempDir = this.getTemporaryName();\n await mkdir(tempDir);\n process.chdir(tempDir);\n await copyFile(toolPath, `${tempDir}/${this.actionOptions.name}`);\n\n // extremely evil shit right here:\n process.env.GITHUB_WORKSPACE_BACKUP = process.env.GITHUB_WORKSPACE;\n delete process.env.GITHUB_WORKSPACE;\n\n await actionsCache.saveCache(\n [this.actionOptions.name],\n this.cacheKey(version),\n undefined,\n true,\n );\n this.recordEvent(EVENT_ARTIFACT_CACHE_PERSIST);\n } finally {\n process.env.GITHUB_WORKSPACE = process.env.GITHUB_WORKSPACE_BACKUP;\n delete process.env.GITHUB_WORKSPACE_BACKUP;\n process.chdir(startCwd);\n }\n }\n\n private async preflightRequireNix(): Promise {\n let nixLocation: string | undefined;\n\n const pathParts = (process.env[\"PATH\"] || \"\").split(\":\");\n for (const location of pathParts) {\n const candidateNix = path.join(location, \"nix\");\n\n try {\n await fs.access(candidateNix, fs.constants.X_OK);\n actionsCore.debug(`Found Nix at ${candidateNix}`);\n nixLocation = candidateNix;\n break;\n } catch {\n actionsCore.debug(`Nix not at ${candidateNix}`);\n }\n }\n this.addFact(FACT_NIX_LOCATION, nixLocation || \"\");\n\n if (this.actionOptions.requireNix === \"ignore\") {\n return true;\n }\n\n const currentNotFoundState = actionsCore.getState(STATE_KEY_NIX_NOT_FOUND);\n if (currentNotFoundState === STATE_NOT_FOUND) {\n // It was previously not found, so don't run subsequent actions\n return false;\n }\n\n if (nixLocation !== undefined) {\n return true;\n }\n actionsCore.saveState(STATE_KEY_NIX_NOT_FOUND, STATE_NOT_FOUND);\n\n switch (this.actionOptions.requireNix) {\n case \"fail\":\n actionsCore.setFailed(\n [\n \"This action can only be used when Nix is installed.\",\n \"Add `- uses: DeterminateSystems/nix-installer-action@main` earlier in your workflow.\",\n ].join(\" \"),\n );\n break;\n case \"warn\":\n actionsCore.warning(\n [\n \"This action is in no-op mode because Nix is not installed.\",\n \"Add `- uses: DeterminateSystems/nix-installer-action@main` earlier in your workflow.\",\n ].join(\" \"),\n );\n break;\n }\n\n return false;\n }\n\n private async preflightNixStoreInfo(): Promise {\n let output = \"\";\n\n const options: actionsExec.ExecOptions = {};\n options.silent = true;\n options.listeners = {\n stdout: (data) => {\n output += data.toString();\n },\n };\n\n try {\n output = \"\";\n await actionsExec.exec(\"nix\", [\"store\", \"info\", \"--json\"], options);\n this.addFact(FACT_NIX_STORE_CHECK_METHOD, \"info\");\n } catch {\n try {\n // reset output\n output = \"\";\n await actionsExec.exec(\"nix\", [\"store\", \"ping\", \"--json\"], options);\n this.addFact(FACT_NIX_STORE_CHECK_METHOD, \"ping\");\n } catch {\n this.addFact(FACT_NIX_STORE_CHECK_METHOD, \"none\");\n return;\n }\n }\n\n try {\n const parsed = JSON.parse(output);\n if (parsed.trusted === 1) {\n this.nixStoreTrust = \"trusted\";\n } else if (parsed.trusted === 0) {\n this.nixStoreTrust = \"untrusted\";\n } else if (parsed.trusted !== undefined) {\n this.addFact(\n FACT_NIX_STORE_CHECK_ERROR,\n `Mysterious trusted value: ${JSON.stringify(parsed.trusted)}`,\n );\n }\n\n this.addFact(FACT_NIX_STORE_VERSION, JSON.stringify(parsed.version));\n } catch (e: unknown) {\n this.addFact(FACT_NIX_STORE_CHECK_ERROR, stringifyError(e));\n }\n }\n\n private async submitEvents(): Promise {\n if (this.actionOptions.diagnosticsUrl === undefined) {\n actionsCore.debug(\n \"Diagnostics are disabled. Not sending the following events:\",\n );\n actionsCore.debug(JSON.stringify(this.events, undefined, 2));\n return;\n }\n\n const batch = {\n type: \"eventlog\",\n sent_at: new Date(),\n events: this.events,\n };\n\n try {\n await this.client.post(this.actionOptions.diagnosticsUrl, {\n json: batch,\n timeout: {\n request: DIAGNOSTIC_ENDPOINT_TIMEOUT_MS,\n },\n });\n } catch (e: unknown) {\n actionsCore.debug(\n `Error submitting diagnostics event: ${stringifyError(e)}`,\n );\n }\n this.events = [];\n }\n}\n\nfunction stringifyError(error: unknown): string {\n return error instanceof Error || typeof error == \"string\"\n ? error.toString()\n : JSON.stringify(error);\n}\n\nfunction makeOptionsConfident(\n actionOptions: ActionOptions,\n): ConfidentActionOptions {\n const idsProjectName = actionOptions.idsProjectName ?? actionOptions.name;\n\n const finalOpts: ConfidentActionOptions = {\n name: actionOptions.name,\n idsProjectName,\n eventPrefix: actionOptions.eventPrefix || \"action:\",\n fetchStyle: actionOptions.fetchStyle,\n legacySourcePrefix: actionOptions.legacySourcePrefix,\n requireNix: actionOptions.requireNix,\n diagnosticsUrl: determineDiagnosticsUrl(\n idsProjectName,\n actionOptions.diagnosticsUrl,\n ),\n };\n\n actionsCore.debug(\"idslib options:\");\n actionsCore.debug(JSON.stringify(finalOpts, undefined, 2));\n\n return finalOpts;\n}\n\nfunction determineDiagnosticsUrl(\n idsProjectName: string,\n urlOption?: URL | null,\n): undefined | URL {\n if (urlOption === null) {\n // Disable diagnostict events\n return undefined;\n }\n\n if (urlOption !== undefined) {\n // Caller specified a specific diagnostics URL\n return urlOption;\n }\n\n {\n // Attempt to use the action input's diagnostic-endpoint option.\n\n // Note: we don't use actionsCore.getInput('diagnostic-endpoint') on purpose:\n // getInput silently converts absent data to an empty string.\n const providedDiagnosticEndpoint = process.env[\"INPUT_DIAGNOSTIC-ENDPOINT\"];\n if (providedDiagnosticEndpoint === \"\") {\n // User probably explicitly turned it off\n return undefined;\n }\n\n if (providedDiagnosticEndpoint !== undefined) {\n try {\n return mungeDiagnosticEndpoint(new URL(providedDiagnosticEndpoint));\n } catch (e: unknown) {\n actionsCore.info(\n `User-provided diagnostic endpoint ignored: not a valid URL: ${stringifyError(e)}`,\n );\n }\n }\n }\n\n try {\n const diagnosticUrl = new URL(IDS_HOST);\n diagnosticUrl.pathname += idsProjectName;\n diagnosticUrl.pathname += \"/diagnostics\";\n return diagnosticUrl;\n } catch (e: unknown) {\n actionsCore.info(\n `Generated diagnostic endpoint ignored: not a valid URL: ${stringifyError(e)}`,\n );\n }\n\n return undefined;\n}\n\nfunction mungeDiagnosticEndpoint(inputUrl: URL): URL {\n if (DEFAULT_IDS_HOST === IDS_HOST) {\n return inputUrl;\n }\n\n try {\n const defaultIdsHost = new URL(DEFAULT_IDS_HOST);\n const currentIdsHost = new URL(IDS_HOST);\n\n if (inputUrl.origin !== defaultIdsHost.origin) {\n return inputUrl;\n }\n\n inputUrl.protocol = currentIdsHost.protocol;\n inputUrl.host = currentIdsHost.host;\n inputUrl.username = currentIdsHost.username;\n inputUrl.password = currentIdsHost.password;\n\n return inputUrl;\n } catch (e: unknown) {\n actionsCore.info(\n `Default or overridden IDS host isn't a valid URL: ${stringifyError(e)}`,\n );\n }\n\n return inputUrl;\n}\n\n// Public exports from other files\nexport { stringifyError } from \"./errors.js\";\nexport * as inputs from \"./inputs.js\";\nexport * as platform from \"./platform.js\";\n","/**\n * Coerce a value of type `unknown` into a string.\n */\nexport function stringifyError(e: unknown): string {\n if (e instanceof Error) {\n return e.message;\n } else if (typeof e === \"string\") {\n return e;\n } else {\n return JSON.stringify(e);\n }\n}\n"],"mappings":";;;;;;;AAEE,cAAW;;;ACYb,YAAY,QAAQ;AACpB,YAAY,QAAQ;AACpB,SAAS,iBAAiB;AAE1B,IAAM,gBAAgB,UAAa,WAAQ;AAyB3C,IAAM,kCAA2D;AAAA,EAC/D,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,OAAO;AACT;AAQO,SAAS,YAAY,aAA8C;AACxE,QAAM,UAAU,EAAE,GAAG,iCAAiC,GAAG,YAAY;AAErE,QAAM,0BAAoC;AAAA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sCore","actionsCore","exec","readFileSync","fs","os","promisify","error","stringifyError","promisify","exec","fs","readFileSync","version"]} \ No newline at end of file +{"version":3,"sources":["../package.json","../src/linux-release-info.ts","../src/actions-core-platform.ts","../src/correlation.ts","../src/errors.ts","../src/ids-host.ts","../src/inputs.ts","../src/platform.ts","../src/sourcedef.ts","../src/index.ts"],"sourcesContent":["{\n \"name\": \"detsys-ts\",\n \"version\": \"1.0.0\",\n \"description\": \"TypeScript goodies for DetSys projects\",\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"type\": \"module\",\n \"scripts\": {\n \"build\": \"tsup\",\n \"check-fmt\": \"prettier --check .\",\n \"format\": \"prettier --write .\",\n \"lint\": \"eslint src/**/*.ts\",\n \"docs\": \"typedoc --tsconfig ./tsconfig.typedoc.json src/index.ts\",\n \"test\": \"vitest --watch false\",\n \"test-dev\": \"vitest\",\n \"all\": \"rm -rf dist && pnpm run format && pnpm run lint && pnpm run build\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/DeterminateSystems/detsys-ts.git\"\n },\n \"keywords\": [],\n \"author\": \"\",\n \"license\": \"MIT\",\n \"bugs\": {\n \"url\": \"https://github.com/DeterminateSystems/detsys-ts/issues\"\n },\n \"homepage\": \"https://github.com/DeterminateSystems/detsys-ts#readme\",\n \"dependencies\": {\n \"@actions/cache\": \"^3.2.4\",\n \"@actions/core\": \"^1.10.1\",\n \"@actions/exec\": \"^1.1.1\",\n \"got\": \"^14.2.1\"\n },\n \"devDependencies\": {\n \"@trivago/prettier-plugin-sort-imports\": \"^4.3.0\",\n \"@types/node\": \"^20.12.7\",\n \"@typescript-eslint/eslint-plugin\": \"^7.6.0\",\n \"eslint\": \"^8.57.0\",\n \"eslint-import-resolver-typescript\": \"^3.6.1\",\n \"eslint-plugin-github\": \"^4.10.2\",\n \"eslint-plugin-import\": \"^2.29.1\",\n \"eslint-plugin-prettier\": \"^5.1.3\",\n \"prettier\": \"^3.2.5\",\n \"tsup\": \"^8.0.2\",\n \"typedoc\": \"^0.25.13\",\n \"typescript\": \"^5.4.5\",\n \"vitest\": \"^1.5.2\"\n }\n}\n","/*!\n * linux-release-info\n * Get Linux release info (distribution name, version, arch, release, etc.)\n * from '/etc/os-release' or '/usr/lib/os-release' files and from native os\n * module. On Windows and Darwin platforms it only returns common node os module\n * info (platform, hostname, release, and arch)\n *\n * Licensed under MIT\n * Copyright (c) 2018-2020 [Samuel Carreira]\n */\n// NOTE: we depend on this directly to get around some un-fun issues with mixing CommonJS\n// and ESM in the bundle. We've modified the original logic to improve things like typing\n// and fixing ESLint issues. Originally drawn from:\n// https://github.com/samuelcarreira/linux-release-info/blob/84a91aa5442b47900da03020c590507545d3dc74/src/index.ts\nimport * as fs from \"node:fs\";\nimport * as os from \"node:os\";\nimport { promisify } from \"node:util\";\n\nconst readFileAsync = promisify(fs.readFile);\n\nexport interface LinuxReleaseInfoOptions {\n /**\n * read mode, possible values: 'async' and 'sync'\n *\n * @default 'async'\n */\n mode?: \"async\" | \"sync\";\n /**\n * custom complete file path with os info default null/none\n * if not provided the system will search on the '/etc/os-release'\n * and '/usr/lib/os-release' files\n *\n * @default null\n */\n customFile?: string | null | undefined;\n /**\n * if true, show console debug messages\n *\n * @default false\n */\n debug?: boolean;\n}\n\nconst linuxReleaseInfoOptionsDefaults: LinuxReleaseInfoOptions = {\n mode: \"async\",\n customFile: null,\n debug: false,\n};\n\n/**\n * Get OS release info from 'os-release' file and from native os module\n * on Windows or Darwin it only returns common os module info\n * (uses native fs module)\n * @returns {object} info from the current os\n */\nexport function releaseInfo(infoOptions: LinuxReleaseInfoOptions): object {\n const options = { ...linuxReleaseInfoOptionsDefaults, ...infoOptions };\n\n const searchOsReleaseFileList: string[] = osReleaseFileList(\n options.customFile,\n );\n\n if (os.type() !== \"Linux\") {\n if (options.mode === \"sync\") {\n return getOsInfo();\n } else {\n return Promise.resolve(getOsInfo());\n }\n }\n\n if (options.mode === \"sync\") {\n return readSyncOsreleaseFile(searchOsReleaseFileList, options);\n } else {\n return Promise.resolve(\n readAsyncOsReleaseFile(searchOsReleaseFileList, options),\n );\n }\n}\n\n/**\n * Format file data: convert data to object keys/values\n *\n * @param {object} sourceData Source object to be appended\n * @param {string} srcParseData Input file data to be parsed\n * @returns {object} Formated object\n */\nfunction formatFileData(sourceData: OsInfo, srcParseData: string): OsInfo {\n const lines: string[] = srcParseData.split(\"\\n\");\n\n for (const line of lines) {\n const lineData = line.split(\"=\");\n\n if (lineData.length === 2) {\n lineData[1] = lineData[1].replace(/[\"'\\r]/gi, \"\"); // remove quotes and return character\n\n Object.defineProperty(sourceData, lineData[0].toLowerCase(), {\n value: lineData[1],\n writable: true,\n enumerable: true,\n configurable: true,\n });\n }\n }\n\n return sourceData;\n}\n\n/**\n * Export a list of os-release files\n *\n * @param {string} customFile optional custom complete filepath\n * @returns {array} list of os-release files\n */\nfunction osReleaseFileList(customFile: string | null | undefined): string[] {\n const DEFAULT_OS_RELEASE_FILES = [\"/etc/os-release\", \"/usr/lib/os-release\"];\n\n if (!customFile) {\n return DEFAULT_OS_RELEASE_FILES;\n } else {\n return Array(customFile);\n }\n}\n\n/**\n * Operating system info.\n */\ntype OsInfo = {\n type: string;\n platform: string;\n hostname: string;\n arch: string;\n release: string;\n};\n\n/**\n * Get OS Basic Info\n * (uses node 'os' native module)\n *\n * @returns {OsInfo} os basic info\n */\nfunction getOsInfo(): OsInfo {\n return {\n type: os.type(),\n platform: os.platform(),\n hostname: os.hostname(),\n arch: os.arch(),\n release: os.release(),\n };\n}\n\n/* Helper functions */\n\nasync function readAsyncOsReleaseFile(\n fileList: string[],\n options: LinuxReleaseInfoOptions,\n): Promise {\n let fileData = null;\n\n for (const osReleaseFile of fileList) {\n try {\n if (options.debug) {\n /* eslint-disable no-console */\n console.log(`Trying to read '${osReleaseFile}'...`);\n }\n\n fileData = await readFileAsync(osReleaseFile, \"binary\");\n\n if (options.debug) {\n console.log(`Read data:\\n${fileData}`);\n }\n\n break;\n } catch (error) {\n if (options.debug) {\n console.error(error);\n }\n }\n }\n\n if (fileData === null) {\n throw new Error(\"Cannot read os-release file!\");\n //return getOsInfo();\n }\n\n return formatFileData(getOsInfo(), fileData);\n}\n\nfunction readSyncOsreleaseFile(\n releaseFileList: string[],\n options: LinuxReleaseInfoOptions,\n): OsInfo {\n let fileData = null;\n\n for (const osReleaseFile of releaseFileList) {\n try {\n if (options.debug) {\n console.log(`Trying to read '${osReleaseFile}'...`);\n }\n\n fileData = fs.readFileSync(osReleaseFile, \"binary\");\n\n if (options.debug) {\n console.log(`Read data:\\n${fileData}`);\n }\n\n break;\n } catch (error) {\n if (options.debug) {\n console.error(error);\n }\n }\n }\n\n if (fileData === null) {\n throw new Error(\"Cannot read os-release file!\");\n //return getOsInfo();\n }\n\n return formatFileData(getOsInfo(), fileData);\n}\n","// MIT, mostly lifted from https://github.com/actions/toolkit/blob/5a736647a123ecf8582376bdaee833fbae5b3847/packages/core/src/platform.ts\n// since it isn't in @actions/core 1.10.1 which is their current release as 2024-04-19.\n// Changes: Replaced the lsb_release call in Linux with `linux-release-info` to parse the os-release file directly.\nimport { releaseInfo } from \"./linux-release-info.js\";\nimport * as actionsCore from \"@actions/core\";\nimport * as exec from \"@actions/exec\";\nimport os from \"os\";\n\n/**\n * The name and version of the Action runner's system.\n */\ntype SystemInfo = {\n name: string;\n version: string;\n};\n\n/**\n * Get the name and version of the current Windows system.\n */\nconst getWindowsInfo = async (): Promise => {\n const { stdout: version } = await exec.getExecOutput(\n 'powershell -command \"(Get-CimInstance -ClassName Win32_OperatingSystem).Version\"',\n undefined,\n {\n silent: true,\n },\n );\n\n const { stdout: name } = await exec.getExecOutput(\n 'powershell -command \"(Get-CimInstance -ClassName Win32_OperatingSystem).Caption\"',\n undefined,\n {\n silent: true,\n },\n );\n\n return {\n name: name.trim(),\n version: version.trim(),\n };\n};\n\n/**\n * Get the name and version of the current macOS system.\n */\nconst getMacOsInfo = async (): Promise => {\n const { stdout } = await exec.getExecOutput(\"sw_vers\", undefined, {\n silent: true,\n });\n\n const version = stdout.match(/ProductVersion:\\s*(.+)/)?.[1] ?? \"\";\n const name = stdout.match(/ProductName:\\s*(.+)/)?.[1] ?? \"\";\n\n return {\n name,\n version,\n };\n};\n\n/**\n * Get the name and version of the current Linux system.\n */\nconst getLinuxInfo = async (): Promise => {\n let data: object = {};\n\n try {\n data = releaseInfo({ mode: \"sync\" });\n actionsCore.debug(`Identified release info: ${JSON.stringify(data)}`);\n } catch (e) {\n actionsCore.debug(`Error collecting release info: ${e}`);\n }\n\n return {\n name: getPropertyViaWithDefault(\n data,\n [\"id\", \"name\", \"pretty_name\", \"id_like\"],\n \"unknown\",\n ),\n version: getPropertyViaWithDefault(\n data,\n [\"version_id\", \"version\", \"version_codename\"],\n \"unknown\",\n ),\n };\n};\n\nfunction getPropertyViaWithDefault(\n data: object,\n names: Property[],\n defaultValue: T,\n): T {\n for (const name of names) {\n const ret: T = getPropertyWithDefault(data, name, defaultValue);\n\n if (ret !== defaultValue) {\n return ret;\n }\n }\n\n return defaultValue;\n}\n\nfunction getPropertyWithDefault(\n data: object,\n name: Property,\n defaultValue: T,\n): T {\n if (!data.hasOwnProperty(name)) {\n return defaultValue;\n }\n\n const value = (data as { [K in Property]: T })[name];\n\n // NB. this check won't work for object instances\n if (typeof value !== typeof defaultValue) {\n return defaultValue;\n }\n\n return value;\n}\n\n/**\n * The Action runner's platform.\n */\nexport const platform = os.platform();\n\n/**\n * The Action runner's architecture.\n */\nexport const arch = os.arch();\n\n/**\n * Whether the Action runner is a Windows system.\n */\nexport const isWindows = platform === \"win32\";\n\n/**\n * Whether the Action runner is a macOS system.\n */\nexport const isMacOS = platform === \"darwin\";\n\n/**\n * Whether the Action runner is a Linux system.\n */\nexport const isLinux = platform === \"linux\";\n\n/**\n * System-level information about the current host (platform, architecture, etc.).\n */\ntype SystemDetails = {\n name: string;\n platform: string;\n arch: string;\n version: string;\n isWindows: boolean;\n isMacOS: boolean;\n isLinux: boolean;\n};\n\n/**\n * Get system-level information about the current host (platform, architecture, etc.).\n */\nexport async function getDetails(): Promise {\n return {\n ...(await (isWindows\n ? getWindowsInfo()\n : isMacOS\n ? getMacOsInfo()\n : getLinuxInfo())),\n platform,\n arch,\n isWindows,\n isMacOS,\n isLinux,\n };\n}\n","import * as actionsCore from \"@actions/core\";\nimport { createHash } from \"node:crypto\";\n\nconst OPTIONAL_VARIABLES = [\"INVOCATION_ID\"];\n\n// JSON sent to server\n/* eslint-disable camelcase */\nexport type AnonymizedCorrelationHashes = {\n correlation_source: string;\n repository?: string;\n run?: string;\n run_differentiator?: string;\n workflow?: string;\n groups: Record;\n};\n\nexport function identify(projectName: string): AnonymizedCorrelationHashes {\n const ident = {\n correlation_source: \"github-actions\",\n\n repository: hashEnvironmentVariables(\"GHR\", [\n \"GITHUB_SERVER_URL\",\n \"GITHUB_REPOSITORY_OWNER\",\n \"GITHUB_REPOSITORY_OWNER_ID\",\n \"GITHUB_REPOSITORY\",\n \"GITHUB_REPOSITORY_ID\",\n ]),\n workflow: hashEnvironmentVariables(\"GHW\", [\n \"GITHUB_SERVER_URL\",\n \"GITHUB_REPOSITORY_OWNER\",\n \"GITHUB_REPOSITORY_OWNER_ID\",\n \"GITHUB_REPOSITORY\",\n \"GITHUB_REPOSITORY_ID\",\n \"GITHUB_WORKFLOW\",\n ]),\n job: hashEnvironmentVariables(\"GHWJ\", [\n \"GITHUB_SERVER_URL\",\n \"GITHUB_REPOSITORY_OWNER\",\n \"GITHUB_REPOSITORY_OWNER_ID\",\n \"GITHUB_REPOSITORY\",\n \"GITHUB_REPOSITORY_ID\",\n \"GITHUB_WORKFLOW\",\n \"GITHUB_JOB\",\n ]),\n run: hashEnvironmentVariables(\"GHWJR\", [\n \"GITHUB_SERVER_URL\",\n \"GITHUB_REPOSITORY_OWNER\",\n \"GITHUB_REPOSITORY_OWNER_ID\",\n \"GITHUB_REPOSITORY\",\n \"GITHUB_REPOSITORY_ID\",\n \"GITHUB_WORKFLOW\",\n \"GITHUB_JOB\",\n \"GITHUB_RUN_ID\",\n ]),\n run_differentiator: hashEnvironmentVariables(\"GHWJA\", [\n \"GITHUB_SERVER_URL\",\n \"GITHUB_REPOSITORY_OWNER\",\n \"GITHUB_REPOSITORY_OWNER_ID\",\n \"GITHUB_REPOSITORY\",\n \"GITHUB_REPOSITORY_ID\",\n \"GITHUB_WORKFLOW\",\n \"GITHUB_JOB\",\n \"GITHUB_RUN_ID\",\n \"GITHUB_RUN_NUMBER\",\n \"GITHUB_RUN_ATTEMPT\",\n \"INVOCATION_ID\",\n ]),\n groups: {\n ci: \"github-actions\",\n project: projectName,\n github_organization: hashEnvironmentVariables(\"GHO\", [\n \"GITHUB_SERVER_URL\",\n \"GITHUB_REPOSITORY_OWNER\",\n \"GITHUB_REPOSITORY_OWNER_ID\",\n ]),\n },\n };\n\n actionsCore.debug(\"Correlation data:\");\n actionsCore.debug(JSON.stringify(ident, null, 2));\n\n return ident;\n}\n\nfunction hashEnvironmentVariables(\n prefix: string,\n variables: string[],\n): undefined | string {\n const hash = createHash(\"sha256\");\n\n for (const varName of variables) {\n let value = process.env[varName];\n\n if (value === undefined) {\n if (OPTIONAL_VARIABLES.includes(varName)) {\n actionsCore.debug(\n `Optional environment variable not set: ${varName} -- substituting with the variable name`,\n );\n value = varName;\n } else {\n actionsCore.debug(\n `Environment variable not set: ${varName} -- can't generate the requested identity`,\n );\n return undefined;\n }\n }\n\n hash.update(value);\n hash.update(\"\\0\");\n }\n\n return `${prefix}-${hash.digest(\"hex\")}`;\n}\n","/**\n * Coerce a value of type `unknown` into a string.\n */\nexport function stringifyError(e: unknown): string {\n if (e instanceof Error) {\n return e.message;\n } else if (typeof e === \"string\") {\n return e;\n } else {\n return JSON.stringify(e);\n }\n}\n","/**\n * @packageDocumentation\n * Identifies and discovers backend servers for install.determinate.systems\n */\nimport { stringifyError } from \"./errors.js\";\nimport * as actionsCore from \"@actions/core\";\nimport { SrvRecord } from \"node:dns\";\nimport { resolveSrv } from \"node:dns/promises\";\n\nconst DEFAULT_LOOKUP = \"_detsys_ids._tcp.install.determinate.systems.\";\nconst ALLOWED_SUFFIXES = [\n \".install.determinate.systems\",\n \".install.detsys.dev\",\n];\n\nconst DEFAULT_IDS_HOST = \"https://install.determinate.systems\";\nconst LOOKUP = process.env[\"IDS_LOOKUP\"] ?? DEFAULT_LOOKUP;\n\nexport class IdsHost {\n private idsProjectName: string;\n private diagnosticsSuffix?: string;\n private runtimeDiagnosticsUrl?: string;\n private prioritizedURLs?: URL[];\n private records?: SrvRecord[];\n\n constructor(\n idsProjectName: string,\n diagnosticsSuffix: string | undefined,\n runtimeDiagnosticsUrl: string | undefined,\n ) {\n this.idsProjectName = idsProjectName;\n this.diagnosticsSuffix = diagnosticsSuffix;\n this.runtimeDiagnosticsUrl = runtimeDiagnosticsUrl;\n }\n\n markCurrentHostBroken(): void {\n this.prioritizedURLs?.shift();\n }\n\n setPrioritizedUrls(urls: URL[]): void {\n this.prioritizedURLs = urls;\n }\n\n async getRootUrl(): Promise {\n const idsHost = process.env[\"IDS_HOST\"];\n if (idsHost !== undefined) {\n try {\n return new URL(idsHost);\n } catch (err: unknown) {\n actionsCore.error(\n `IDS_HOST environment variable is not a valid URL. Ignoring. ${stringifyError(err)}`,\n );\n }\n }\n\n let url: URL | undefined = undefined;\n try {\n const urls = await this.getUrlsByPreference();\n url = urls[0];\n } catch (err: unknown) {\n actionsCore.error(\n `Error collecting IDS URLs by preference: ${stringifyError(err)}`,\n );\n }\n\n if (url === undefined) {\n url = new URL(DEFAULT_IDS_HOST);\n }\n\n // This is a load-bearing `new URL(url)` so that callers can't mutate\n // getRootUrl's return value.\n return new URL(url);\n }\n\n async getDiagnosticsUrl(): Promise {\n if (this.runtimeDiagnosticsUrl === \"\") {\n // User specifically set the diagnostics URL to an empty string\n // so disable diagnostics\n return undefined;\n }\n\n if (\n this.runtimeDiagnosticsUrl !== \"-\" &&\n this.runtimeDiagnosticsUrl !== undefined\n ) {\n try {\n // Caller specified a specific diagnostics URL\n return new URL(this.runtimeDiagnosticsUrl);\n } catch (err: unknown) {\n actionsCore.info(\n `User-provided diagnostic endpoint ignored: not a valid URL: ${stringifyError(err)}`,\n );\n }\n }\n\n try {\n const diagnosticUrl = await this.getRootUrl();\n diagnosticUrl.pathname += this.idsProjectName;\n diagnosticUrl.pathname += \"/\";\n diagnosticUrl.pathname += this.diagnosticsSuffix || \"diagnostics\";\n return diagnosticUrl;\n } catch (err: unknown) {\n actionsCore.info(\n `Generated diagnostic endpoint ignored, and diagnostics are disabled: not a valid URL: ${stringifyError(err)}`,\n );\n return undefined;\n }\n }\n\n private async getUrlsByPreference(): Promise {\n if (this.prioritizedURLs === undefined) {\n this.prioritizedURLs = orderRecordsByPriorityWeight(\n await discoverServiceRecords(),\n ).flatMap((record) => recordToUrl(record) || []);\n }\n\n return this.prioritizedURLs;\n }\n}\n\nexport function recordToUrl(record: SrvRecord): URL | undefined {\n const urlStr = `https://${record.name}:${record.port}`;\n try {\n return new URL(urlStr);\n } catch (err: unknown) {\n actionsCore.debug(\n `Record ${JSON.stringify(record)} produced an invalid URL: ${urlStr} (${err})`,\n );\n return undefined;\n }\n}\n\nasync function discoverServiceRecords(): Promise {\n return await discoverServicesStub(resolveSrv(LOOKUP), 1_000);\n}\n\nexport async function discoverServicesStub(\n lookup: Promise,\n timeout: number,\n): Promise {\n const defaultFallback: Promise = new Promise(\n (resolve, _reject) => {\n setTimeout(resolve, timeout, []);\n },\n );\n\n let records: SrvRecord[];\n\n try {\n records = await Promise.race([lookup, defaultFallback]);\n } catch (reason: unknown) {\n actionsCore.debug(`Error resolving SRV records: ${stringifyError(reason)}`);\n records = [];\n }\n\n const acceptableRecords = records.filter((record: SrvRecord): boolean => {\n for (const suffix of ALLOWED_SUFFIXES) {\n if (record.name.endsWith(suffix)) {\n return true;\n }\n }\n\n actionsCore.debug(\n `Unacceptable domain due to an invalid suffix: ${record.name}`,\n );\n\n return false;\n });\n\n if (acceptableRecords.length === 0) {\n actionsCore.debug(`No records found for ${LOOKUP}`);\n } else {\n actionsCore.debug(\n `Resolved ${LOOKUP} to ${JSON.stringify(acceptableRecords)}`,\n );\n }\n\n return acceptableRecords;\n}\n\nexport function orderRecordsByPriorityWeight(\n records: SrvRecord[],\n): SrvRecord[] {\n const byPriorityWeight: Map = new Map();\n for (const record of records) {\n const existing = byPriorityWeight.get(record.priority);\n if (existing) {\n existing.push(record);\n } else {\n byPriorityWeight.set(record.priority, [record]);\n }\n }\n\n const prioritizedRecords: SrvRecord[] = [];\n const keys: number[] = Array.from(byPriorityWeight.keys()).sort(\n (a, b) => a - b,\n );\n\n for (const priority of keys) {\n const recordsByPrio = byPriorityWeight.get(priority);\n if (recordsByPrio === undefined) {\n continue;\n }\n\n prioritizedRecords.push(...weightedRandom(recordsByPrio));\n }\n\n return prioritizedRecords;\n}\n\nexport function weightedRandom(records: SrvRecord[]): SrvRecord[] {\n // Duplicate records so we don't accidentally change our caller's data\n const scratchRecords: SrvRecord[] = records.slice();\n const result: SrvRecord[] = [];\n\n while (scratchRecords.length > 0) {\n const weights: number[] = [];\n\n {\n for (let i = 0; i < scratchRecords.length; i++) {\n weights.push(\n scratchRecords[i].weight + (i > 0 ? scratchRecords[i - 1].weight : 0),\n );\n }\n }\n\n const point = Math.random() * weights[weights.length - 1];\n\n for (\n let selectedIndex = 0;\n selectedIndex < weights.length;\n selectedIndex++\n ) {\n if (weights[selectedIndex] > point) {\n // Remove our selected record and add it to the result\n result.push(scratchRecords.splice(selectedIndex, 1)[0]);\n break;\n }\n }\n }\n\n return result;\n}\n","/**\n * @packageDocumentation\n * Helpers for getting values from an Action's configuration.\n */\nimport * as actionsCore from \"@actions/core\";\n\n/**\n * Get a Boolean input from the Action's configuration by name.\n */\nconst getBool = (name: string): boolean => {\n return actionsCore.getBooleanInput(name);\n};\n\n/**\n * The character used to separate values in the input string.\n */\nexport type Separator = \"space\" | \"comma\";\n\n/**\n * Convert a comma-separated string input into an array of strings. If `comma` is selected,\n * all whitespace is removed from the string before converting to an array.\n */\nconst getArrayOfStrings = (name: string, separator: Separator): string[] => {\n const original = getString(name);\n return handleString(original, separator);\n};\n\n/**\n * Convert a string input into an array of strings or `null` if no value is set.\n */\nconst getArrayOfStringsOrNull = (\n name: string,\n separator: Separator,\n): string[] | null => {\n const original = getStringOrNull(name);\n if (original === null) {\n return null;\n } else {\n return handleString(original, separator);\n }\n};\n\n// Split out this function for use in testing\nexport const handleString = (input: string, separator: Separator): string[] => {\n const sepChar = separator === \"comma\" ? \",\" : /\\s+/;\n const trimmed = input.trim(); // Remove whitespace at the beginning and end\n if (trimmed === \"\") {\n return [];\n }\n\n return trimmed.split(sepChar).map((s: string) => s.trim());\n};\n\n/**\n * Get a multi-line string input from the Action's configuration by name or return `null` if not set.\n */\nconst getMultilineStringOrNull = (name: string): string[] | null => {\n const value = actionsCore.getMultilineInput(name);\n if (value.length === 0) {\n return null;\n } else {\n return value;\n }\n};\n\n/**\n * Get a number input from the Action's configuration by name or return `null` if not set.\n */\nconst getNumberOrNull = (name: string): number | null => {\n const value = actionsCore.getInput(name);\n if (value === \"\") {\n return null;\n } else {\n return Number(value);\n }\n};\n\n/**\n * Get a string input from the Action's configuration.\n */\nconst getString = (name: string): string => {\n return actionsCore.getInput(name);\n};\n\n/**\n * Get a string input from the Action's configuration by name or return `null` if not set.\n */\nconst getStringOrNull = (name: string): string | null => {\n const value = actionsCore.getInput(name);\n if (value === \"\") {\n return null;\n } else {\n return value;\n }\n};\n\n/**\n * Get a string input from the Action's configuration by name or return `undefined` if not set.\n */\nconst getStringOrUndefined = (name: string): string | undefined => {\n const value = actionsCore.getInput(name);\n if (value === \"\") {\n return undefined;\n } else {\n return value;\n }\n};\n\nexport {\n getBool,\n getArrayOfStrings,\n getArrayOfStringsOrNull,\n getMultilineStringOrNull,\n getNumberOrNull,\n getString,\n getStringOrNull,\n getStringOrUndefined,\n};\n","/**\n * @packageDocumentation\n * Helpers for determining system attributes of the current runner.\n */\nimport * as actionsCore from \"@actions/core\";\n\n/**\n * Get the current architecture plus OS. Examples include `X64-Linux` and `ARM64-macOS`.\n */\nexport function getArchOs(): string {\n const envArch = process.env.RUNNER_ARCH;\n const envOs = process.env.RUNNER_OS;\n\n if (envArch && envOs) {\n return `${envArch}-${envOs}`;\n } else {\n actionsCore.error(\n `Can't identify the platform: RUNNER_ARCH or RUNNER_OS undefined (${envArch}-${envOs})`,\n );\n throw new Error(\"RUNNER_ARCH and/or RUNNER_OS is not defined\");\n }\n}\n\n/**\n * Get the current Nix system. Examples include `x86_64-linux` and `aarch64-darwin`.\n */\nexport function getNixPlatform(archOs: string): string {\n const archOsMap: Map = new Map([\n [\"X64-macOS\", \"x86_64-darwin\"],\n [\"ARM64-macOS\", \"aarch64-darwin\"],\n [\"X64-Linux\", \"x86_64-linux\"],\n [\"ARM64-Linux\", \"aarch64-linux\"],\n ]);\n\n const mappedTo = archOsMap.get(archOs);\n if (mappedTo) {\n return mappedTo;\n } else {\n actionsCore.error(\n `ArchOs (${archOs}) doesn't map to a supported Nix platform.`,\n );\n throw new Error(\n `Cannot convert ArchOs (${archOs}) to a supported Nix platform.`,\n );\n }\n}\n","import { getStringOrUndefined } from \"./inputs.js\";\nimport * as actionsCore from \"@actions/core\";\n\nexport type SourceDef = {\n path?: string;\n url?: string;\n tag?: string;\n pr?: string;\n branch?: string;\n revision?: string;\n};\n\nexport function constructSourceParameters(legacyPrefix?: string): SourceDef {\n return {\n path: noisilyGetInput(\"path\", legacyPrefix),\n url: noisilyGetInput(\"url\", legacyPrefix),\n tag: noisilyGetInput(\"tag\", legacyPrefix),\n pr: noisilyGetInput(\"pr\", legacyPrefix),\n branch: noisilyGetInput(\"branch\", legacyPrefix),\n revision: noisilyGetInput(\"revision\", legacyPrefix),\n };\n}\n\nfunction noisilyGetInput(\n suffix: string,\n legacyPrefix: string | undefined,\n): string | undefined {\n const preferredInput = getStringOrUndefined(`source-${suffix}`);\n\n if (!legacyPrefix) {\n return preferredInput;\n }\n\n // Remaining is for handling cases where the legacy prefix\n // should be examined.\n const legacyInput = getStringOrUndefined(`${legacyPrefix}-${suffix}`);\n\n if (preferredInput && legacyInput) {\n actionsCore.warning(\n `The supported option source-${suffix} and the legacy option ${legacyPrefix}-${suffix} are both set. Preferring source-${suffix}. Please stop setting ${legacyPrefix}-${suffix}.`,\n );\n return preferredInput;\n } else if (legacyInput) {\n actionsCore.warning(\n `The legacy option ${legacyPrefix}-${suffix} is set. Please migrate to source-${suffix}.`,\n );\n return legacyInput;\n } else {\n return preferredInput;\n }\n}\n","/**\n * @packageDocumentation\n * Determinate Systems' TypeScript library for creating GitHub Actions logic.\n */\nimport { version as pkgVersion } from \"../package.json\";\nimport * as ghActionsCorePlatform from \"./actions-core-platform.js\";\nimport * as correlation from \"./correlation.js\";\nimport { IdsHost } from \"./ids-host.js\";\nimport { getBool, getStringOrNull } from \"./inputs.js\";\nimport * as platform from \"./platform.js\";\nimport { SourceDef, constructSourceParameters } from \"./sourcedef.js\";\nimport * as actionsCache from \"@actions/cache\";\nimport * as actionsCore from \"@actions/core\";\nimport * as actionsExec from \"@actions/exec\";\nimport got, { Got } from \"got\";\nimport { exec } from \"node:child_process\";\nimport { UUID, randomUUID } from \"node:crypto\";\nimport { PathLike, createWriteStream, readFileSync } from \"node:fs\";\nimport fs, { chmod, copyFile, mkdir } from \"node:fs/promises\";\nimport * as os from \"node:os\";\nimport { tmpdir } from \"node:os\";\nimport * as path from \"node:path\";\nimport { pipeline } from \"node:stream/promises\";\nimport { promisify } from \"node:util\";\nimport { gzip } from \"node:zlib\";\n\nconst EVENT_EXCEPTION = \"exception\";\nconst EVENT_ARTIFACT_CACHE_HIT = \"artifact_cache_hit\";\nconst EVENT_ARTIFACT_CACHE_MISS = \"artifact_cache_miss\";\nconst EVENT_ARTIFACT_CACHE_PERSIST = \"artifact_cache_persist\";\nconst EVENT_PREFLIGHT_REQUIRE_NIX_DENIED = \"preflight-require-nix-denied\";\n\nconst FACT_ARTIFACT_FETCHED_FROM_CACHE = \"artifact_fetched_from_cache\";\nconst FACT_ENDED_WITH_EXCEPTION = \"ended_with_exception\";\nconst FACT_FINAL_EXCEPTION = \"final_exception\";\nconst FACT_OS = \"$os\";\nconst FACT_OS_VERSION = \"$os_version\";\nconst FACT_SOURCE_URL = \"source_url\";\nconst FACT_SOURCE_URL_ETAG = \"source_url_etag\";\n\nconst FACT_NIX_LOCATION = \"nix_location\";\nconst FACT_NIX_STORE_TRUST = \"nix_store_trusted\";\nconst FACT_NIX_STORE_VERSION = \"nix_store_version\";\nconst FACT_NIX_STORE_CHECK_METHOD = \"nix_store_check_method\";\nconst FACT_NIX_STORE_CHECK_ERROR = \"nix_store_check_error\";\n\nconst STATE_KEY_EXECUTION_PHASE = \"detsys_action_execution_phase\";\nconst STATE_KEY_NIX_NOT_FOUND = \"detsys_action_nix_not_found\";\nconst STATE_NOT_FOUND = \"not-found\";\n\nconst DIAGNOSTIC_ENDPOINT_TIMEOUT_MS = 30_000; // 30 seconds in milliseconds\n\n/**\n * An enum for describing different \"fetch suffixes\" for i.d.s.\n *\n * - `nix-style` means that system names like `x86_64-linux` and `aarch64-darwin` are used\n * - `gh-env-style` means that names like `X64-Linux` and `ARM64-macOS` are used\n * - `universal` means that the suffix is the static `universal` (for non-system-specific things)\n */\nexport type FetchSuffixStyle = \"nix-style\" | \"gh-env-style\" | \"universal\";\n\n/**\n * GitHub Actions has two possible execution phases: `main` and `post`.\n */\nexport type ExecutionPhase = \"main\" | \"post\";\n\n/**\n * How to handle whether Nix is currently installed on the runner.\n *\n * - `fail` means that the workflow fails if Nix isn't installed\n * - `warn` means that a warning is logged if Nix isn't installed\n * - `ignore` means that Nix will not be checked\n */\nexport type NixRequirementHandling = \"fail\" | \"warn\" | \"ignore\";\n\n/**\n * Whether the Nix store on the runner is trusted.\n *\n * - `trusted` means yes\n * - `untrusted` means no\n * - `unknown` means that the status couldn't be determined\n *\n * This is determined via the output of `nix store info --json`.\n */\nexport type NixStoreTrust = \"trusted\" | \"untrusted\" | \"unknown\";\n\nexport type ActionOptions = {\n // Name of the project generally, and the name of the binary on disk.\n name: string;\n\n // Defaults to `name`, Corresponds to the ProjectHost entry on i.d.s.\n idsProjectName?: string;\n\n // Defaults to `action:`\n eventPrefix?: string;\n\n // The \"architecture\" URL component expected by I.D.S. for the ProjectHost.\n fetchStyle: FetchSuffixStyle;\n\n // IdsToolbox assumes the GitHub Action exposes source overrides, like branch/pr/etc. to be named `source-*`.\n // This prefix adds a fallback name, prefixed by `${legacySourcePrefix}-`.\n // Users who configure legacySourcePrefix will get warnings asking them to change to `source-*`.\n legacySourcePrefix?: string;\n\n // Check if Nix is installed before running this action.\n // If Nix isn't installed, this action will not fail, and will instead do nothing.\n // The action will emit a user-visible warning instructing them to install Nix.\n requireNix: NixRequirementHandling;\n\n // The URL suffix to send diagnostics events to.\n //\n // The final URL is constructed via IDS_HOST/idsProjectName/diagnosticsSuffix.\n //\n // Default: `diagnostics`.\n diagnosticsSuffix?: string;\n};\n\n// A confident version of Options, where defaults have been resolved into final values\ntype ConfidentActionOptions = {\n name: string;\n idsProjectName: string;\n eventPrefix: string;\n fetchStyle: FetchSuffixStyle;\n legacySourcePrefix?: string;\n requireNix: NixRequirementHandling;\n providedDiagnosticsUrl?: URL;\n};\n\ntype DiagnosticEvent = {\n event_name: string;\n correlation: correlation.AnonymizedCorrelationHashes;\n facts: Record;\n context: Record;\n timestamp: Date;\n uuid: UUID;\n};\n\nexport abstract class DetSysAction {\n nixStoreTrust: NixStoreTrust;\n\n private actionOptions: ConfidentActionOptions;\n private strictMode: boolean;\n private client: Got;\n private exceptionAttachments: Map;\n private archOs: string;\n private executionPhase: ExecutionPhase;\n private nixSystem: string;\n private architectureFetchSuffix: string;\n private sourceParameters: SourceDef;\n private facts: Record;\n private events: DiagnosticEvent[];\n private identity: correlation.AnonymizedCorrelationHashes;\n private idsHost: IdsHost;\n\n private determineExecutionPhase(): ExecutionPhase {\n const currentPhase = actionsCore.getState(STATE_KEY_EXECUTION_PHASE);\n if (currentPhase === \"\") {\n actionsCore.saveState(STATE_KEY_EXECUTION_PHASE, \"post\");\n return \"main\";\n } else {\n return \"post\";\n }\n }\n\n constructor(actionOptions: ActionOptions) {\n this.actionOptions = makeOptionsConfident(actionOptions);\n this.idsHost = new IdsHost(\n this.actionOptions.idsProjectName,\n actionOptions.diagnosticsSuffix,\n // Note: we don't use actionsCore.getInput('diagnostic-endpoint') on purpose:\n // getInput silently converts absent data to an empty string.\n process.env[\"INPUT_DIAGNOSTIC-ENDPOINT\"],\n );\n this.exceptionAttachments = new Map();\n this.nixStoreTrust = \"unknown\";\n this.strictMode = getBool(\"_internal-strict-mode\");\n\n this.events = [];\n this.client = got.extend({\n retry: {\n limit: 3,\n methods: [\"GET\", \"HEAD\"],\n },\n hooks: {\n beforeRetry: [\n (error, retryCount) => {\n actionsCore.info(\n `Retrying after error ${error.code}, retry #: ${retryCount}`,\n );\n },\n ],\n },\n });\n\n // JSON sent to server\n /* eslint-disable camelcase */\n this.facts = {\n $lib: \"idslib\",\n $lib_version: pkgVersion,\n project: this.actionOptions.name,\n ids_project: this.actionOptions.idsProjectName,\n };\n\n const params = [\n [\"github_action_ref\", \"GITHUB_ACTION_REF\"],\n [\"github_action_repository\", \"GITHUB_ACTION_REPOSITORY\"],\n [\"github_event_name\", \"GITHUB_EVENT_NAME\"],\n [\"$os\", \"RUNNER_OS\"],\n [\"arch\", \"RUNNER_ARCH\"],\n ];\n for (const [target, env] of params) {\n const value = process.env[env];\n if (value) {\n this.facts[target] = value;\n }\n }\n\n this.identity = correlation.identify(this.actionOptions.name);\n this.archOs = platform.getArchOs();\n this.nixSystem = platform.getNixPlatform(this.archOs);\n\n this.facts.arch_os = this.archOs;\n this.facts.nix_system = this.nixSystem;\n\n {\n ghActionsCorePlatform\n .getDetails()\n // eslint-disable-next-line github/no-then\n .then((details) => {\n if (details.name !== \"unknown\") {\n this.addFact(FACT_OS, details.name);\n }\n if (details.version !== \"unknown\") {\n this.addFact(FACT_OS_VERSION, details.version);\n }\n })\n // eslint-disable-next-line github/no-then\n .catch((e: unknown) => {\n actionsCore.debug(\n `Failure getting platform details: ${stringifyError(e)}`,\n );\n });\n }\n\n this.executionPhase = this.determineExecutionPhase();\n this.facts.execution_phase = this.executionPhase;\n\n if (this.actionOptions.fetchStyle === \"gh-env-style\") {\n this.architectureFetchSuffix = this.archOs;\n } else if (this.actionOptions.fetchStyle === \"nix-style\") {\n this.architectureFetchSuffix = this.nixSystem;\n } else if (this.actionOptions.fetchStyle === \"universal\") {\n this.architectureFetchSuffix = \"universal\";\n } else {\n throw new Error(\n `fetchStyle ${this.actionOptions.fetchStyle} is not a valid style`,\n );\n }\n\n this.sourceParameters = constructSourceParameters(\n this.actionOptions.legacySourcePrefix,\n );\n\n this.recordEvent(`begin_${this.executionPhase}`);\n }\n\n /**\n * Attach a file to the diagnostics data in error conditions.\n *\n * The file at `location` doesn't need to exist when stapleFile is called.\n *\n * If the file doesn't exist or is unreadable when trying to staple the attachments, the JS error will be stored in a context value at `staple_failure_{name}`.\n * If the file is readable, the file's contents will be stored in a context value at `staple_value_{name}`.\n */\n stapleFile(name: string, location: string): void {\n this.exceptionAttachments.set(name, location);\n }\n\n /**\n * The main execution phase.\n */\n abstract main(): Promise;\n\n /**\n * The post execution phase.\n */\n abstract post(): Promise;\n\n /**\n * Execute the Action as defined.\n */\n execute(): void {\n // eslint-disable-next-line github/no-then\n this.executeAsync().catch((error: Error) => {\n // eslint-disable-next-line no-console\n console.log(error);\n process.exitCode = 1;\n });\n }\n\n getTemporaryName(): string {\n const tmpDir = process.env[\"RUNNER_TEMP\"] || tmpdir();\n return path.join(tmpDir, `${this.actionOptions.name}-${randomUUID()}`);\n }\n\n addFact(key: string, value: string | boolean): void {\n this.facts[key] = value;\n }\n\n async getDiagnosticsUrl(): Promise {\n return await this.idsHost.getDiagnosticsUrl();\n }\n\n getUniqueId(): string {\n return (\n this.identity.run_differentiator ||\n process.env.RUNNER_TRACKING_ID ||\n randomUUID()\n );\n }\n\n getCorrelationHashes(): correlation.AnonymizedCorrelationHashes {\n return this.identity;\n }\n\n recordEvent(eventName: string, context: Record = {}): void {\n this.events.push({\n event_name: `${this.actionOptions.eventPrefix}${eventName}`,\n context,\n correlation: this.identity,\n facts: this.facts,\n timestamp: new Date(),\n uuid: randomUUID(),\n });\n }\n\n /**\n * Unpacks the closure returned by `fetchArtifact()`, imports the\n * contents into the Nix store, and returns the path of the executable at\n * `/nix/store/STORE_PATH/bin/${bin}`.\n */\n async unpackClosure(bin: string): Promise {\n const artifact = await this.fetchArtifact();\n const { stdout } = await promisify(exec)(\n `cat \"${artifact}\" | xz -d | nix-store --import`,\n );\n const paths = stdout.split(os.EOL);\n const lastPath = paths.at(-2);\n return `${lastPath}/bin/${bin}`;\n }\n\n /**\n * Fetches the executable at the URL determined by the `source-*` inputs and\n * other facts, `chmod`s it, and returns the path to the executable on disk.\n */\n async fetchExecutable(): Promise {\n const binaryPath = await this.fetchArtifact();\n await chmod(binaryPath, fs.constants.S_IXUSR | fs.constants.S_IXGRP);\n return binaryPath;\n }\n\n private get isMain(): boolean {\n return this.executionPhase === \"main\";\n }\n\n private get isPost(): boolean {\n return this.executionPhase === \"post\";\n }\n\n private async executeAsync(): Promise {\n try {\n process.env.DETSYS_CORRELATION = JSON.stringify(\n this.getCorrelationHashes(),\n );\n\n if (!(await this.preflightRequireNix())) {\n this.recordEvent(EVENT_PREFLIGHT_REQUIRE_NIX_DENIED);\n return;\n } else {\n await this.preflightNixStoreInfo();\n this.addFact(FACT_NIX_STORE_TRUST, this.nixStoreTrust);\n }\n\n if (this.isMain) {\n await this.main();\n } else if (this.isPost) {\n await this.post();\n }\n this.addFact(FACT_ENDED_WITH_EXCEPTION, false);\n } catch (e: unknown) {\n this.addFact(FACT_ENDED_WITH_EXCEPTION, true);\n\n const reportable = stringifyError(e);\n\n this.addFact(FACT_FINAL_EXCEPTION, reportable);\n\n if (this.isPost) {\n actionsCore.warning(reportable);\n } else {\n actionsCore.setFailed(reportable);\n }\n\n const doGzip = promisify(gzip);\n\n const exceptionContext: Map = new Map();\n for (const [attachmentLabel, filePath] of this.exceptionAttachments) {\n try {\n const logText = readFileSync(filePath);\n const buf = await doGzip(logText);\n exceptionContext.set(\n `staple_value_${attachmentLabel}`,\n buf.toString(\"base64\"),\n );\n } catch (innerError: unknown) {\n exceptionContext.set(\n `staple_failure_${attachmentLabel}`,\n stringifyError(innerError),\n );\n }\n }\n\n this.recordEvent(EVENT_EXCEPTION, Object.fromEntries(exceptionContext));\n } finally {\n await this.complete();\n }\n }\n\n /**\n * Fetch an artifact, such as a tarball, from the location determined by the\n * `source-*` inputs. If `source-binary` is specified, this will return a path\n * to a binary on disk; otherwise, the artifact will be downloaded from the\n * URL determined by the other `source-*` inputs (`source-url`, `source-pr`,\n * etc.).\n */\n private async fetchArtifact(): Promise {\n const sourceBinary = getStringOrNull(\"source-binary\");\n\n // If source-binary is set, use that. Otherwise fall back to the source-* parameters.\n if (sourceBinary !== null && sourceBinary !== \"\") {\n actionsCore.debug(`Using the provided source binary at ${sourceBinary}`);\n return sourceBinary;\n }\n\n actionsCore.startGroup(\n `Downloading ${this.actionOptions.name} for ${this.architectureFetchSuffix}`,\n );\n\n try {\n actionsCore.info(`Fetching from ${await this.getSourceUrl()}`);\n\n const correlatedUrl = await this.getSourceUrl();\n correlatedUrl.searchParams.set(\"ci\", \"github\");\n correlatedUrl.searchParams.set(\n \"correlation\",\n JSON.stringify(this.identity),\n );\n\n const versionCheckup = await this.client.head(correlatedUrl);\n if (versionCheckup.headers.etag) {\n const v = versionCheckup.headers.etag;\n this.addFact(FACT_SOURCE_URL_ETAG, v);\n\n actionsCore.debug(\n `Checking the tool cache for ${await this.getSourceUrl()} at ${v}`,\n );\n const cached = await this.getCachedVersion(v);\n if (cached) {\n this.facts[FACT_ARTIFACT_FETCHED_FROM_CACHE] = true;\n actionsCore.debug(`Tool cache hit.`);\n return cached;\n }\n }\n\n this.facts[FACT_ARTIFACT_FETCHED_FROM_CACHE] = false;\n\n actionsCore.debug(\n `No match from the cache, re-fetching from the redirect: ${versionCheckup.url}`,\n );\n\n const destFile = this.getTemporaryName();\n const fetchStream = this.client.stream(versionCheckup.url);\n\n await pipeline(\n fetchStream,\n createWriteStream(destFile, {\n encoding: \"binary\",\n mode: 0o755,\n }),\n );\n\n if (fetchStream.response?.headers.etag) {\n const v = fetchStream.response.headers.etag;\n\n try {\n await this.saveCachedVersion(v, destFile);\n } catch (e: unknown) {\n actionsCore.debug(`Error caching the artifact: ${stringifyError(e)}`);\n }\n }\n\n return destFile;\n } finally {\n actionsCore.endGroup();\n }\n }\n\n /**\n * A helper function for failing on error only if strict mode is enabled.\n * This is intended only for CI environments testing Actions themselves.\n */\n failOnError(msg: string): void {\n if (this.strictMode) {\n actionsCore.setFailed(`strict mode failure: ${msg}`);\n }\n }\n\n private async complete(): Promise {\n this.recordEvent(`complete_${this.executionPhase}`);\n await this.submitEvents();\n }\n\n private async getSourceUrl(): Promise {\n const p = this.sourceParameters;\n\n if (p.url) {\n this.addFact(FACT_SOURCE_URL, p.url);\n return new URL(p.url);\n }\n\n const fetchUrl = await this.idsHost.getRootUrl();\n fetchUrl.pathname += this.actionOptions.idsProjectName;\n\n if (p.tag) {\n fetchUrl.pathname += `/tag/${p.tag}`;\n } else if (p.pr) {\n fetchUrl.pathname += `/pr/${p.pr}`;\n } else if (p.branch) {\n fetchUrl.pathname += `/branch/${p.branch}`;\n } else if (p.revision) {\n fetchUrl.pathname += `/rev/${p.revision}`;\n } else {\n fetchUrl.pathname += `/stable`;\n }\n\n fetchUrl.pathname += `/${this.architectureFetchSuffix}`;\n\n this.addFact(FACT_SOURCE_URL, fetchUrl.toString());\n\n return fetchUrl;\n }\n\n private cacheKey(version: string): string {\n const cleanedVersion = version.replace(/[^a-zA-Z0-9-+.]/g, \"\");\n return `determinatesystem-${this.actionOptions.name}-${this.architectureFetchSuffix}-${cleanedVersion}`;\n }\n\n private async getCachedVersion(version: string): Promise {\n const startCwd = process.cwd();\n\n try {\n const tempDir = this.getTemporaryName();\n await mkdir(tempDir);\n process.chdir(tempDir);\n\n // extremely evil shit right here:\n process.env.GITHUB_WORKSPACE_BACKUP = process.env.GITHUB_WORKSPACE;\n delete process.env.GITHUB_WORKSPACE;\n\n if (\n await actionsCache.restoreCache(\n [this.actionOptions.name],\n this.cacheKey(version),\n [],\n undefined,\n true,\n )\n ) {\n this.recordEvent(EVENT_ARTIFACT_CACHE_HIT);\n return `${tempDir}/${this.actionOptions.name}`;\n }\n\n this.recordEvent(EVENT_ARTIFACT_CACHE_MISS);\n return undefined;\n } finally {\n process.env.GITHUB_WORKSPACE = process.env.GITHUB_WORKSPACE_BACKUP;\n delete process.env.GITHUB_WORKSPACE_BACKUP;\n process.chdir(startCwd);\n }\n }\n\n private async saveCachedVersion(\n version: string,\n toolPath: string,\n ): Promise {\n const startCwd = process.cwd();\n\n try {\n const tempDir = this.getTemporaryName();\n await mkdir(tempDir);\n process.chdir(tempDir);\n await copyFile(toolPath, `${tempDir}/${this.actionOptions.name}`);\n\n // extremely evil shit right here:\n process.env.GITHUB_WORKSPACE_BACKUP = process.env.GITHUB_WORKSPACE;\n delete process.env.GITHUB_WORKSPACE;\n\n await actionsCache.saveCache(\n [this.actionOptions.name],\n this.cacheKey(version),\n undefined,\n true,\n );\n this.recordEvent(EVENT_ARTIFACT_CACHE_PERSIST);\n } finally {\n process.env.GITHUB_WORKSPACE = process.env.GITHUB_WORKSPACE_BACKUP;\n delete process.env.GITHUB_WORKSPACE_BACKUP;\n process.chdir(startCwd);\n }\n }\n\n private async preflightRequireNix(): Promise {\n let nixLocation: string | undefined;\n\n const pathParts = (process.env[\"PATH\"] || \"\").split(\":\");\n for (const location of pathParts) {\n const candidateNix = path.join(location, \"nix\");\n\n try {\n await fs.access(candidateNix, fs.constants.X_OK);\n actionsCore.debug(`Found Nix at ${candidateNix}`);\n nixLocation = candidateNix;\n break;\n } catch {\n actionsCore.debug(`Nix not at ${candidateNix}`);\n }\n }\n this.addFact(FACT_NIX_LOCATION, nixLocation || \"\");\n\n if (this.actionOptions.requireNix === \"ignore\") {\n return true;\n }\n\n const currentNotFoundState = actionsCore.getState(STATE_KEY_NIX_NOT_FOUND);\n if (currentNotFoundState === STATE_NOT_FOUND) {\n // It was previously not found, so don't run subsequent actions\n return false;\n }\n\n if (nixLocation !== undefined) {\n return true;\n }\n actionsCore.saveState(STATE_KEY_NIX_NOT_FOUND, STATE_NOT_FOUND);\n\n switch (this.actionOptions.requireNix) {\n case \"fail\":\n actionsCore.setFailed(\n [\n \"This action can only be used when Nix is installed.\",\n \"Add `- uses: DeterminateSystems/nix-installer-action@main` earlier in your workflow.\",\n ].join(\" \"),\n );\n break;\n case \"warn\":\n actionsCore.warning(\n [\n \"This action is in no-op mode because Nix is not installed.\",\n \"Add `- uses: DeterminateSystems/nix-installer-action@main` earlier in your workflow.\",\n ].join(\" \"),\n );\n break;\n }\n\n return false;\n }\n\n private async preflightNixStoreInfo(): Promise {\n let output = \"\";\n\n const options: actionsExec.ExecOptions = {};\n options.silent = true;\n options.listeners = {\n stdout: (data) => {\n output += data.toString();\n },\n };\n\n try {\n output = \"\";\n await actionsExec.exec(\"nix\", [\"store\", \"info\", \"--json\"], options);\n this.addFact(FACT_NIX_STORE_CHECK_METHOD, \"info\");\n } catch {\n try {\n // reset output\n output = \"\";\n await actionsExec.exec(\"nix\", [\"store\", \"ping\", \"--json\"], options);\n this.addFact(FACT_NIX_STORE_CHECK_METHOD, \"ping\");\n } catch {\n this.addFact(FACT_NIX_STORE_CHECK_METHOD, \"none\");\n return;\n }\n }\n\n try {\n const parsed = JSON.parse(output);\n if (parsed.trusted === 1) {\n this.nixStoreTrust = \"trusted\";\n } else if (parsed.trusted === 0) {\n this.nixStoreTrust = \"untrusted\";\n } else if (parsed.trusted !== undefined) {\n this.addFact(\n FACT_NIX_STORE_CHECK_ERROR,\n `Mysterious trusted value: ${JSON.stringify(parsed.trusted)}`,\n );\n }\n\n this.addFact(FACT_NIX_STORE_VERSION, JSON.stringify(parsed.version));\n } catch (e: unknown) {\n this.addFact(FACT_NIX_STORE_CHECK_ERROR, stringifyError(e));\n }\n }\n\n private async submitEvents(): Promise {\n const diagnosticsUrl = await this.idsHost.getDiagnosticsUrl();\n if (diagnosticsUrl === undefined) {\n actionsCore.debug(\n \"Diagnostics are disabled. Not sending the following events:\",\n );\n actionsCore.debug(JSON.stringify(this.events, undefined, 2));\n return;\n }\n\n const batch = {\n type: \"eventlog\",\n sent_at: new Date(),\n events: this.events,\n };\n\n try {\n await this.client.post(diagnosticsUrl, {\n json: batch,\n timeout: {\n request: DIAGNOSTIC_ENDPOINT_TIMEOUT_MS,\n },\n });\n } catch (e: unknown) {\n actionsCore.debug(\n `Error submitting diagnostics event: ${stringifyError(e)}`,\n );\n this.idsHost.markCurrentHostBroken();\n\n const secondaryDiagnosticsUrl = await this.idsHost.getDiagnosticsUrl();\n if (secondaryDiagnosticsUrl !== undefined) {\n try {\n await this.client.post(secondaryDiagnosticsUrl, {\n json: batch,\n timeout: {\n request: DIAGNOSTIC_ENDPOINT_TIMEOUT_MS,\n },\n });\n } catch (err: unknown) {\n actionsCore.debug(\n `Error submitting diagnostics event to secondary host (${secondaryDiagnosticsUrl}): ${stringifyError(err)}`,\n );\n }\n }\n }\n this.events = [];\n }\n}\n\nfunction stringifyError(error: unknown): string {\n return error instanceof Error || typeof error == \"string\"\n ? error.toString()\n : JSON.stringify(error);\n}\n\nfunction makeOptionsConfident(\n actionOptions: ActionOptions,\n): ConfidentActionOptions {\n const idsProjectName = actionOptions.idsProjectName ?? actionOptions.name;\n\n const finalOpts: ConfidentActionOptions = {\n name: actionOptions.name,\n idsProjectName,\n eventPrefix: actionOptions.eventPrefix || \"action:\",\n fetchStyle: actionOptions.fetchStyle,\n legacySourcePrefix: actionOptions.legacySourcePrefix,\n requireNix: actionOptions.requireNix,\n };\n\n actionsCore.debug(\"idslib options:\");\n actionsCore.debug(JSON.stringify(finalOpts, undefined, 2));\n\n return finalOpts;\n}\n\n// Public exports from other files\nexport { stringifyError } from \"./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ore","actionsCore","actionsCore","actionsCore","actionsCore","actionsCore","exec","readFileSync","fs","os","promisify","error","stringifyError","version"]} \ No newline at end of file diff --git a/package.json b/package.json index dee3fb8..0fc095d 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,8 @@ "build": "tsup", "check-fmt": "prettier --check .", "format": "prettier --write .", - "lint": "eslint src/**/*.ts --ignore-pattern *.test.ts", - "docs": "typedoc src/index.ts", + "lint": "eslint src/**/*.ts", + "docs": "typedoc --tsconfig ./tsconfig.typedoc.json src/index.ts", "test": "vitest --watch false", "test-dev": "vitest", "all": "rm -rf dist && pnpm run format && pnpm run lint && pnpm run build" diff --git a/src/ids-host.test.ts b/src/ids-host.test.ts new file mode 100644 index 0000000..4c5e95c --- /dev/null +++ b/src/ids-host.test.ts @@ -0,0 +1,313 @@ +import { + IdsHost, + discoverServicesStub, + orderRecordsByPriorityWeight, + recordToUrl, + weightedRandom, +} from "./ids-host"; +import { SrvRecord } from "node:dns"; +import { assert, describe, expect, test } from "vitest"; + +function mkRecord( + weight: number, + priority = 0, + suffix = "install.determinate.systems", +): SrvRecord { + return { + weight, + priority, + port: priority * 100 + weight, + name: `${priority}.${weight}.${suffix}`, + }; +} + +async function mkPromise(lookup: () => T): Promise { + return lookup(); +} + +describe("getRootUrl", () => { + test("handles no URLs", async () => { + const host = new IdsHost("foo", "bar", "-"); + host.setPrioritizedUrls([]); + expect(await host.getRootUrl()).toStrictEqual( + new URL("https://install.determinate.systems"), + ); + }); + + test("handles multiple URLs", async () => { + const host = new IdsHost("foo", "bar", "-"); + host.setPrioritizedUrls(["https://foo/", "https://bar/"]); + expect(await host.getRootUrl()).toStrictEqual(new URL("https://foo")); + }); + + test("falls back on downed URL", async () => { + const host = new IdsHost("foo", "bar", "-"); + host.setPrioritizedUrls(["https://foo/", "https://bar/"]); + expect(await host.getRootUrl()).toStrictEqual(new URL("https://foo")); + host.markCurrentHostBroken(); + expect(await host.getRootUrl()).toStrictEqual(new URL("https://bar")); + host.markCurrentHostBroken(); + expect(await host.getRootUrl()).toStrictEqual( + new URL("https://install.determinate.systems"), + ); + host.markCurrentHostBroken(); + host.markCurrentHostBroken(); + expect(await host.getRootUrl()).toStrictEqual( + new URL("https://install.determinate.systems"), + ); + }); +}); + +describe("getDiagnosticsUrl", () => { + type TestCase = { + description: string; + idsProjectName: string; + suffix?: string; + runtimeDiagnosticsUrl?: string; + expectedUrl?: string; + }; + + const testCases: TestCase[] = [ + { + description: "User-provided diagnostic URL is preferred", + idsProjectName: "project-name", + suffix: "telemetry", + runtimeDiagnosticsUrl: "https://example.com/bar", + expectedUrl: "https://example.com/bar", + }, + + { + description: "Empty diagnostic URL means turn it off", + idsProjectName: "project-name", + suffix: "telemetry", + runtimeDiagnosticsUrl: "", + expectedUrl: undefined, + }, + + { + description: + "No diagnostics URL provided means generate one (custom suffix)", + idsProjectName: "project-name", + suffix: "telemetry", + runtimeDiagnosticsUrl: undefined, + expectedUrl: "https://install.determinate.systems/project-name/telemetry", + }, + + { + description: + "'-' as the diagnostics URL means generate one (custom suffix)", + idsProjectName: "project-name", + suffix: "telemetry", + runtimeDiagnosticsUrl: "-", + expectedUrl: "https://install.determinate.systems/project-name/telemetry", + }, + + { + description: + "No diagnostics URL provided means generate one (default suffix)", + idsProjectName: "project-name", + suffix: undefined, + runtimeDiagnosticsUrl: undefined, + expectedUrl: + "https://install.determinate.systems/project-name/diagnostics", + }, + + { + description: + "Invalid user-provided diagnostic URL might be a whitespace-only string or otherwise, so use the default", + idsProjectName: "project-name", + runtimeDiagnosticsUrl: "http://hi:999999999999", + expectedUrl: + "https://install.determinate.systems/project-name/diagnostics", + }, + ]; + + for (const { + description, + idsProjectName, + suffix, + runtimeDiagnosticsUrl, + expectedUrl, + } of testCases) { + test(description, async () => { + const preEnv = process.env["IDS_HOST"]; + process.env["IDS_HOST"] = "https://install.determinate.systems"; + + const host = new IdsHost(idsProjectName, suffix, runtimeDiagnosticsUrl); + const diagUrl = await host.getDiagnosticsUrl(); + process.env["IDS_HOST"] = preEnv; + + expect(diagUrl).toStrictEqual( + expectedUrl ? new URL(expectedUrl) : undefined, + ); + }); + } +}); + +describe("recordToUrl", () => { + test("a valid record", () => { + expect( + recordToUrl({ + name: "hi", + port: 123, + priority: 1, + weight: 1, + }), + ).toStrictEqual(new URL("https://hi:123")); + }); + + test("an invalid record", () => { + expect( + recordToUrl({ + name: "!", + port: 99999999999, + priority: 1, + weight: 1, + }), + ).toStrictEqual(undefined); + }); +}); + +describe("discoverServicesStub", async () => { + type TestCase = { + description: string; + lookup: () => Promise; + timeout?: number; + expected: SrvRecord[]; + }; + + const testCases: TestCase[] = [ + { + description: "lookup has an exception", + lookup: async () => { + throw new Error("oops"); + }, + expected: [], + timeout: 0, + }, + + { + description: "basic in / out", + lookup: async () => { + return mkPromise(() => { + return [mkRecord(1)]; + }); + }, + expected: [mkRecord(1)], + }, + + { + description: "Records with invalid suffixes are omitted", + lookup: async () => { + return mkPromise(() => { + return [ + mkRecord(1, 1, "mallory.com"), + mkRecord(1, 1, "install.detsys.dev"), + mkRecord(1, 1, "install.determinate.systems"), + ]; + }); + }, + expected: [ + mkRecord(1, 1, "install.detsys.dev"), + mkRecord(1, 1, "install.determinate.systems"), + ], + }, + + { + description: "lookup loses the race", + lookup: async () => { + return new Promise((r) => setTimeout(r, 1000, [mkRecord(123)])); + }, + expected: [], + timeout: 100, + }, + { + description: "lookup wins the race", + lookup: async () => { + return new Promise((r) => setTimeout(r, 100, [mkRecord(456)])); + }, + expected: [mkRecord(456)], + timeout: 1000, + }, + ]; + + for (const { description, lookup, timeout, expected } of testCases) { + test(description, async () => { + const ret = await discoverServicesStub(lookup(), timeout || 0); + expect(ret).toStrictEqual(expected); + }); + } +}); + +test("orderRecordsByPriorityWeight does that", () => { + expect( + orderRecordsByPriorityWeight([ + mkRecord(3, 3), + mkRecord(1000, 1), + mkRecord(2, 2), + mkRecord(1, 1), + ]), + ).toStrictEqual([ + mkRecord(1000, 1), + mkRecord(1, 1), + mkRecord(2, 2), + mkRecord(3, 3), + ]); +}); + +test("weightedRandom handles empty and single-element records", () => { + expect(weightedRandom([]), "one element passes through").toStrictEqual([]); + + expect( + weightedRandom([mkRecord(1)]), + "empty lists aren't crashing", + ).toStrictEqual([mkRecord(1)]); +}); + +test("weightedRandom orders records acceptably predictably", () => { + const records: SrvRecord[] = [mkRecord(1), mkRecord(2), mkRecord(3)]; + + const counts: Map = new Map(); + counts.set(1, 0); + counts.set(2, 0); + counts.set(3, 0); + + const iterations = 1_000; + + for (let i = 0; i < iterations; i++) { + const weighted = weightedRandom(records); + counts.set( + weighted[0].weight, + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + counts.get(weighted[0].weight)! + 1, + ); + } + + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const firstPlaceSum1 = counts.get(1)!; + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const firstPlaceSum2 = counts.get(2)!; + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const firstPlaceSum3 = counts.get(3)!; + + assert.equal(firstPlaceSum1 + firstPlaceSum2 + firstPlaceSum3, iterations); + + assert.closeTo( + firstPlaceSum3 / iterations, + 3 / 6, + 1 / 6, + "3 should be first approximately 3/6 of the time", + ); + assert.closeTo( + firstPlaceSum2 / iterations, + 2 / 6, + 1 / 6, + "2 should be first approximately 2/6 of the time", + ); + assert.closeTo( + firstPlaceSum1 / iterations, + 1 / 6, + 1 / 6, + "1 should be first approximately 1/6 of the time", + ); +}); diff --git a/src/ids-host.ts b/src/ids-host.ts new file mode 100644 index 0000000..eac46f0 --- /dev/null +++ b/src/ids-host.ts @@ -0,0 +1,243 @@ +/** + * @packageDocumentation + * Identifies and discovers backend servers for install.determinate.systems + */ +import { stringifyError } from "./errors.js"; +import * as actionsCore from "@actions/core"; +import { SrvRecord } from "node:dns"; +import { resolveSrv } from "node:dns/promises"; + +const DEFAULT_LOOKUP = "_detsys_ids._tcp.install.determinate.systems."; +const ALLOWED_SUFFIXES = [ + ".install.determinate.systems", + ".install.detsys.dev", +]; + +const DEFAULT_IDS_HOST = "https://install.determinate.systems"; +const LOOKUP = process.env["IDS_LOOKUP"] ?? DEFAULT_LOOKUP; + +export class IdsHost { + private idsProjectName: string; + private diagnosticsSuffix?: string; + private runtimeDiagnosticsUrl?: string; + private prioritizedURLs?: URL[]; + private records?: SrvRecord[]; + + constructor( + idsProjectName: string, + diagnosticsSuffix: string | undefined, + runtimeDiagnosticsUrl: string | undefined, + ) { + this.idsProjectName = idsProjectName; + this.diagnosticsSuffix = diagnosticsSuffix; + this.runtimeDiagnosticsUrl = runtimeDiagnosticsUrl; + } + + markCurrentHostBroken(): void { + this.prioritizedURLs?.shift(); + } + + setPrioritizedUrls(urls: URL[]): void { + this.prioritizedURLs = urls; + } + + async getRootUrl(): Promise { + const idsHost = process.env["IDS_HOST"]; + if (idsHost !== undefined) { + try { + return new URL(idsHost); + } catch (err: unknown) { + actionsCore.error( + `IDS_HOST environment variable is not a valid URL. Ignoring. ${stringifyError(err)}`, + ); + } + } + + let url: URL | undefined = undefined; + try { + const urls = await this.getUrlsByPreference(); + url = urls[0]; + } catch (err: unknown) { + actionsCore.error( + `Error collecting IDS URLs by preference: ${stringifyError(err)}`, + ); + } + + if (url === undefined) { + url = new URL(DEFAULT_IDS_HOST); + } + + // This is a load-bearing `new URL(url)` so that callers can't mutate + // getRootUrl's return value. + return new URL(url); + } + + async getDiagnosticsUrl(): Promise { + if (this.runtimeDiagnosticsUrl === "") { + // User specifically set the diagnostics URL to an empty string + // so disable diagnostics + return undefined; + } + + if ( + this.runtimeDiagnosticsUrl !== "-" && + this.runtimeDiagnosticsUrl !== undefined + ) { + try { + // Caller specified a specific diagnostics URL + return new URL(this.runtimeDiagnosticsUrl); + } catch (err: unknown) { + actionsCore.info( + `User-provided diagnostic endpoint ignored: not a valid URL: ${stringifyError(err)}`, + ); + } + } + + try { + const diagnosticUrl = await this.getRootUrl(); + diagnosticUrl.pathname += this.idsProjectName; + diagnosticUrl.pathname += "/"; + diagnosticUrl.pathname += this.diagnosticsSuffix || "diagnostics"; + return diagnosticUrl; + } catch (err: unknown) { + actionsCore.info( + `Generated diagnostic endpoint ignored, and diagnostics are disabled: not a valid URL: ${stringifyError(err)}`, + ); + return undefined; + } + } + + private async getUrlsByPreference(): Promise { + if (this.prioritizedURLs === undefined) { + this.prioritizedURLs = orderRecordsByPriorityWeight( + await discoverServiceRecords(), + ).flatMap((record) => recordToUrl(record) || []); + } + + return this.prioritizedURLs; + } +} + +export function recordToUrl(record: SrvRecord): URL | undefined { + const urlStr = `https://${record.name}:${record.port}`; + try { + return new URL(urlStr); + } catch (err: unknown) { + actionsCore.debug( + `Record ${JSON.stringify(record)} produced an invalid URL: ${urlStr} (${err})`, + ); + return undefined; + } +} + +async function discoverServiceRecords(): Promise { + return await discoverServicesStub(resolveSrv(LOOKUP), 1_000); +} + +export async function discoverServicesStub( + lookup: Promise, + timeout: number, +): Promise { + const defaultFallback: Promise = new Promise( + (resolve, _reject) => { + setTimeout(resolve, timeout, []); + }, + ); + + let records: SrvRecord[]; + + try { + records = await Promise.race([lookup, defaultFallback]); + } catch (reason: unknown) { + actionsCore.debug(`Error resolving SRV records: ${stringifyError(reason)}`); + records = []; + } + + const acceptableRecords = records.filter((record: SrvRecord): boolean => { + for (const suffix of ALLOWED_SUFFIXES) { + if (record.name.endsWith(suffix)) { + return true; + } + } + + actionsCore.debug( + `Unacceptable domain due to an invalid suffix: ${record.name}`, + ); + + return false; + }); + + if (acceptableRecords.length === 0) { + actionsCore.debug(`No records found for ${LOOKUP}`); + } else { + actionsCore.debug( + `Resolved ${LOOKUP} to ${JSON.stringify(acceptableRecords)}`, + ); + } + + return acceptableRecords; +} + +export function orderRecordsByPriorityWeight( + records: SrvRecord[], +): SrvRecord[] { + const byPriorityWeight: Map = new Map(); + for (const record of records) { + const existing = byPriorityWeight.get(record.priority); + if (existing) { + existing.push(record); + } else { + byPriorityWeight.set(record.priority, [record]); + } + } + + const prioritizedRecords: SrvRecord[] = []; + const keys: number[] = Array.from(byPriorityWeight.keys()).sort( + (a, b) => a - b, + ); + + for (const priority of keys) { + const recordsByPrio = byPriorityWeight.get(priority); + if (recordsByPrio === undefined) { + continue; + } + + prioritizedRecords.push(...weightedRandom(recordsByPrio)); + } + + return prioritizedRecords; +} + +export function weightedRandom(records: SrvRecord[]): SrvRecord[] { + // Duplicate records so we don't accidentally change our caller's data + const scratchRecords: SrvRecord[] = records.slice(); + const result: SrvRecord[] = []; + + while (scratchRecords.length > 0) { + const weights: number[] = []; + + { + for (let i = 0; i < scratchRecords.length; i++) { + weights.push( + scratchRecords[i].weight + (i > 0 ? scratchRecords[i - 1].weight : 0), + ); + } + } + + const point = Math.random() * weights[weights.length - 1]; + + for ( + let selectedIndex = 0; + selectedIndex < weights.length; + selectedIndex++ + ) { + if (weights[selectedIndex] > point) { + // Remove our selected record and add it to the result + result.push(scratchRecords.splice(selectedIndex, 1)[0]); + break; + } + } + } + + return result; +} diff --git a/src/index.ts b/src/index.ts index cffcf80..dbfa628 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,6 +5,7 @@ import { version as pkgVersion } from "../package.json"; import * as ghActionsCorePlatform from "./actions-core-platform.js"; import * as correlation from "./correlation.js"; +import { IdsHost } from "./ids-host.js"; import { getBool, getStringOrNull } from "./inputs.js"; import * as platform from "./platform.js"; import { SourceDef, constructSourceParameters } from "./sourcedef.js"; @@ -23,9 +24,6 @@ import { pipeline } from "node:stream/promises"; import { promisify } from "node:util"; import { gzip } from "node:zlib"; -const DEFAULT_IDS_HOST = "https://install.determinate.systems"; -const IDS_HOST = process.env["IDS_HOST"] ?? DEFAULT_IDS_HOST; - const EVENT_EXCEPTION = "exception"; const EVENT_ARTIFACT_CACHE_HIT = "artifact_cache_hit"; const EVENT_ARTIFACT_CACHE_MISS = "artifact_cache_miss"; @@ -109,12 +107,12 @@ export type ActionOptions = { // The action will emit a user-visible warning instructing them to install Nix. requireNix: NixRequirementHandling; - // The URL to send diagnostics events to. - // Specifically: - // * `undefined` -> Attempt to read the `diagnostic-enpdoint` action input, and calculate the default diagnostics URL for IDS from there. - // * `null` -> Disable sending diagnostics altogether. - // * URL(...) -> Send diagnostics to this other URL instead - diagnosticsUrl?: URL | null; + // The URL suffix to send diagnostics events to. + // + // The final URL is constructed via IDS_HOST/idsProjectName/diagnosticsSuffix. + // + // Default: `diagnostics`. + diagnosticsSuffix?: string; }; // A confident version of Options, where defaults have been resolved into final values @@ -125,7 +123,7 @@ type ConfidentActionOptions = { fetchStyle: FetchSuffixStyle; legacySourcePrefix?: string; requireNix: NixRequirementHandling; - diagnosticsUrl?: URL; + providedDiagnosticsUrl?: URL; }; type DiagnosticEvent = { @@ -152,6 +150,7 @@ export abstract class DetSysAction { private facts: Record; private events: DiagnosticEvent[]; private identity: correlation.AnonymizedCorrelationHashes; + private idsHost: IdsHost; private determineExecutionPhase(): ExecutionPhase { const currentPhase = actionsCore.getState(STATE_KEY_EXECUTION_PHASE); @@ -165,6 +164,13 @@ export abstract class DetSysAction { constructor(actionOptions: ActionOptions) { this.actionOptions = makeOptionsConfident(actionOptions); + this.idsHost = new IdsHost( + this.actionOptions.idsProjectName, + actionOptions.diagnosticsSuffix, + // Note: we don't use actionsCore.getInput('diagnostic-endpoint') on purpose: + // getInput silently converts absent data to an empty string. + process.env["INPUT_DIAGNOSTIC-ENDPOINT"], + ); this.exceptionAttachments = new Map(); this.nixStoreTrust = "unknown"; this.strictMode = getBool("_internal-strict-mode"); @@ -301,8 +307,8 @@ export abstract class DetSysAction { this.facts[key] = value; } - getDiagnosticsUrl(): URL | undefined { - return this.actionOptions.diagnosticsUrl; + async getDiagnosticsUrl(): Promise { + return await this.idsHost.getDiagnosticsUrl(); } getUniqueId(): string { @@ -440,9 +446,9 @@ export abstract class DetSysAction { ); try { - actionsCore.info(`Fetching from ${this.getSourceUrl()}`); + actionsCore.info(`Fetching from ${await this.getSourceUrl()}`); - const correlatedUrl = this.getSourceUrl(); + const correlatedUrl = await this.getSourceUrl(); correlatedUrl.searchParams.set("ci", "github"); correlatedUrl.searchParams.set( "correlation", @@ -455,7 +461,7 @@ export abstract class DetSysAction { this.addFact(FACT_SOURCE_URL_ETAG, v); actionsCore.debug( - `Checking the tool cache for ${this.getSourceUrl()} at ${v}`, + `Checking the tool cache for ${await this.getSourceUrl()} at ${v}`, ); const cached = await this.getCachedVersion(v); if (cached) { @@ -513,7 +519,7 @@ export abstract class DetSysAction { await this.submitEvents(); } - private getSourceUrl(): URL { + private async getSourceUrl(): Promise { const p = this.sourceParameters; if (p.url) { @@ -521,7 +527,7 @@ export abstract class DetSysAction { return new URL(p.url); } - const fetchUrl = new URL(IDS_HOST); + const fetchUrl = await this.idsHost.getRootUrl(); fetchUrl.pathname += this.actionOptions.idsProjectName; if (p.tag) { @@ -714,7 +720,8 @@ export abstract class DetSysAction { } private async submitEvents(): Promise { - if (this.actionOptions.diagnosticsUrl === undefined) { + const diagnosticsUrl = await this.idsHost.getDiagnosticsUrl(); + if (diagnosticsUrl === undefined) { actionsCore.debug( "Diagnostics are disabled. Not sending the following events:", ); @@ -729,7 +736,7 @@ export abstract class DetSysAction { }; try { - await this.client.post(this.actionOptions.diagnosticsUrl, { + await this.client.post(diagnosticsUrl, { json: batch, timeout: { request: DIAGNOSTIC_ENDPOINT_TIMEOUT_MS, @@ -739,6 +746,23 @@ export abstract class DetSysAction { actionsCore.debug( `Error submitting diagnostics event: ${stringifyError(e)}`, ); + this.idsHost.markCurrentHostBroken(); + + const secondaryDiagnosticsUrl = await this.idsHost.getDiagnosticsUrl(); + if (secondaryDiagnosticsUrl !== undefined) { + try { + await this.client.post(secondaryDiagnosticsUrl, { + json: batch, + timeout: { + request: DIAGNOSTIC_ENDPOINT_TIMEOUT_MS, + }, + }); + } catch (err: unknown) { + actionsCore.debug( + `Error submitting diagnostics event to secondary host (${secondaryDiagnosticsUrl}): ${stringifyError(err)}`, + ); + } + } } this.events = []; } @@ -762,10 +786,6 @@ function makeOptionsConfident( fetchStyle: actionOptions.fetchStyle, legacySourcePrefix: actionOptions.legacySourcePrefix, requireNix: actionOptions.requireNix, - diagnosticsUrl: determineDiagnosticsUrl( - idsProjectName, - actionOptions.diagnosticsUrl, - ), }; actionsCore.debug("idslib options:"); @@ -774,84 +794,6 @@ function makeOptionsConfident( return finalOpts; } -function determineDiagnosticsUrl( - idsProjectName: string, - urlOption?: URL | null, -): undefined | URL { - if (urlOption === null) { - // Disable diagnostict events - return undefined; - } - - if (urlOption !== undefined) { - // Caller specified a specific diagnostics URL - return urlOption; - } - - { - // Attempt to use the action input's diagnostic-endpoint option. - - // Note: we don't use actionsCore.getInput('diagnostic-endpoint') on purpose: - // getInput silently converts absent data to an empty string. - const providedDiagnosticEndpoint = process.env["INPUT_DIAGNOSTIC-ENDPOINT"]; - if (providedDiagnosticEndpoint === "") { - // User probably explicitly turned it off - return undefined; - } - - if (providedDiagnosticEndpoint !== undefined) { - try { - return mungeDiagnosticEndpoint(new URL(providedDiagnosticEndpoint)); - } catch (e: unknown) { - actionsCore.info( - `User-provided diagnostic endpoint ignored: not a valid URL: ${stringifyError(e)}`, - ); - } - } - } - - try { - const diagnosticUrl = new URL(IDS_HOST); - diagnosticUrl.pathname += idsProjectName; - diagnosticUrl.pathname += "/diagnostics"; - return diagnosticUrl; - } catch (e: unknown) { - actionsCore.info( - `Generated diagnostic endpoint ignored: not a valid URL: ${stringifyError(e)}`, - ); - } - - return undefined; -} - -function mungeDiagnosticEndpoint(inputUrl: URL): URL { - if (DEFAULT_IDS_HOST === IDS_HOST) { - return inputUrl; - } - - try { - const defaultIdsHost = new URL(DEFAULT_IDS_HOST); - const currentIdsHost = new URL(IDS_HOST); - - if (inputUrl.origin !== defaultIdsHost.origin) { - return inputUrl; - } - - inputUrl.protocol = currentIdsHost.protocol; - inputUrl.host = currentIdsHost.host; - inputUrl.username = currentIdsHost.username; - inputUrl.password = currentIdsHost.password; - - return inputUrl; - } catch (e: unknown) { - actionsCore.info( - `Default or overridden IDS host isn't a valid URL: ${stringifyError(e)}`, - ); - } - - return inputUrl; -} - // Public exports from other files export { stringifyError } from "./errors.js"; export * as inputs from "./inputs.js"; diff --git a/src/inputs.test.ts b/src/inputs.test.ts index e78c17a..df8552f 100644 --- a/src/inputs.test.ts +++ b/src/inputs.test.ts @@ -1,7 +1,7 @@ import { Separator, handleString } from "./inputs"; -import { expect, test } from "vitest"; +import { describe, expect, test } from "vitest"; -test("converting strings into arrays", () => { +describe("converting strings into arrays", () => { type TestCase = { input: string; separator: Separator; @@ -75,7 +75,9 @@ test("converting strings into arrays", () => { }, ]; - testCases.forEach(({ input, separator, expected }) => - expect(handleString(input, separator)).toStrictEqual(expected), - ); + for (const { input, separator, expected } of testCases) { + test(`Splitting ${JSON.stringify(input)} on ${JSON.stringify(separator)}`, () => { + expect(handleString(input, separator)).toStrictEqual(expected); + }); + } }); diff --git a/tsconfig.json b/tsconfig.json index 971644a..22ca949 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,6 +11,6 @@ "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, "declaration": true }, - "exclude": ["node_modules", "**/*.test.ts", "dist"], + "exclude": ["node_modules", "dist"], "include": ["src/**/*"] } diff --git a/tsconfig.typedoc.json b/tsconfig.typedoc.json new file mode 100644 index 0000000..0a11719 --- /dev/null +++ b/tsconfig.typedoc.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "exclude": ["src/**/*.test.ts"] +}