Update detsys-ts

This commit is contained in:
Luc Perkins 2024-05-23 19:19:07 -03:00
parent c16b76233e
commit dccc3175bf
No known key found for this signature in database
GPG key ID: 16DB1108FB591835
6 changed files with 89 additions and 134 deletions

168
dist/index.js vendored
View file

@ -39513,7 +39513,7 @@ module.exports =
{ {
parallel : __nccwpck_require__(644), parallel : __nccwpck_require__(644),
serial : __nccwpck_require__(4501), serial : __nccwpck_require__(4501),
serialOrdered : __nccwpck_require__(3958) serialOrdered : __nccwpck_require__(2362)
}; };
@ -39844,7 +39844,7 @@ function parallel(list, iterator, callback)
/***/ 4501: /***/ 4501:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
var serialOrdered = __nccwpck_require__(3958); var serialOrdered = __nccwpck_require__(2362);
// Public API // Public API
module.exports = serial; module.exports = serial;
@ -39865,7 +39865,7 @@ function serial(list, iterator, callback)
/***/ }), /***/ }),
/***/ 3958: /***/ 2362:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
var iterate = __nccwpck_require__(5748) var iterate = __nccwpck_require__(5748)
@ -93710,7 +93710,7 @@ const external_node_path_namespaceObject = __WEBPACK_EXTERNAL_createRequire(impo
const external_node_stream_promises_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:stream/promises"); const external_node_stream_promises_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:stream/promises");
;// CONCATENATED MODULE: external "node:zlib" ;// CONCATENATED MODULE: external "node:zlib"
const external_node_zlib_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("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@ed02129aed8e4d6402d920152652877189bece70_3whmnlhrx56zhgtsjnkrhnutfu/node_modules/detsys-ts/dist/index.js ;// CONCATENATED MODULE: ./node_modules/.pnpm/github.com+DeterminateSystems+detsys-ts@1c510e3aff595c88769d3706895ecebbc625ff2c_5f3ck3sx4ossruvxt6hpzqrwhy/node_modules/detsys-ts/dist/index.js
var __defProp = Object.defineProperty; var __defProp = Object.defineProperty;
var __export = (target, all) => { var __export = (target, all) => {
for (var name in all) for (var name in all)
@ -94018,6 +94018,7 @@ function hashEnvironmentVariables(prefix, variables) {
var inputs_exports = {}; var inputs_exports = {};
__export(inputs_exports, { __export(inputs_exports, {
getArrayOfStrings: () => getArrayOfStrings, getArrayOfStrings: () => getArrayOfStrings,
getArrayOfStringsOrNull: () => getArrayOfStringsOrNull,
getBool: () => getBool, getBool: () => getBool,
getMultilineStringOrNull: () => getMultilineStringOrNull, getMultilineStringOrNull: () => getMultilineStringOrNull,
getNumberOrNull: () => getNumberOrNull, getNumberOrNull: () => getNumberOrNull,
@ -94034,6 +94035,14 @@ var getArrayOfStrings = (name, separator) => {
const original = getString(name); const original = getString(name);
return handleString(original, separator); return handleString(original, separator);
}; };
var getArrayOfStringsOrNull = (name, separator) => {
const original = getStringOrNull(name);
if (original === null) {
return null;
} else {
return handleString(original, separator);
}
};
var handleString = (input, separator) => { var handleString = (input, separator) => {
const sepChar = separator === "comma" ? "," : /\s+/; const sepChar = separator === "comma" ? "," : /\s+/;
const trimmed = input.trim(); const trimmed = input.trim();
@ -94172,6 +94181,7 @@ var EVENT_ARTIFACT_CACHE_HIT = "artifact_cache_hit";
var EVENT_ARTIFACT_CACHE_MISS = "artifact_cache_miss"; var EVENT_ARTIFACT_CACHE_MISS = "artifact_cache_miss";
var EVENT_ARTIFACT_CACHE_PERSIST = "artifact_cache_persist"; var EVENT_ARTIFACT_CACHE_PERSIST = "artifact_cache_persist";
var EVENT_PREFLIGHT_REQUIRE_NIX_DENIED = "preflight-require-nix-denied"; var EVENT_PREFLIGHT_REQUIRE_NIX_DENIED = "preflight-require-nix-denied";
var FACT_ARTIFACT_FETCHED_FROM_CACHE = "artifact_fetched_from_cache";
var FACT_ENDED_WITH_EXCEPTION = "ended_with_exception"; var FACT_ENDED_WITH_EXCEPTION = "ended_with_exception";
var FACT_FINAL_EXCEPTION = "final_exception"; var FACT_FINAL_EXCEPTION = "final_exception";
var FACT_OS = "$os"; var FACT_OS = "$os";
@ -94284,16 +94294,6 @@ var DetSysAction = class {
stapleFile(name, location) { stapleFile(name, location) {
this.exceptionAttachments.set(name, location); this.exceptionAttachments.set(name, location);
} }
setExecutionPhase() {
const phase = core.getState(STATE_KEY_EXECUTION_PHASE);
if (phase === "") {
core.saveState(STATE_KEY_EXECUTION_PHASE, "post");
this.executionPhase = "main";
} else {
this.executionPhase = "post";
}
this.facts.execution_phase = this.executionPhase;
}
/** /**
* Execute the Action as defined. * Execute the Action as defined.
*/ */
@ -94303,7 +94303,55 @@ var DetSysAction = class {
process.exitCode = 1; process.exitCode = 1;
}); });
} }
// Whether the getTemporaryName() {
const tmpDir = process.env["RUNNER_TEMP"] || (0,external_node_os_.tmpdir)();
return external_node_path_namespaceObject.join(tmpDir, `${this.actionOptions.name}-${(0,external_node_crypto_namespaceObject.randomUUID)()}`);
}
addFact(key, value) {
this.facts[key] = value;
}
getDiagnosticsUrl() {
return this.actionOptions.diagnosticsUrl;
}
getUniqueId() {
return this.identity.run_differentiator || process.env.RUNNER_TRACKING_ID || (0,external_node_crypto_namespaceObject.randomUUID)();
}
getCorrelationHashes() {
return this.identity;
}
recordEvent(eventName, context = {}) {
this.events.push({
event_name: `${this.actionOptions.eventPrefix}${eventName}`,
context,
correlation: this.identity,
facts: this.facts,
timestamp: /* @__PURE__ */ new Date(),
uuid: (0,external_node_crypto_namespaceObject.randomUUID)()
});
}
/**
* Unpacks the closure returned by `fetchArtifact()`, imports the
* contents into the Nix store, and returns the path of the executable at
* `/nix/store/STORE_PATH/bin/${bin}`.
*/
async unpackClosure(bin) {
const artifact = await this.fetchArtifact();
const { stdout } = await (0,external_node_util_.promisify)(external_node_child_process_namespaceObject.exec)(
`cat "${artifact}" | xz -d | nix-store --import`
);
const paths = stdout.split(external_node_os_.EOL);
const lastPath = paths.at(-2);
return `${lastPath}/bin/${bin}`;
}
/**
* Fetches the executable at the URL determined by the `source-*` inputs and
* other facts, `chmod`s it, and returns the path to the executable on disk.
*/
async fetchExecutable() {
const binaryPath = await this.fetchArtifact();
await (0,promises_namespaceObject.chmod)(binaryPath, promises_namespaceObject.constants.S_IXUSR | promises_namespaceObject.constants.S_IXGRP);
return binaryPath;
}
get isMain() { get isMain() {
return this.executionPhase === "main"; return this.executionPhase === "main";
} }
@ -94359,52 +94407,25 @@ var DetSysAction = class {
await this.complete(); await this.complete();
} }
} }
addFact(key, value) {
this.facts[key] = value;
}
getDiagnosticsUrl() {
return this.actionOptions.diagnosticsUrl;
}
getUniqueId() {
return this.identity.run_differentiator || process.env.RUNNER_TRACKING_ID || (0,external_node_crypto_namespaceObject.randomUUID)();
}
getCorrelationHashes() {
return this.identity;
}
recordEvent(eventName, context = {}) {
this.events.push({
event_name: `${this.actionOptions.eventPrefix}${eventName}`,
context,
correlation: this.identity,
facts: this.facts,
timestamp: /* @__PURE__ */ new Date(),
uuid: (0,external_node_crypto_namespaceObject.randomUUID)()
});
}
/** /**
* Fetches a file in `.xz` format, imports its contents into the Nix store, * Fetch an artifact, such as a tarball, from the location determined by the
* and returns the path of the executable at `/nix/store/STORE_PATH/bin/${bin}`. * `source-*` inputs. If `source-binary` is specified, this will return a path
*/ * to a binary on disk; otherwise, the artifact will be downloaded from the
async unpackClosure(bin) { * URL determined by the other `source-*` inputs (`source-url`, `source-pr`,
const artifact = this.fetchArtifact(); * etc.).
const { stdout } = await (0,external_node_util_.promisify)(external_node_child_process_namespaceObject.exec)(
`cat "${artifact}" | xz -d | nix-store --import`
);
const paths = stdout.split(external_node_os_.EOL);
const lastPath = paths.at(-2);
return `${lastPath}/bin/${bin}`;
}
/**
* Fetch an artifact, such as a tarball, from the URL determined by the `source-*`
* inputs and other factors.
*/ */
async fetchArtifact() { async fetchArtifact() {
const sourceBinary = getStringOrNull("source-binary");
if (sourceBinary !== null && sourceBinary !== "") {
core.debug(`Using the provided source binary at ${sourceBinary}`);
return sourceBinary;
}
core.startGroup( core.startGroup(
`Downloading ${this.actionOptions.name} for ${this.architectureFetchSuffix}` `Downloading ${this.actionOptions.name} for ${this.architectureFetchSuffix}`
); );
try { try {
core.info(`Fetching from ${this.getUrl()}`); core.info(`Fetching from ${this.getSourceUrl()}`);
const correlatedUrl = this.getUrl(); const correlatedUrl = this.getSourceUrl();
correlatedUrl.searchParams.set("ci", "github"); correlatedUrl.searchParams.set("ci", "github");
correlatedUrl.searchParams.set( correlatedUrl.searchParams.set(
"correlation", "correlation",
@ -94415,16 +94436,16 @@ var DetSysAction = class {
const v = versionCheckup.headers.etag; const v = versionCheckup.headers.etag;
this.addFact(FACT_SOURCE_URL_ETAG, v); this.addFact(FACT_SOURCE_URL_ETAG, v);
core.debug( core.debug(
`Checking the tool cache for ${this.getUrl()} at ${v}` `Checking the tool cache for ${this.getSourceUrl()} at ${v}`
); );
const cached = await this.getCachedVersion(v); const cached = await this.getCachedVersion(v);
if (cached) { if (cached) {
this.facts["artifact_fetched_from_cache"] = true; this.facts[FACT_ARTIFACT_FETCHED_FROM_CACHE] = true;
core.debug(`Tool cache hit.`); core.debug(`Tool cache hit.`);
return cached; return cached;
} }
} }
this.facts["artifact_fetched_from_cache"] = false; this.facts[FACT_ARTIFACT_FETCHED_FROM_CACHE] = false;
core.debug( core.debug(
`No match from the cache, re-fetching from the redirect: ${versionCheckup.url}` `No match from the cache, re-fetching from the redirect: ${versionCheckup.url}`
); );
@ -94450,15 +94471,6 @@ var DetSysAction = class {
core.endGroup(); core.endGroup();
} }
} }
/**
* Fetches the executable at the URL determined by the `source-*` inputs and
* other facts, `chmod`s it, and returns the path to the executable on disk.
*/
async fetchExecutable() {
const binaryPath = await this.fetchArtifact();
await (0,promises_namespaceObject.chmod)(binaryPath, promises_namespaceObject.constants.S_IXUSR | promises_namespaceObject.constants.S_IXGRP);
return binaryPath;
}
/** /**
* A helper function for failing on error only if strict mode is enabled. * A helper function for failing on error only if strict mode is enabled.
* This is intended only for CI environments testing Actions themselves. * This is intended only for CI environments testing Actions themselves.
@ -94472,7 +94484,7 @@ var DetSysAction = class {
this.recordEvent(`complete_${this.executionPhase}`); this.recordEvent(`complete_${this.executionPhase}`);
await this.submitEvents(); await this.submitEvents();
} }
getUrl() { getSourceUrl() {
const p = this.sourceParameters; const p = this.sourceParameters;
if (p.url) { if (p.url) {
this.addFact(FACT_SOURCE_URL, p.url); this.addFact(FACT_SOURCE_URL, p.url);
@ -94657,10 +94669,6 @@ var DetSysAction = class {
} }
this.events = []; this.events = [];
} }
getTemporaryName() {
const _tmpdir = process.env["RUNNER_TEMP"] || (0,external_node_os_.tmpdir)();
return external_node_path_namespaceObject.join(_tmpdir, `${this.actionOptions.name}-${(0,external_node_crypto_namespaceObject.randomUUID)()}`);
}
}; };
function stringifyError(error2) { function stringifyError(error2) {
return error2 instanceof Error || typeof error2 == "string" ? error2.toString() : JSON.stringify(error2); return error2 instanceof Error || typeof error2 == "string" ? error2.toString() : JSON.stringify(error2);
@ -94754,17 +94762,6 @@ function mungeDiagnosticEndpoint(inputUrl) {
// EXTERNAL MODULE: external "fs" // EXTERNAL MODULE: external "fs"
var external_fs_ = __nccwpck_require__(7147); var external_fs_ = __nccwpck_require__(7147);
;// CONCATENATED MODULE: ./dist/index.js ;// CONCATENATED MODULE: ./dist/index.js
// src/inputs.ts
function determineFlakeDirectories(input) {
const sepChar = /\s+/;
const trimmed = input.trim();
if (trimmed === "") {
return [];
} else {
return trimmed.split(sepChar).map((s) => s.trim());
}
}
// src/nix.ts // src/nix.ts
function makeNixCommandArgs(nixOptions, flakeInputs, commitMessage) { function makeNixCommandArgs(nixOptions, flakeInputs, commitMessage) {
const flakeInputFlags = flakeInputs.flatMap((input) => [ const flakeInputFlags = flakeInputs.flatMap((input) => [
@ -94792,12 +94789,7 @@ var UpdateFlakeLockAction = class extends DetSysAction {
this.flakeInputs = inputs_exports.getArrayOfStrings("inputs", "space"); this.flakeInputs = inputs_exports.getArrayOfStrings("inputs", "space");
this.nixOptions = inputs_exports.getArrayOfStrings("nix-options", "space"); this.nixOptions = inputs_exports.getArrayOfStrings("nix-options", "space");
this.pathToFlakeDir = inputs_exports.getStringOrNull("path-to-flake-dir"); this.pathToFlakeDir = inputs_exports.getStringOrNull("path-to-flake-dir");
const flakeDirsInput = inputs_exports.getStringOrNull("flake-dirs"); this.flakeDirs = inputs_exports.getArrayOfStringsOrNull("flake-dirs", "space");
if (flakeDirsInput !== null) {
this.flakeDirs = determineFlakeDirectories(flakeDirsInput);
} else {
this.flakeDirs = null;
}
this.validateInputs(); this.validateInputs();
} }
async main() { async main() {

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -13,7 +13,7 @@ dependencies:
version: 1.1.1 version: 1.1.1
detsys-ts: detsys-ts:
specifier: github:DeterminateSystems/detsys-ts specifier: github:DeterminateSystems/detsys-ts
version: github.com/DeterminateSystems/detsys-ts/ed02129aed8e4d6402d920152652877189bece70 version: github.com/DeterminateSystems/detsys-ts/1c510e3aff595c88769d3706895ecebbc625ff2c
devDependencies: devDependencies:
'@trivago/prettier-plugin-sort-imports': '@trivago/prettier-plugin-sort-imports':
@ -1518,7 +1518,7 @@ packages:
hasBin: true hasBin: true
dependencies: dependencies:
caniuse-lite: 1.0.30001621 caniuse-lite: 1.0.30001621
electron-to-chromium: 1.4.777 electron-to-chromium: 1.4.781
node-releases: 2.0.14 node-releases: 2.0.14
update-browserslist-db: 1.0.16(browserslist@4.23.0) update-browserslist-db: 1.0.16(browserslist@4.23.0)
dev: true dev: true
@ -1811,8 +1811,8 @@ packages:
resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==}
dev: true dev: true
/electron-to-chromium@1.4.777: /electron-to-chromium@1.4.781:
resolution: {integrity: sha512-n02NCwLJ3wexLfK/yQeqfywCblZqLcXphzmid5e8yVPdtEcida7li0A5WQKghHNG0FeOMCzeFOzEbtAh5riXFw==} resolution: {integrity: sha512-aBI40ltvcWJQDW+V803FY6HjXAfi5xCWzpa3vSM/NGg7GfKEvI7ftzW4Gb2XKTRO4WsxDG7YG8ykrr/pG9bkKQ==}
dev: true dev: true
/emoji-regex@8.0.0: /emoji-regex@8.0.0:
@ -2765,6 +2765,7 @@ packages:
/inflight@1.0.6: /inflight@1.0.6:
resolution: {integrity: sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==} resolution: {integrity: sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==}
deprecated: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
dependencies: dependencies:
once: 1.4.0 once: 1.4.0
wrappy: 1.0.2 wrappy: 1.0.2
@ -4455,8 +4456,8 @@ packages:
engines: {node: '>=12.20'} engines: {node: '>=12.20'}
dev: true dev: true
github.com/DeterminateSystems/detsys-ts/ed02129aed8e4d6402d920152652877189bece70: github.com/DeterminateSystems/detsys-ts/1c510e3aff595c88769d3706895ecebbc625ff2c:
resolution: {tarball: https://codeload.github.com/DeterminateSystems/detsys-ts/tar.gz/ed02129aed8e4d6402d920152652877189bece70} resolution: {tarball: https://codeload.github.com/DeterminateSystems/detsys-ts/tar.gz/1c510e3aff595c88769d3706895ecebbc625ff2c}
name: detsys-ts name: detsys-ts
version: 1.0.0 version: 1.0.0
dependencies: dependencies:

View file

@ -1,4 +1,3 @@
import { determineFlakeDirectories } from "./inputs.js";
import { makeNixCommandArgs } from "./nix.js"; import { makeNixCommandArgs } from "./nix.js";
import * as actionsCore from "@actions/core"; import * as actionsCore from "@actions/core";
import * as actionsExec from "@actions/exec"; import * as actionsExec from "@actions/exec";
@ -25,13 +24,7 @@ class UpdateFlakeLockAction extends DetSysAction {
this.flakeInputs = inputs.getArrayOfStrings("inputs", "space"); this.flakeInputs = inputs.getArrayOfStrings("inputs", "space");
this.nixOptions = inputs.getArrayOfStrings("nix-options", "space"); this.nixOptions = inputs.getArrayOfStrings("nix-options", "space");
this.pathToFlakeDir = inputs.getStringOrNull("path-to-flake-dir"); this.pathToFlakeDir = inputs.getStringOrNull("path-to-flake-dir");
this.flakeDirs = inputs.getArrayOfStringsOrNull("flake-dirs", "space");
const flakeDirsInput = inputs.getStringOrNull("flake-dirs");
if (flakeDirsInput !== null) {
this.flakeDirs = determineFlakeDirectories(flakeDirsInput);
} else {
this.flakeDirs = null;
}
this.validateInputs(); this.validateInputs();
} }

View file

@ -1,10 +0,0 @@
// Helper function for nullable input fields into an array of strings
export function determineFlakeDirectories(input: string): string[] {
const sepChar = /\s+/;
const trimmed = input.trim();
if (trimmed === "") {
return [];
} else {
return trimmed.split(sepChar).map((s: string) => s.trim());
}
}

View file

@ -1,4 +1,3 @@
import { determineFlakeDirectories } from "./inputs.js";
import { makeNixCommandArgs } from "./nix.js"; import { makeNixCommandArgs } from "./nix.js";
import { expect, test } from "vitest"; import { expect, test } from "vitest";
@ -73,23 +72,3 @@ test("Nix command arguments", () => {
expect(args).toStrictEqual(expected); expect(args).toStrictEqual(expected);
}); });
}); });
test("Flake directory parsing", () => {
type TestCase = {
input: string;
outputs: string[];
};
const testCases: TestCase[] = [
{ input: "", outputs: [] },
{ input: "one two three", outputs: ["one", "two", "three"] },
{
input: ` one two three `,
outputs: ["one", "two", "three"],
},
];
testCases.forEach(({ input, outputs }) => {
expect(determineFlakeDirectories(input)).toStrictEqual(outputs);
});
});