mirror of
https://github.com/DeterminateSystems/magic-nix-cache-action.git
synced 2024-12-27 01:30:35 +01:00
Preflight nix, or don't fail
This commit is contained in:
parent
5e58ce0108
commit
40128c21ab
4 changed files with 133 additions and 21 deletions
143
dist/index.js
generated
vendored
143
dist/index.js
generated
vendored
|
@ -94412,7 +94412,7 @@ const got = source_create(defaults);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;// CONCATENATED MODULE: ./node_modules/.pnpm/github.com+DeterminateSystems+detsys-ts@3a315cdffd83d4b229d4fb16548d22a3756baf28_lprtsns3vmnabnzqpk64lag6gi/node_modules/detsys-ts/dist/correlation.js
|
;// CONCATENATED MODULE: ./node_modules/.pnpm/github.com+DeterminateSystems+detsys-ts@d0549728861cc4c4797fddc2c931739ff5f7c819_aivncslwkd46yrth3vskk4g6rm/node_modules/detsys-ts/dist/correlation.js
|
||||||
|
|
||||||
|
|
||||||
function identify(projectName) {
|
function identify(projectName) {
|
||||||
|
@ -94494,10 +94494,17 @@ function hashEnvironmentVariables(prefix, variables) {
|
||||||
return `${prefix}-${hash.digest("hex")}`;
|
return `${prefix}-${hash.digest("hex")}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
;// CONCATENATED MODULE: ./node_modules/.pnpm/github.com+DeterminateSystems+detsys-ts@3a315cdffd83d4b229d4fb16548d22a3756baf28_lprtsns3vmnabnzqpk64lag6gi/node_modules/detsys-ts/dist/package.json
|
;// CONCATENATED MODULE: ./node_modules/.pnpm/github.com+DeterminateSystems+detsys-ts@d0549728861cc4c4797fddc2c931739ff5f7c819_aivncslwkd46yrth3vskk4g6rm/node_modules/detsys-ts/dist/package.json
|
||||||
const package_namespaceObject = {"i8":"1.0.0"};
|
const package_namespaceObject = {"i8":"1.0.0"};
|
||||||
;// CONCATENATED MODULE: ./node_modules/.pnpm/github.com+DeterminateSystems+detsys-ts@3a315cdffd83d4b229d4fb16548d22a3756baf28_lprtsns3vmnabnzqpk64lag6gi/node_modules/detsys-ts/dist/platform.js
|
;// CONCATENATED MODULE: ./node_modules/.pnpm/github.com+DeterminateSystems+detsys-ts@d0549728861cc4c4797fddc2c931739ff5f7c819_aivncslwkd46yrth3vskk4g6rm/node_modules/detsys-ts/dist/platform.js
|
||||||
|
/**
|
||||||
|
* @packageDocumentation
|
||||||
|
* Helpers for determining system attributes of the current runner.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current architecture plus OS. Examples include `X64-Linux` and `ARM64-macOS`.
|
||||||
|
*/
|
||||||
function getArchOs() {
|
function getArchOs() {
|
||||||
const envArch = process.env.RUNNER_ARCH;
|
const envArch = process.env.RUNNER_ARCH;
|
||||||
const envOs = process.env.RUNNER_OS;
|
const envOs = process.env.RUNNER_OS;
|
||||||
|
@ -94509,6 +94516,9 @@ function getArchOs() {
|
||||||
throw new Error("RUNNER_ARCH and/or RUNNER_OS is not defined");
|
throw new Error("RUNNER_ARCH and/or RUNNER_OS is not defined");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Get the current Nix system. Examples include `x86_64-linux` and `aarch64-darwin`.
|
||||||
|
*/
|
||||||
function getNixPlatform(archOs) {
|
function getNixPlatform(archOs) {
|
||||||
const archOsMap = new Map([
|
const archOsMap = new Map([
|
||||||
["X64-macOS", "x86_64-darwin"],
|
["X64-macOS", "x86_64-darwin"],
|
||||||
|
@ -94526,17 +94536,86 @@ function getNixPlatform(archOs) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
;// CONCATENATED MODULE: ./node_modules/.pnpm/github.com+DeterminateSystems+detsys-ts@3a315cdffd83d4b229d4fb16548d22a3756baf28_lprtsns3vmnabnzqpk64lag6gi/node_modules/detsys-ts/dist/sourcedef.js
|
;// CONCATENATED MODULE: ./node_modules/.pnpm/github.com+DeterminateSystems+detsys-ts@d0549728861cc4c4797fddc2c931739ff5f7c819_aivncslwkd46yrth3vskk4g6rm/node_modules/detsys-ts/dist/inputs.js
|
||||||
|
/**
|
||||||
|
* @packageDocumentation
|
||||||
|
* Helpers for getting values from an Action's configuration.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a Boolean input from the Action's configuration by name.
|
||||||
|
*/
|
||||||
|
const getBool = (name) => {
|
||||||
|
return actionsCore.getBooleanInput(name);
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Get a multi-line string input from the Action's configuration by name or return `null` if not set.
|
||||||
|
*/
|
||||||
|
const getMultilineStringOrNull = (name) => {
|
||||||
|
const value = actionsCore.getMultilineInput(name);
|
||||||
|
if (value.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Get a number input from the Action's configuration by name or return `null` if not set.
|
||||||
|
*/
|
||||||
|
const getNumberOrNull = (name) => {
|
||||||
|
const value = actionsCore.getInput(name);
|
||||||
|
if (value === "") {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return Number(value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Get a string input from the Action's configuration.
|
||||||
|
*/
|
||||||
|
const getString = (name) => {
|
||||||
|
return actionsCore.getInput(name);
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Get a string input from the Action's configuration by name or return `null` if not set.
|
||||||
|
*/
|
||||||
|
const getStringOrNull = (name) => {
|
||||||
|
const value = actionsCore.getInput(name);
|
||||||
|
if (value === "") {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Get a string input from the Action's configuration by name or return `undefined` if not set.
|
||||||
|
*/
|
||||||
|
const getStringOrUndefined = (name) => {
|
||||||
|
const value = core.getInput(name);
|
||||||
|
if (value === "") {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
;// CONCATENATED MODULE: ./node_modules/.pnpm/github.com+DeterminateSystems+detsys-ts@d0549728861cc4c4797fddc2c931739ff5f7c819_aivncslwkd46yrth3vskk4g6rm/node_modules/detsys-ts/dist/sourcedef.js
|
||||||
|
|
||||||
|
|
||||||
function constructSourceParameters(legacyPrefix) {
|
function constructSourceParameters(legacyPrefix) {
|
||||||
const noisilyGetInput = (suffix) => {
|
const noisilyGetInput = (suffix) => {
|
||||||
const preferredInput = inputStringOrUndef(`source-${suffix}`);
|
const preferredInput = getStringOrUndefined(`source-${suffix}`);
|
||||||
if (!legacyPrefix) {
|
if (!legacyPrefix) {
|
||||||
return preferredInput;
|
return preferredInput;
|
||||||
}
|
}
|
||||||
// Remaining is for handling cases where the legacy prefix
|
// Remaining is for handling cases where the legacy prefix
|
||||||
// should be examined.
|
// should be examined.
|
||||||
const legacyInput = inputStringOrUndef(`${legacyPrefix}-${suffix}`);
|
const legacyInput = getStringOrUndefined(`${legacyPrefix}-${suffix}`);
|
||||||
if (preferredInput && legacyInput) {
|
if (preferredInput && legacyInput) {
|
||||||
core.warning(`The supported option source-${suffix} and the legacy option ${legacyPrefix}-${suffix} are both set. Preferring source-${suffix}. Please stop setting ${legacyPrefix}-${suffix}.`);
|
core.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;
|
return preferredInput;
|
||||||
|
@ -94558,15 +94637,6 @@ function constructSourceParameters(legacyPrefix) {
|
||||||
revision: noisilyGetInput("revision"),
|
revision: noisilyGetInput("revision"),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
function inputStringOrUndef(name) {
|
|
||||||
const value = core.getInput(name);
|
|
||||||
if (value === "") {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// EXTERNAL MODULE: ./node_modules/.pnpm/@actions+cache@3.2.4/node_modules/@actions/cache/lib/cache.js
|
// EXTERNAL MODULE: ./node_modules/.pnpm/@actions+cache@3.2.4/node_modules/@actions/cache/lib/cache.js
|
||||||
var cache = __nccwpck_require__(6878);
|
var cache = __nccwpck_require__(6878);
|
||||||
|
@ -94586,7 +94656,11 @@ const validate = uuid_dist/* validate */.Gu;
|
||||||
const stringify = uuid_dist/* stringify */.Pz;
|
const stringify = uuid_dist/* stringify */.Pz;
|
||||||
const parse = uuid_dist/* parse */.Qc;
|
const parse = uuid_dist/* parse */.Qc;
|
||||||
|
|
||||||
;// CONCATENATED MODULE: ./node_modules/.pnpm/github.com+DeterminateSystems+detsys-ts@3a315cdffd83d4b229d4fb16548d22a3756baf28_lprtsns3vmnabnzqpk64lag6gi/node_modules/detsys-ts/dist/main.js
|
;// CONCATENATED MODULE: ./node_modules/.pnpm/github.com+DeterminateSystems+detsys-ts@d0549728861cc4c4797fddc2c931739ff5f7c819_aivncslwkd46yrth3vskk4g6rm/node_modules/detsys-ts/dist/main.js
|
||||||
|
/**
|
||||||
|
* @packageDocumentation
|
||||||
|
* Determinate Systems' TypeScript library for creating GitHub Actions logic.
|
||||||
|
*/
|
||||||
|
|
||||||
// eslint-disable-next-line import/extensions
|
// eslint-disable-next-line import/extensions
|
||||||
|
|
||||||
|
@ -94695,6 +94769,10 @@ class IdsToolbox {
|
||||||
async executeAsync() {
|
async executeAsync() {
|
||||||
try {
|
try {
|
||||||
process.env.DETSYS_CORRELATION = JSON.stringify(this.getCorrelationHashes());
|
process.env.DETSYS_CORRELATION = JSON.stringify(this.getCorrelationHashes());
|
||||||
|
if (!(await this.preflightRequireNix())) {
|
||||||
|
this.recordEvent("preflight-require-nix-denied");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (this.executionPhase === "main" && this.hookMain) {
|
if (this.executionPhase === "main" && this.hookMain) {
|
||||||
await this.hookMain();
|
await this.hookMain();
|
||||||
}
|
}
|
||||||
|
@ -94858,6 +94936,34 @@ class IdsToolbox {
|
||||||
process.chdir(startCwd);
|
process.chdir(startCwd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
async preflightRequireNix() {
|
||||||
|
let nixLocation;
|
||||||
|
const pathParts = (process.env["PATH"] || "").split(":");
|
||||||
|
for (const location of pathParts) {
|
||||||
|
const candidateNix = external_node_path_namespaceObject.join(location, "nix");
|
||||||
|
try {
|
||||||
|
await promises_namespaceObject.access(candidateNix, promises_namespaceObject.constants.X_OK);
|
||||||
|
core.debug(`Found Nix at ${candidateNix}`);
|
||||||
|
nixLocation = candidateNix;
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
core.debug(`Nix not at ${candidateNix}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.addFact("nix_location", nixLocation || "");
|
||||||
|
const currentNotFoundState = core.getState("idstoolbox_nix_not_found");
|
||||||
|
if (this.actionOptions.requireNix && currentNotFoundState === "not-found") {
|
||||||
|
// It was previously not found, so don't run subsequent actions
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this.actionOptions.requireNix && nixLocation === undefined) {
|
||||||
|
core.warning("This action is in no-op mode because Nix is not installed." +
|
||||||
|
" Add `- uses: DeterminateSystems/nix-installer-action@main` earlier in your workflow.");
|
||||||
|
core.saveState("idstoolbox_nix_not_found", "not-found");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
async submitEvents() {
|
async submitEvents() {
|
||||||
if (!this.actionOptions.diagnosticsUrl) {
|
if (!this.actionOptions.diagnosticsUrl) {
|
||||||
core.debug("Diagnostics are disabled. Not sending the following events:");
|
core.debug("Diagnostics are disabled. Not sending the following events:");
|
||||||
|
@ -94892,6 +94998,7 @@ function makeOptionsConfident(actionOptions) {
|
||||||
eventPrefix: actionOptions.eventPrefix || "action:",
|
eventPrefix: actionOptions.eventPrefix || "action:",
|
||||||
fetchStyle: actionOptions.fetchStyle,
|
fetchStyle: actionOptions.fetchStyle,
|
||||||
legacySourcePrefix: actionOptions.legacySourcePrefix,
|
legacySourcePrefix: actionOptions.legacySourcePrefix,
|
||||||
|
requireNix: actionOptions.requireNix,
|
||||||
diagnosticsUrl: determineDiagnosticsUrl(idsProjectName, actionOptions.diagnosticsUrl),
|
diagnosticsUrl: determineDiagnosticsUrl(idsProjectName, actionOptions.diagnosticsUrl),
|
||||||
};
|
};
|
||||||
core.debug("idslib options:");
|
core.debug("idslib options:");
|
||||||
|
@ -94957,6 +95064,9 @@ function mungeDiagnosticEndpoint(inputUrl) {
|
||||||
}
|
}
|
||||||
return inputUrl;
|
return inputUrl;
|
||||||
}
|
}
|
||||||
|
// Public exports from other files
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;// CONCATENATED MODULE: ./dist/index.js
|
;// CONCATENATED MODULE: ./dist/index.js
|
||||||
|
|
||||||
|
@ -95220,6 +95330,7 @@ const idslib = new IdsToolbox({
|
||||||
name: "magic-nix-cache",
|
name: "magic-nix-cache",
|
||||||
fetchStyle: "gh-env-style",
|
fetchStyle: "gh-env-style",
|
||||||
idsProjectName: "magic-nix-cache-closure",
|
idsProjectName: "magic-nix-cache-closure",
|
||||||
|
requireNix: true,
|
||||||
});
|
});
|
||||||
idslib.onMain(async () => {
|
idslib.onMain(async () => {
|
||||||
await setUpAutoCache(idslib);
|
await setUpAutoCache(idslib);
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
"@actions/exec": "^1.1.1",
|
"@actions/exec": "^1.1.1",
|
||||||
"@actions/github": "^5.1.1",
|
"@actions/github": "^5.1.1",
|
||||||
"@actions/tool-cache": "^2.0.1",
|
"@actions/tool-cache": "^2.0.1",
|
||||||
"detsys-ts": "github:DeterminateSystems/detsys-ts",
|
"detsys-ts": "github:DeterminateSystems/detsys-ts#graham/fh-272-detsys-ts-create-a-helper-to-assert-nix-is-available-ahead",
|
||||||
"fetch-retry": "^5.0.6",
|
"fetch-retry": "^5.0.6",
|
||||||
"got": "^14.2.1",
|
"got": "^14.2.1",
|
||||||
"string-argv": "^0.3.2",
|
"string-argv": "^0.3.2",
|
||||||
|
|
|
@ -18,8 +18,8 @@ dependencies:
|
||||||
specifier: ^2.0.1
|
specifier: ^2.0.1
|
||||||
version: 2.0.1
|
version: 2.0.1
|
||||||
detsys-ts:
|
detsys-ts:
|
||||||
specifier: github:DeterminateSystems/detsys-ts
|
specifier: github:DeterminateSystems/detsys-ts#graham/fh-272-detsys-ts-create-a-helper-to-assert-nix-is-available-ahead
|
||||||
version: github.com/DeterminateSystems/detsys-ts/3a315cdffd83d4b229d4fb16548d22a3756baf28
|
version: github.com/DeterminateSystems/detsys-ts/d0549728861cc4c4797fddc2c931739ff5f7c819
|
||||||
fetch-retry:
|
fetch-retry:
|
||||||
specifier: ^5.0.6
|
specifier: ^5.0.6
|
||||||
version: 5.0.6
|
version: 5.0.6
|
||||||
|
@ -4353,10 +4353,10 @@ packages:
|
||||||
engines: { node: ">=10" }
|
engines: { node: ">=10" }
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
github.com/DeterminateSystems/detsys-ts/3a315cdffd83d4b229d4fb16548d22a3756baf28:
|
github.com/DeterminateSystems/detsys-ts/d0549728861cc4c4797fddc2c931739ff5f7c819:
|
||||||
resolution:
|
resolution:
|
||||||
{
|
{
|
||||||
tarball: https://codeload.github.com/DeterminateSystems/detsys-ts/tar.gz/3a315cdffd83d4b229d4fb16548d22a3756baf28,
|
tarball: https://codeload.github.com/DeterminateSystems/detsys-ts/tar.gz/d0549728861cc4c4797fddc2c931739ff5f7c819,
|
||||||
}
|
}
|
||||||
name: detsys-ts
|
name: detsys-ts
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
|
|
|
@ -305,6 +305,7 @@ const idslib = new IdsToolbox({
|
||||||
name: "magic-nix-cache",
|
name: "magic-nix-cache",
|
||||||
fetchStyle: "gh-env-style",
|
fetchStyle: "gh-env-style",
|
||||||
idsProjectName: "magic-nix-cache-closure",
|
idsProjectName: "magic-nix-cache-closure",
|
||||||
|
requireNix: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
idslib.onMain(async () => {
|
idslib.onMain(async () => {
|
||||||
|
|
Loading…
Reference in a new issue