mirror of
https://github.com/DeterminateSystems/magic-nix-cache-action.git
synced 2024-12-23 05:22:07 +01:00
Merge pull request #48 from DeterminateSystems/double-action
Gracefully handle it if a user tries to register the action twice.
This commit is contained in:
commit
c9cb2a2a7f
5 changed files with 92 additions and 34 deletions
48
dist/index.js
generated
vendored
48
dist/index.js
generated
vendored
|
@ -57770,7 +57770,7 @@ module.exports = function () {
|
|||
|
||||
/***/ }),
|
||||
|
||||
/***/ 4791:
|
||||
/***/ 4736:
|
||||
/***/ ((module) => {
|
||||
|
||||
|
||||
|
@ -57985,7 +57985,7 @@ module.exports = {
|
|||
|
||||
|
||||
|
||||
const { maxNameValuePairSize, maxAttributeValueSize } = __nccwpck_require__(4791)
|
||||
const { maxNameValuePairSize, maxAttributeValueSize } = __nccwpck_require__(4736)
|
||||
const { isCTLExcludingHtab } = __nccwpck_require__(3319)
|
||||
const { collectASequenceOfCodePointsFast } = __nccwpck_require__(6932)
|
||||
const assert = __nccwpck_require__(9491)
|
||||
|
@ -93752,7 +93752,7 @@ const got = source_create(defaults);
|
|||
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@b2ff406239cb9d311fa9dad332ccfee2669ce6dc_o2lwkok3rvt3rnal2ayts63upe/node_modules/detsys-ts/dist/index.js
|
||||
;// CONCATENATED MODULE: ./node_modules/.pnpm/github.com+DeterminateSystems+detsys-ts@38e5bec8265276e0ffc60a474eeb0fe563690ad1_ohjjfxyz5zc5v7acp635bu77r4/node_modules/detsys-ts/dist/index.js
|
||||
var __defProp = Object.defineProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
|
@ -94117,7 +94117,11 @@ var getArrayOfStrings = (name, separator) => {
|
|||
};
|
||||
var handleString = (input, separator) => {
|
||||
const sepChar = separator === "comma" ? "," : /\s+/;
|
||||
return input.trim().split(sepChar).map((s) => s.trim());
|
||||
const trimmed = input.trim();
|
||||
if (trimmed === "") {
|
||||
return [];
|
||||
}
|
||||
return trimmed.split(sepChar).map((s) => s.trim());
|
||||
};
|
||||
var getMultilineStringOrNull = (name) => {
|
||||
const value = core.getMultilineInput(name);
|
||||
|
@ -94741,9 +94745,11 @@ async function flakeHubLogin(netrc) {
|
|||
|
||||
|
||||
|
||||
var ENV_CACHE_DAEMONDIR = "MAGIC_NIX_CACHE_DAEMONDIR";
|
||||
var ENV_CACHE_STARTED = "MAGIC_NIX_CACHE_STARTED";
|
||||
var ENV_DAEMON_DIR = "MAGIC_NIX_CACHE_DAEMONDIR";
|
||||
var STATE_DAEMONDIR = "MAGIC_NIX_CACHE_DAEMONDIR";
|
||||
var STATE_STARTED = "MAGIC_NIX_CACHE_STARTED";
|
||||
var STARTED_HINT = "true";
|
||||
var NOOP_TEXT = "Magic Nix Cache is already running, this workflow job is in noop mode. Is the Magic Nix Cache in the workflow twice?";
|
||||
var MagicNixCacheAction = class {
|
||||
constructor() {
|
||||
this.idslib = new IdsToolbox({
|
||||
|
@ -94767,14 +94773,21 @@ var MagicNixCacheAction = class {
|
|||
]
|
||||
}
|
||||
});
|
||||
this.daemonStarted = process.env[ENV_CACHE_STARTED] === STARTED_HINT;
|
||||
if (process.env[ENV_CACHE_DAEMONDIR]) {
|
||||
this.daemonDir = process.env[ENV_CACHE_DAEMONDIR];
|
||||
this.daemonStarted = core.getState(STATE_STARTED) === STARTED_HINT;
|
||||
if (core.getState(STATE_DAEMONDIR) !== "") {
|
||||
this.daemonDir = core.getState(STATE_DAEMONDIR);
|
||||
} else {
|
||||
this.daemonDir = this.idslib.getTemporaryName();
|
||||
(0,external_node_fs_namespaceObject.mkdirSync)(this.daemonDir);
|
||||
core.exportVariable(ENV_CACHE_DAEMONDIR, this.daemonDir);
|
||||
core.saveState(STATE_DAEMONDIR, this.daemonDir);
|
||||
}
|
||||
if (process.env[ENV_DAEMON_DIR] === void 0) {
|
||||
this.noopMode = false;
|
||||
core.exportVariable(ENV_DAEMON_DIR, this.daemonDir);
|
||||
} else {
|
||||
this.noopMode = process.env[ENV_DAEMON_DIR] !== this.daemonDir;
|
||||
}
|
||||
this.idslib.addFact("noop_mode", this.noopMode);
|
||||
this.idslib.stapleFile(
|
||||
"daemon.log",
|
||||
external_node_path_namespaceObject.join(this.daemonDir, "daemon.log")
|
||||
|
@ -94795,14 +94808,19 @@ var MagicNixCacheAction = class {
|
|||
);
|
||||
}
|
||||
}
|
||||
this.idslib.addFact("authenticated_env", !anyMissing);
|
||||
if (anyMissing) {
|
||||
return;
|
||||
}
|
||||
if (this.daemonStarted) {
|
||||
core.debug("Already started.");
|
||||
return;
|
||||
}
|
||||
core.debug(
|
||||
`GitHub Action Cache URL: ${process.env["ACTIONS_CACHE_URL"]}`
|
||||
);
|
||||
this.daemonStarted = true;
|
||||
core.exportVariable(ENV_CACHE_STARTED, STARTED_HINT);
|
||||
core.saveState(STATE_STARTED, STARTED_HINT);
|
||||
const sourceBinary = inputs_exports.getStringOrNull("source-binary");
|
||||
const daemonBin = sourceBinary !== null ? sourceBinary : await this.fetchAutoCacher();
|
||||
let runEnv;
|
||||
|
@ -94968,10 +94986,18 @@ var MagicNixCacheAction = class {
|
|||
function main() {
|
||||
const cacheAction = new MagicNixCacheAction();
|
||||
cacheAction.idslib.onMain(async () => {
|
||||
if (cacheAction.noopMode) {
|
||||
core.warning(NOOP_TEXT);
|
||||
return;
|
||||
}
|
||||
await cacheAction.setUpAutoCache();
|
||||
await cacheAction.notifyAutoCache();
|
||||
});
|
||||
cacheAction.idslib.onPost(async () => {
|
||||
if (cacheAction.noopMode) {
|
||||
core.debug(NOOP_TEXT);
|
||||
return;
|
||||
}
|
||||
await cacheAction.tearDownAutoCache();
|
||||
});
|
||||
cacheAction.idslib.execute();
|
||||
|
|
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
|
@ -27,13 +27,13 @@
|
|||
"dependencies": {
|
||||
"@actions/core": "^1.10.1",
|
||||
"@actions/exec": "^1.1.1",
|
||||
"detsys-ts": "github:DeterminateSystems/detsys-ts",
|
||||
"detsys-ts": "github:DeterminateSystems/detsys-ts#array-inputs",
|
||||
"got": "^14.2.1",
|
||||
"tail": "^2.2.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
|
||||
"@types/node": "^20.12.9",
|
||||
"@types/node": "^20.12.10",
|
||||
"@types/tail": "^2.2.3",
|
||||
"@types/uuid": "^9.0.8",
|
||||
"@typescript-eslint/eslint-plugin": "^7.8.0",
|
||||
|
|
|
@ -12,8 +12,8 @@ dependencies:
|
|||
specifier: ^1.1.1
|
||||
version: 1.1.1
|
||||
detsys-ts:
|
||||
specifier: github:DeterminateSystems/detsys-ts
|
||||
version: github.com/DeterminateSystems/detsys-ts/b2ff406239cb9d311fa9dad332ccfee2669ce6dc
|
||||
specifier: github:DeterminateSystems/detsys-ts#array-inputs
|
||||
version: github.com/DeterminateSystems/detsys-ts/38e5bec8265276e0ffc60a474eeb0fe563690ad1
|
||||
got:
|
||||
specifier: ^14.2.1
|
||||
version: 14.2.1
|
||||
|
@ -26,8 +26,8 @@ devDependencies:
|
|||
specifier: ^4.3.0
|
||||
version: 4.3.0(prettier@3.2.5)
|
||||
'@types/node':
|
||||
specifier: ^20.12.9
|
||||
version: 20.12.9
|
||||
specifier: ^20.12.10
|
||||
version: 20.12.10
|
||||
'@types/tail':
|
||||
specifier: ^2.2.3
|
||||
version: 2.2.3
|
||||
|
@ -896,12 +896,12 @@ packages:
|
|||
/@types/node-fetch@2.6.11:
|
||||
resolution: {integrity: sha512-24xFj9R5+rfQJLRyM56qh+wnVSYhyXC2tkoBndtY0U+vubqNsYXGjufB2nn8Q6gt0LrARwL6UBtMCSVCwl4B1g==}
|
||||
dependencies:
|
||||
'@types/node': 20.12.9
|
||||
'@types/node': 20.12.10
|
||||
form-data: 4.0.0
|
||||
dev: false
|
||||
|
||||
/@types/node@20.12.9:
|
||||
resolution: {integrity: sha512-o93r47yu04MHumPBCFg0bMPBMNgtMg3jzbhl7e68z50+BMHmRMGDJv13eBlUgOdc9i/uoJXGMGYLtJV4ReTXEg==}
|
||||
/@types/node@20.12.10:
|
||||
resolution: {integrity: sha512-Eem5pH9pmWBHoGAT8Dr5fdc5rYA+4NAovdM4EktRPVAAiJhmWWfQrA0cFhAbOsQdSfIHjAud6YdkbL69+zSKjw==}
|
||||
dependencies:
|
||||
undici-types: 5.26.5
|
||||
|
||||
|
@ -916,7 +916,7 @@ packages:
|
|||
/@types/tunnel@0.0.3:
|
||||
resolution: {integrity: sha512-sOUTGn6h1SfQ+gbgqC364jLFBw2lnFqkgF3q0WovEHRLMrVD1sd5aufqi/aJObLekJO+Aq5z646U4Oxy6shXMA==}
|
||||
dependencies:
|
||||
'@types/node': 20.12.9
|
||||
'@types/node': 20.12.10
|
||||
dev: false
|
||||
|
||||
/@types/uuid@9.0.8:
|
||||
|
@ -1275,7 +1275,7 @@ packages:
|
|||
hasBin: true
|
||||
dependencies:
|
||||
caniuse-lite: 1.0.30001616
|
||||
electron-to-chromium: 1.4.756
|
||||
electron-to-chromium: 1.4.757
|
||||
node-releases: 2.0.14
|
||||
update-browserslist-db: 1.0.15(browserslist@4.23.0)
|
||||
dev: true
|
||||
|
@ -1533,8 +1533,8 @@ packages:
|
|||
resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==}
|
||||
dev: true
|
||||
|
||||
/electron-to-chromium@1.4.756:
|
||||
resolution: {integrity: sha512-RJKZ9+vEBMeiPAvKNWyZjuYyUqMndcP1f335oHqn3BEQbs2NFtVrnK5+6Xg5wSM9TknNNpWghGDUCKGYF+xWXw==}
|
||||
/electron-to-chromium@1.4.757:
|
||||
resolution: {integrity: sha512-jftDaCknYSSt/+KKeXzH3LX5E2CvRLm75P3Hj+J/dv3CL0qUYcOt13d5FN1NiL5IJbbhzHrb3BomeG2tkSlZmw==}
|
||||
dev: true
|
||||
|
||||
/emoji-regex@8.0.0:
|
||||
|
@ -3831,8 +3831,8 @@ packages:
|
|||
engines: {node: '>=10'}
|
||||
dev: true
|
||||
|
||||
github.com/DeterminateSystems/detsys-ts/b2ff406239cb9d311fa9dad332ccfee2669ce6dc:
|
||||
resolution: {tarball: https://codeload.github.com/DeterminateSystems/detsys-ts/tar.gz/b2ff406239cb9d311fa9dad332ccfee2669ce6dc}
|
||||
github.com/DeterminateSystems/detsys-ts/38e5bec8265276e0ffc60a474eeb0fe563690ad1:
|
||||
resolution: {tarball: https://codeload.github.com/DeterminateSystems/detsys-ts/tar.gz/38e5bec8265276e0ffc60a474eeb0fe563690ad1}
|
||||
name: detsys-ts
|
||||
version: 1.0.0
|
||||
dependencies:
|
||||
|
|
46
src/index.ts
46
src/index.ts
|
@ -10,15 +10,23 @@ import * as os from "node:os";
|
|||
import * as path from "node:path";
|
||||
import { inspect, promisify } from "node:util";
|
||||
|
||||
const ENV_CACHE_DAEMONDIR = "MAGIC_NIX_CACHE_DAEMONDIR";
|
||||
const ENV_CACHE_STARTED = "MAGIC_NIX_CACHE_STARTED";
|
||||
// The ENV_DAEMON_DIR is intended to determine if we "own" the daemon or not,
|
||||
// in the case that a user has put the magic nix cache into their workflow
|
||||
// twice.
|
||||
const ENV_DAEMON_DIR = "MAGIC_NIX_CACHE_DAEMONDIR";
|
||||
|
||||
const STATE_DAEMONDIR = "MAGIC_NIX_CACHE_DAEMONDIR";
|
||||
const STATE_STARTED = "MAGIC_NIX_CACHE_STARTED";
|
||||
const STARTED_HINT = "true";
|
||||
|
||||
const NOOP_TEXT =
|
||||
"Magic Nix Cache is already running, this workflow job is in noop mode. Is the Magic Nix Cache in the workflow twice?";
|
||||
|
||||
class MagicNixCacheAction {
|
||||
idslib: IdsToolbox;
|
||||
private client: Got;
|
||||
|
||||
noopMode: boolean;
|
||||
private daemonDir: string;
|
||||
private daemonStarted: boolean;
|
||||
|
||||
|
@ -46,16 +54,24 @@ class MagicNixCacheAction {
|
|||
},
|
||||
});
|
||||
|
||||
this.daemonStarted = process.env[ENV_CACHE_STARTED] === STARTED_HINT;
|
||||
this.daemonStarted = actionsCore.getState(STATE_STARTED) === STARTED_HINT;
|
||||
|
||||
if (process.env[ENV_CACHE_DAEMONDIR]) {
|
||||
this.daemonDir = process.env[ENV_CACHE_DAEMONDIR];
|
||||
if (actionsCore.getState(STATE_DAEMONDIR) !== "") {
|
||||
this.daemonDir = actionsCore.getState(STATE_DAEMONDIR);
|
||||
} else {
|
||||
this.daemonDir = this.idslib.getTemporaryName();
|
||||
mkdirSync(this.daemonDir);
|
||||
actionsCore.exportVariable(ENV_CACHE_DAEMONDIR, this.daemonDir);
|
||||
actionsCore.saveState(STATE_DAEMONDIR, this.daemonDir);
|
||||
}
|
||||
|
||||
if (process.env[ENV_DAEMON_DIR] === undefined) {
|
||||
this.noopMode = false;
|
||||
actionsCore.exportVariable(ENV_DAEMON_DIR, this.daemonDir);
|
||||
} else {
|
||||
this.noopMode = process.env[ENV_DAEMON_DIR] !== this.daemonDir;
|
||||
}
|
||||
this.idslib.addFact("noop_mode", this.noopMode);
|
||||
|
||||
this.idslib.stapleFile(
|
||||
"daemon.log",
|
||||
path.join(this.daemonDir, "daemon.log"),
|
||||
|
@ -79,16 +95,22 @@ class MagicNixCacheAction {
|
|||
}
|
||||
}
|
||||
|
||||
this.idslib.addFact("authenticated_env", !anyMissing);
|
||||
if (anyMissing) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.daemonStarted) {
|
||||
actionsCore.debug("Already started.");
|
||||
return;
|
||||
}
|
||||
|
||||
actionsCore.debug(
|
||||
`GitHub Action Cache URL: ${process.env["ACTIONS_CACHE_URL"]}`,
|
||||
);
|
||||
|
||||
this.daemonStarted = true;
|
||||
actionsCore.exportVariable(ENV_CACHE_STARTED, STARTED_HINT);
|
||||
actionsCore.saveState(STATE_STARTED, STARTED_HINT);
|
||||
const sourceBinary = inputs.getStringOrNull("source-binary");
|
||||
const daemonBin =
|
||||
sourceBinary !== null ? sourceBinary : await this.fetchAutoCacher();
|
||||
|
@ -298,10 +320,20 @@ function main(): void {
|
|||
const cacheAction = new MagicNixCacheAction();
|
||||
|
||||
cacheAction.idslib.onMain(async () => {
|
||||
if (cacheAction.noopMode) {
|
||||
actionsCore.warning(NOOP_TEXT);
|
||||
return;
|
||||
}
|
||||
|
||||
await cacheAction.setUpAutoCache();
|
||||
await cacheAction.notifyAutoCache();
|
||||
});
|
||||
cacheAction.idslib.onPost(async () => {
|
||||
if (cacheAction.noopMode) {
|
||||
actionsCore.debug(NOOP_TEXT);
|
||||
return;
|
||||
}
|
||||
|
||||
await cacheAction.tearDownAutoCache();
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue