From b1e40f81bd5a838dcc63f3aa13c3af07d87d3a9d Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Mon, 12 Feb 2024 14:13:43 -0800 Subject: [PATCH 1/3] Try logging into FlakeHub if nix-installer didn't do that for us --- bun.lockb | Bin 24784 -> 24794 bytes dist/index.js | 34 +++++++++++++++++++++++++++++++++- package.json | 6 +++--- src/index.ts | 45 +++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 79 insertions(+), 6 deletions(-) diff --git a/bun.lockb b/bun.lockb index f3e62912f3b30ea1b7d9c03a1c162e9e9830278f..8fa1e2d22992c0fc00fcbf8bdfc78d7feed3523a 100755 GIT binary patch delta 2328 zcmdT_`%~0a6u);_V81M{6&1cvIglZUv+lye;sd^pASjQJR0uN!a}f)WjYn!0oAl5T zQ#?7gIMt9^jh2Nw`AA2`(QGs^ZPaOT8fFKZMkz5Ho076V_q+R@Y5EV^AMW{n&gYzS z&pqevJ(o`L!Bc#@IdMnFr?a|^LyeoCc0O?Som={3=nvMHO2eo24Ue3OJ{WhRsJpDZ z!^0U1XUye>jD-9!fV&_gfG_I&{Fjgt@J8svAf1pV$ZE(K$P~Tbzciq~2Q2(G{d10W z?F_%8!HgN9_kkbJScmH@J`$kFfn&6AfSdqn5B1}?fPOukMZmVU)hk7yAcGpf)!Nq7 z)s6>B2e<&bRU@H!i1ZTmUAVq~vLPkLv0{Z(1hEEqb z7K;+NM!_P6s~E=@0fxz{n`E+q7h$eL3U>?D>SCo-AaR;O&nvo09e;zodW9b&IauL0 zsVZ0r?nk-i(D%W!_}}CO&O_h)xRa_v6h269tnuWR>-P(>OHV(f7Q4k2H# zooA63%zBayiljrw=7KQ@M#=}u2hyu(6OhG^^mgeqP%cmqC5GB19>Ul{KNn(`%7H3X zB)E@&<^zSQQSJa00tKsng=oCsbOP~h9k)A@;vi<%>yNQ5i0-?~NaLj}qr_d$6fqTgd>v(i^5qKl{LhQVUsv;E00K+=y zxX6w-kvBr&`$>*e_$XCHD$-PROH>3r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OBOn>I)dX``*$ni}ha_B(gENz?zJ`@@<2=9`%_ zXXe~9-=E{X=XkR%Vv@46C(_$AkDC|Yu1QYsH2q-u@xh_(?LA|vTed~*-#e!zE4#j( zGd6;;hGs}JXZ1Jloz1zK5}CXAurZUk_`%fkMazP)aS?8Yls>^ zZF(nvmAqgoNj56dU+B&}Fh;>hGtoR3kiUxRfnroN;O~@910@0ZQG~%MJqB9j;{u#g zS^#6YDiYiQpfn(Z8s%r8`9OLq3QaVkse;mpAbcyi0~P)id9hkaHYrl3(Pylq0q`G^ z+obSo1t$>cJWmrz$AcY?!*{twE$}=m{1awIhgR4Hp-`3s%6gvnEs7=Q z?q@f?TWH$&aYxX|gEt`hvu3KI*xi#wKRm-u{pI#oyc-ZxK_k`ZyXDPMsc;a6+ zm~=Tg)Z+i5XWg`3PKDD((H#2-Zl)r8sBfKOM(yj0(~Z0!HpUif zvok7mh4C_a%O&GW-sLLe7JBZIt=j8qk${G6;fvBvJXOX=C#AgDO01^MK0Rp zXj~*stlhuyD400kS=9XaP5L6$!Nch;a@EGsJ%9Gu#e2EOV4L`_ToSagv}VeS#qB$b zvvgdfiX@mehhqG8Y-lMj+5^v6AN9mQ74uhEwZS5-oz-(EyY&oS<#=0cf-R1f(Ea(# zUaCRY#J$r7)PYG2Q=_+(766P?o=`vobvDi~&AdlB3j-xALSBLKKQysV4 z#5G}TD2STV$62*ewdC%Ygr#+>{zOoRdW+aN>P}CQBJePYBb=lVY@r6V_Cg`%Q_j{R z^Xe{7<8UHKQ6%E9dcljS_Vt}d{eLvIT~{|%D>_J@XGBZCgBLO9(g0!}p{H2GX>{g7 z9z`Ws`{+cb%p>V?<`uaIpT3CoZesj5yw*H)bAkE-utYkspwTmXVWH#~V{>@gmQD}+ E2L?1Oi2wiq diff --git a/dist/index.js b/dist/index.js index 5831399..7dc58c1 100644 --- a/dist/index.js +++ b/dist/index.js @@ -12192,6 +12192,7 @@ async function setUpAutoCache() { const output = openSync(outputPath, 'a'); const log = tailLog(daemonDir); const notifyFd = 3; + const netrc = await netrcPath(); const daemon = spawn(daemonBin, [ '--notify-fd', String(notifyFd), '--listen', coreExports.getInput('listen'), @@ -12202,7 +12203,7 @@ async function setUpAutoCache() { '--use-flakehub', '--flakehub-cache-server', coreExports.getInput('flakehub-cache-server'), '--flakehub-api-server', coreExports.getInput('flakehub-api-server'), - '--flakehub-api-server-netrc', path$1.join(process.env['RUNNER_TEMP'], 'determinate-nix-installer-netrc'), + '--flakehub-api-server-netrc', netrc, ] : []).concat(coreExports.getInput('use-gha-cache') === 'true' ? [ '--use-gha-cache' ] : []), { @@ -12252,6 +12253,37 @@ async function notifyAutoCache() { coreExports.info(`Magic Nix Cache may not be running for this workflow.`); } } +async function netrcPath() { + const expectedNetrcPath = path$1.join(process.env['RUNNER_TEMP'], 'determinate-nix-installer-netrc'); + try { + await fs$2.access(expectedNetrcPath); + return expectedNetrcPath; + } + catch { + // `nix-installer` was not used, the user may be registered with FlakeHub though. + const destinedNetrcPath = path$1.join(process.env['RUNNER_TEMP'], 'magic-nix-cache-netrc'); + try { + await flakehub_login(destinedNetrcPath); + } + catch { + coreExports.info("FlakeHub cache disabled."); + } + return destinedNetrcPath; + } +} +async function flakehub_login(netrc) { + const jwt = await coreExports.getIDToken("api.flakehub.com"); + await fs$2.writeFile(netrc, [ + `machine api.flakehub.com login flakehub password ${jwt}`, + `machine flakehub.com login flakehub password ${jwt}`, + ].join("\n")); + coreExports.info("Logging in to FlakeHub."); + // the join followed by a match on ^... looks silly, but extra_config + // could contain multi-line values + if (this.extra_conf?.join("\n").match(/^netrc-file/m)) { + coreExports.warning("Logging in to FlakeHub conflicts with the Nix option `netrc-file`."); + } +} async function tearDownAutoCache() { const daemonDir = process.env[ENV_CACHE_DAEMONDIR]; if (!daemonDir) { diff --git a/package.json b/package.json index d0a0394..52f23d9 100644 --- a/package.json +++ b/package.json @@ -10,15 +10,15 @@ "license": "LGPL", "dependencies": { "@actions/core": "^1.10.0", + "got": "^12.6.0", "tail": "^2.2.6", - "tslib": "^2.5.2", - "got": "^12.6.0" + "tslib": "^2.5.2" }, "devDependencies": { "@rollup/plugin-commonjs": "^25.0.0", "@rollup/plugin-node-resolve": "^15.0.2", "@rollup/plugin-typescript": "^11.1.1", - "@types/node": "^20.2.1", + "@types/node": "^20.11.17", "rollup": "^3.22.0", "typescript": "^5.0.4" } diff --git a/src/index.ts b/src/index.ts index cf2790e..fcc366d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -123,6 +123,8 @@ async function setUpAutoCache() { const output = openSync(outputPath, 'a'); const log = tailLog(daemonDir); const notifyFd = 3; + const netrc = await netrcPath(); + const daemon = spawn( daemonBin, [ @@ -136,7 +138,7 @@ async function setUpAutoCache() { '--use-flakehub', '--flakehub-cache-server', core.getInput('flakehub-cache-server'), '--flakehub-api-server', core.getInput('flakehub-api-server'), - '--flakehub-api-server-netrc', path.join(process.env['RUNNER_TEMP'], 'determinate-nix-installer-netrc'), + '--flakehub-api-server-netrc', netrc, ] : []).concat( core.getInput('use-gha-cache') === 'true' ? [ '--use-gha-cache' @@ -196,6 +198,46 @@ async function notifyAutoCache() { } } + +async function netrcPath() { + const expectedNetrcPath = path.join(process.env['RUNNER_TEMP'], 'determinate-nix-installer-netrc') + try { + await fs.access(expectedNetrcPath) + return expectedNetrcPath; + } catch { + // `nix-installer` was not used, the user may be registered with FlakeHub though. + const destinedNetrcPath = path.join(process.env['RUNNER_TEMP'], 'magic-nix-cache-netrc') + try { + await flakehub_login(destinedNetrcPath); + } catch { + core.info("FlakeHub cache disabled.") + } + return destinedNetrcPath; + } +} + +async function flakehub_login(netrc: string) { + const jwt = await core.getIDToken("api.flakehub.com"); + + await fs.writeFile( + netrc, + [ + `machine api.flakehub.com login flakehub password ${jwt}`, + `machine flakehub.com login flakehub password ${jwt}`, + ].join("\n"), + ); + + core.info("Logging in to FlakeHub."); + + // the join followed by a match on ^... looks silly, but extra_config + // could contain multi-line values + if (this.extra_conf?.join("\n").match(/^netrc-file/m)) { + core.warning( + "Logging in to FlakeHub conflicts with the Nix option `netrc-file`.", + ); + } +} + async function tearDownAutoCache() { const daemonDir = process.env[ENV_CACHE_DAEMONDIR]; @@ -258,4 +300,3 @@ try { }} core.debug(`rip`); - From 232a98572bafd48290aca274780952cbd3da30b2 Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Tue, 13 Feb 2024 11:40:27 -0800 Subject: [PATCH 2/3] Improve logging --- dist/index.js | 5 +++-- src/index.ts | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/dist/index.js b/dist/index.js index 7dc58c1..8a0685e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -12265,8 +12265,9 @@ async function netrcPath() { try { await flakehub_login(destinedNetrcPath); } - catch { + catch (e) { coreExports.info("FlakeHub cache disabled."); + coreExports.debug(`Error while logging into FlakeHub: ${e}`); } return destinedNetrcPath; } @@ -12277,7 +12278,7 @@ async function flakehub_login(netrc) { `machine api.flakehub.com login flakehub password ${jwt}`, `machine flakehub.com login flakehub password ${jwt}`, ].join("\n")); - coreExports.info("Logging in to FlakeHub."); + coreExports.info("Logged in to FlakeHub."); // the join followed by a match on ^... looks silly, but extra_config // could contain multi-line values if (this.extra_conf?.join("\n").match(/^netrc-file/m)) { diff --git a/src/index.ts b/src/index.ts index fcc366d..a861078 100644 --- a/src/index.ts +++ b/src/index.ts @@ -209,8 +209,9 @@ async function netrcPath() { const destinedNetrcPath = path.join(process.env['RUNNER_TEMP'], 'magic-nix-cache-netrc') try { await flakehub_login(destinedNetrcPath); - } catch { - core.info("FlakeHub cache disabled.") + } catch (e) { + core.info("FlakeHub cache disabled."); + core.debug(`Error while logging into FlakeHub: ${e}`) } return destinedNetrcPath; } @@ -227,7 +228,7 @@ async function flakehub_login(netrc: string) { ].join("\n"), ); - core.info("Logging in to FlakeHub."); + core.info("Logged in to FlakeHub."); // the join followed by a match on ^... looks silly, but extra_config // could contain multi-line values From 04d5b7e8119d2b1a655f8a3b00346929a7ea033e Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Tue, 13 Feb 2024 11:45:21 -0800 Subject: [PATCH 3/3] Don't care about extra-conf --- dist/index.js | 5 ----- src/index.ts | 8 -------- 2 files changed, 13 deletions(-) diff --git a/dist/index.js b/dist/index.js index 8a0685e..62a3fac 100644 --- a/dist/index.js +++ b/dist/index.js @@ -12279,11 +12279,6 @@ async function flakehub_login(netrc) { `machine flakehub.com login flakehub password ${jwt}`, ].join("\n")); coreExports.info("Logged in to FlakeHub."); - // the join followed by a match on ^... looks silly, but extra_config - // could contain multi-line values - if (this.extra_conf?.join("\n").match(/^netrc-file/m)) { - coreExports.warning("Logging in to FlakeHub conflicts with the Nix option `netrc-file`."); - } } async function tearDownAutoCache() { const daemonDir = process.env[ENV_CACHE_DAEMONDIR]; diff --git a/src/index.ts b/src/index.ts index a861078..a2d84ea 100644 --- a/src/index.ts +++ b/src/index.ts @@ -229,14 +229,6 @@ async function flakehub_login(netrc: string) { ); core.info("Logged in to FlakeHub."); - - // the join followed by a match on ^... looks silly, but extra_config - // could contain multi-line values - if (this.extra_conf?.join("\n").match(/^netrc-file/m)) { - core.warning( - "Logging in to FlakeHub conflicts with the Nix option `netrc-file`.", - ); - } } async function tearDownAutoCache() {