srv update

This commit is contained in:
Graham Christensen 2024-05-31 11:39:31 -04:00
parent 7718b5acea
commit b4a210999f
6 changed files with 256 additions and 116 deletions

View File

@ -29,6 +29,7 @@
"accessibility": "no-public"
}
],
"@typescript-eslint/no-base-to-string": "error",
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/await-thenable": "error",

View File

@ -16,7 +16,7 @@ inputs:
default: https://cache.nixos.org
diagnostic-endpoint:
description: "Diagnostic endpoint url where diagnostics and performance data is sent. To disable set this to an empty string."
default: "https://install.determinate.systems/magic-nix-cache/perf"
default: "-"
use-flakehub:
description: "Whether to upload build results to FlakeHub Cache."
default: true

332
dist/index.js generated vendored
View File

@ -86693,6 +86693,8 @@ var exec = __nccwpck_require__(7775);
var external_os_ = __nccwpck_require__(2037);
;// CONCATENATED MODULE: external "node:crypto"
const external_node_crypto_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:crypto");
;// CONCATENATED MODULE: external "node:dns/promises"
const external_node_dns_promises_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:dns/promises");
// EXTERNAL MODULE: ./node_modules/.pnpm/@actions+cache@3.2.4/node_modules/@actions/cache/lib/cache.js
var cache = __nccwpck_require__(6878);
;// CONCATENATED MODULE: ./node_modules/.pnpm/@sindresorhus+is@6.3.1/node_modules/@sindresorhus/is/dist/index.js
@ -94089,7 +94091,7 @@ const external_node_child_process_namespaceObject = __WEBPACK_EXTERNAL_createReq
const external_node_stream_promises_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:stream/promises");
;// CONCATENATED MODULE: external "node:zlib"
const external_node_zlib_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:zlib");
;// CONCATENATED MODULE: ./node_modules/.pnpm/github.com+DeterminateSystems+detsys-ts@5fcb0532d85556ebc2de286e483885976531339d_uqngfub4ls4loys67iy653x57e/node_modules/detsys-ts/dist/index.js
;// CONCATENATED MODULE: ./node_modules/.pnpm/github.com+DeterminateSystems+detsys-ts@9d66d2c89c150f796165fdcc20b3be538807c0f4_46ybmzqhaua4eiwu3nj2qm63te/node_modules/detsys-ts/dist/index.js
var __defProp = Object.defineProperty;
var __export = (target, all) => {
for (var name in all)
@ -94175,9 +94177,9 @@ async function readAsyncOsReleaseFile(fileList, options) {
${fileData}`);
}
break;
} catch (error2) {
} catch (error3) {
if (options.debug) {
console.error(error2);
console.error(error3);
}
}
}
@ -94199,9 +94201,9 @@ function readSyncOsreleaseFile(releaseFileList, options) {
${fileData}`);
}
break;
} catch (error2) {
} catch (error3) {
if (options.debug) {
console.error(error2);
console.error(error3);
}
}
}
@ -94393,6 +94395,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
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) {
core.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) {
core.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) {
core.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) {
core.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) {
core.debug(
`Record ${JSON.stringify(record)} produced an invalid URL: ${urlStr} (${err})`
);
return void 0;
}
}
async function discoverServiceRecords() {
return await discoverServicesStub((0,external_node_dns_promises_namespaceObject.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) {
core.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;
}
}
core.debug(
`Unacceptable domain due to an invalid suffix: ${record.name}`
);
return false;
});
if (acceptableRecords.length === 0) {
core.debug(`No records found for ${LOOKUP}`);
} else {
core.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, {
@ -94553,21 +94741,6 @@ function noisilyGetInput(suffix, legacyPrefix) {
// 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";
@ -94601,6 +94774,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");
@ -94612,9 +94792,9 @@ var DetSysAction = class {
},
hooks: {
beforeRetry: [
(error2, retryCount) => {
(error3, retryCount) => {
core.info(
`Retrying after error ${error2.code}, retry #: ${retryCount}`
`Retrying after error ${error3.code}, retry #: ${retryCount}`
);
}
]
@ -94691,8 +94871,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;
});
}
@ -94703,8 +94883,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 || (0,external_node_crypto_namespaceObject.randomUUID)();
@ -94817,8 +94997,8 @@ var DetSysAction = class {
`Downloading ${this.actionOptions.name} for ${this.architectureFetchSuffix}`
);
try {
core.info(`Fetching from ${this.getSourceUrl()}`);
const correlatedUrl = this.getSourceUrl();
core.info(`Fetching from ${await this.getSourceUrl()}`);
const correlatedUrl = await this.getSourceUrl();
correlatedUrl.searchParams.set("ci", "github");
correlatedUrl.searchParams.set(
"correlation",
@ -94829,7 +95009,7 @@ var DetSysAction = class {
const v = versionCheckup.headers.etag;
this.addFact(FACT_SOURCE_URL_ETAG, v);
core.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) {
@ -94877,13 +95057,13 @@ var DetSysAction = class {
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}`;
@ -95039,7 +95219,8 @@ var DetSysAction = class {
}
}
async submitEvents() {
if (this.actionOptions.diagnosticsUrl === void 0) {
const diagnosticsUrl = await this.idsHost.getDiagnosticsUrl();
if (diagnosticsUrl === void 0) {
core.debug(
"Diagnostics are disabled. Not sending the following events:"
);
@ -95052,7 +95233,7 @@ 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
@ -95062,12 +95243,28 @@ var DetSysAction = class {
core.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) {
core.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;
@ -95077,72 +95274,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
};
core.debug("idslib options:");
core.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) {
core.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) {
core.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) {
core.info(
`Default or overridden IDS host isn't a valid URL: ${stringifyError2(e)}`
);
}
return inputUrl;
}
/*!
* linux-release-info
@ -95233,7 +95370,8 @@ var MagicNixCacheAction = class extends DetSysAction {
name: "magic-nix-cache",
fetchStyle: "gh-env-style",
idsProjectName: "magic-nix-cache-closure",
requireNix: "warn"
requireNix: "warn",
diagnosticsSuffix: "perf"
});
this.hostAndPort = inputs_exports.getString("listen");
this.diffStore = inputs_exports.getBool("diff-store");

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -13,7 +13,7 @@ dependencies:
version: 1.1.1
detsys-ts:
specifier: github:DeterminateSystems/detsys-ts
version: github.com/DeterminateSystems/detsys-ts/5fcb0532d85556ebc2de286e483885976531339d
version: github.com/DeterminateSystems/detsys-ts/9d66d2c89c150f796165fdcc20b3be538807c0f4
got:
specifier: ^14.3.0
version: 14.3.0
@ -341,7 +341,7 @@ packages:
'@babel/helper-split-export-declaration': 7.24.6
'@babel/parser': 7.24.6
'@babel/types': 7.24.6
debug: 4.3.4
debug: 4.3.5
globals: 11.12.0
transitivePeerDependencies:
- supports-color
@ -591,7 +591,7 @@ packages:
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
dependencies:
ajv: 6.12.6
debug: 4.3.4
debug: 4.3.5
espree: 9.6.1
globals: 13.24.0
ignore: 5.3.1
@ -622,7 +622,7 @@ packages:
engines: {node: '>=10.10.0'}
dependencies:
'@humanwhocodes/object-schema': 2.0.3
debug: 4.3.4
debug: 4.3.5
minimatch: 3.1.2
transitivePeerDependencies:
- supports-color
@ -960,7 +960,7 @@ packages:
'@typescript-eslint/types': 7.11.0
'@typescript-eslint/typescript-estree': 7.11.0(typescript@5.4.5)
'@typescript-eslint/visitor-keys': 7.11.0
debug: 4.3.4
debug: 4.3.5
eslint: 8.57.0
typescript: 5.4.5
transitivePeerDependencies:
@ -987,7 +987,7 @@ packages:
dependencies:
'@typescript-eslint/typescript-estree': 7.11.0(typescript@5.4.5)
'@typescript-eslint/utils': 7.11.0(eslint@8.57.0)(typescript@5.4.5)
debug: 4.3.4
debug: 4.3.5
eslint: 8.57.0
ts-api-utils: 1.3.0(typescript@5.4.5)
typescript: 5.4.5
@ -1011,7 +1011,7 @@ packages:
dependencies:
'@typescript-eslint/types': 7.11.0
'@typescript-eslint/visitor-keys': 7.11.0
debug: 4.3.4
debug: 4.3.5
globby: 11.1.0
is-glob: 4.0.3
minimatch: 9.0.4
@ -1266,7 +1266,7 @@ packages:
hasBin: true
dependencies:
caniuse-lite: 1.0.30001625
electron-to-chromium: 1.4.784
electron-to-chromium: 1.4.787
node-releases: 2.0.14
update-browserslist-db: 1.0.16(browserslist@4.23.0)
dev: true
@ -1443,8 +1443,8 @@ packages:
ms: 2.1.3
dev: true
/debug@4.3.4:
resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==}
/debug@4.3.5:
resolution: {integrity: sha512-pt0bNEmneDIvdL1Xsd9oDQ/wrQRkXDT4AUWlNZNPKvW5x/jyO9VFXkJUP07vQ2upmw5PlaITaPKc31jK13V+jg==}
engines: {node: '>=6.0'}
peerDependencies:
supports-color: '*'
@ -1524,8 +1524,8 @@ packages:
resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==}
dev: true
/electron-to-chromium@1.4.784:
resolution: {integrity: sha512-9CZwh+sDrhDAeOEFh8s3PqwduzTyYIeYwZolc1b9ENAUt3ePu7R1sJSCWr/820ISssRxCJUyHI9Wb7j+0Uo1AA==}
/electron-to-chromium@1.4.787:
resolution: {integrity: sha512-d0EFmtLPjctczO3LogReyM2pbBiiZbnsKnGF+cdZhsYzHm/A0GV7W94kqzLD8SN4O3f3iHlgLUChqghgyznvCQ==}
dev: true
/emoji-regex@8.0.0:
@ -1731,7 +1731,7 @@ packages:
eslint: '*'
eslint-plugin-import: '*'
dependencies:
debug: 4.3.4
debug: 4.3.5
enhanced-resolve: 5.16.1
eslint: 8.57.0
eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.11.0)(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0)
@ -1969,7 +1969,7 @@ packages:
ajv: 6.12.6
chalk: 4.1.2
cross-spawn: 7.0.3
debug: 4.3.4
debug: 4.3.5
doctrine: 3.0.0
escape-string-regexp: 4.0.0
eslint-scope: 7.2.2
@ -3564,7 +3564,7 @@ packages:
bundle-require: 4.1.0(esbuild@0.19.12)
cac: 6.7.14
chokidar: 3.6.0
debug: 4.3.4
debug: 4.3.5
esbuild: 0.19.12
execa: 5.1.1
globby: 11.1.0
@ -3826,8 +3826,8 @@ packages:
engines: {node: '>=10'}
dev: true
github.com/DeterminateSystems/detsys-ts/5fcb0532d85556ebc2de286e483885976531339d:
resolution: {tarball: https://codeload.github.com/DeterminateSystems/detsys-ts/tar.gz/5fcb0532d85556ebc2de286e483885976531339d}
github.com/DeterminateSystems/detsys-ts/9d66d2c89c150f796165fdcc20b3be538807c0f4:
resolution: {tarball: https://codeload.github.com/DeterminateSystems/detsys-ts/tar.gz/9d66d2c89c150f796165fdcc20b3be538807c0f4}
name: detsys-ts
version: 1.0.0
dependencies:

View File

@ -43,6 +43,7 @@ class MagicNixCacheAction extends DetSysAction {
fetchStyle: "gh-env-style",
idsProjectName: "magic-nix-cache-closure",
requireNix: "warn",
diagnosticsSuffix: "perf",
});
this.hostAndPort = inputs.getString("listen");