From 7ec43f883b1f923ad06322a536a3d74bb9e2b151 Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Mon, 25 Mar 2024 17:42:40 -0300 Subject: [PATCH 1/3] Better Boolean handling and debug statement --- src/index.ts | 57 ++++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/src/index.ts b/src/index.ts index ee9e1b3..abc9634 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,7 @@ import * as fs from 'node:fs/promises'; import * as os from 'node:os'; import * as path from 'node:path'; -import { spawn, exec } from 'node:child_process'; +import { spawn, exec, SpawnOptions } from 'node:child_process'; import { openSync, readFileSync } from 'node:fs'; import { inspect, promisify } from 'node:util'; import * as http from 'http'; @@ -145,33 +145,38 @@ async function setUpAutoCache() { const output = openSync(outputPath, 'a'); const log = tailLog(daemonDir); const netrc = await netrcPath(); + const nixConfPath = `${process.env["HOME"]}/.config/nix/nix.conf`; + + const daemonCliFlags: string[] = [ + '--startup-notification-url', `http://127.0.0.1:${notifyPort}`, + '--listen', core.getInput('listen'), + '--upstream', core.getInput('upstream-cache'), + '--diagnostic-endpoint', core.getInput('diagnostic-endpoint'), + '--nix-conf', nixConfPath + ].concat( + core.getBooleanInput('use-flakehub') ? [ + '--use-flakehub', + '--flakehub-cache-server', core.getInput('flakehub-cache-server'), + '--flakehub-api-server', core.getInput('flakehub-api-server'), + '--flakehub-api-server-netrc', netrc, + '--flakehub-flake-name', core.getInput('flakehub-flake-name'), + ] : []).concat( + core.getBooleanInput('use-gha-cache') ? [ + '--use-gha-cache' + ] : []); + + const opts: SpawnOptions = { + stdio: ['ignore', output, output], + env: runEnv, + detached: true + }; + + // Display the final command for debugging purposes + core.debug("Full daemon start command:"); + core.debug(`${daemonBin} ${daemonCliFlags.join(" ")}`); // Start the server. Once it is ready, it will notify us via the notification server. - const daemon = spawn( - daemonBin, - [ - '--startup-notification-url', `http://127.0.0.1:${notifyPort}`, - '--listen', core.getInput('listen'), - '--upstream', core.getInput('upstream-cache'), - '--diagnostic-endpoint', core.getInput('diagnostic-endpoint'), - '--nix-conf', `${process.env["HOME"]}/.config/nix/nix.conf` - ].concat( - core.getInput('use-flakehub') === 'true' ? [ - '--use-flakehub', - '--flakehub-cache-server', core.getInput('flakehub-cache-server'), - '--flakehub-api-server', core.getInput('flakehub-api-server'), - '--flakehub-api-server-netrc', netrc, - '--flakehub-flake-name', core.getInput('flakehub-flake-name'), - ] : []).concat( - core.getInput('use-gha-cache') === 'true' ? [ - '--use-gha-cache' - ] : []), - { - stdio: ['ignore', output, output], - env: runEnv, - detached: true - } - ); + const daemon = spawn(daemonBin, daemonCliFlags, opts); const pidFile = path.join(daemonDir, 'daemon.pid'); await fs.writeFile(pidFile, `${daemon.pid}`); From c22d6efcb803f4652661bbf8b28cdad9f06b912f Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Mon, 25 Mar 2024 17:44:35 -0300 Subject: [PATCH 2/3] Regenerate index.js --- dist/index.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/dist/index.js b/dist/index.js index 20624a8..1630381 100644 --- a/dist/index.js +++ b/dist/index.js @@ -12211,26 +12211,32 @@ async function setUpAutoCache() { const output = openSync(outputPath, 'a'); const log = tailLog(daemonDir); const netrc = await netrcPath(); - // Start the server. Once it is ready, it will notify us via the notification server. - const daemon = spawn(daemonBin, [ + const nixConfPath = `${process.env["HOME"]}/.config/nix/nix.conf`; + const daemonCliFlags = [ '--startup-notification-url', `http://127.0.0.1:${notifyPort}`, '--listen', coreExports.getInput('listen'), '--upstream', coreExports.getInput('upstream-cache'), '--diagnostic-endpoint', coreExports.getInput('diagnostic-endpoint'), - '--nix-conf', `${process.env["HOME"]}/.config/nix/nix.conf` - ].concat(coreExports.getInput('use-flakehub') === 'true' ? [ + '--nix-conf', nixConfPath + ].concat(coreExports.getBooleanInput('use-flakehub') ? [ '--use-flakehub', '--flakehub-cache-server', coreExports.getInput('flakehub-cache-server'), '--flakehub-api-server', coreExports.getInput('flakehub-api-server'), '--flakehub-api-server-netrc', netrc, '--flakehub-flake-name', coreExports.getInput('flakehub-flake-name'), - ] : []).concat(coreExports.getInput('use-gha-cache') === 'true' ? [ + ] : []).concat(coreExports.getBooleanInput('use-gha-cache') ? [ '--use-gha-cache' - ] : []), { + ] : []); + const opts = { stdio: ['ignore', output, output], env: runEnv, detached: true - }); + }; + // Display the final command for debugging purposes + coreExports.debug("Full daemon start command:"); + coreExports.debug(`${daemonBin} ${daemonCliFlags.join(" ")}`); + // Start the server. Once it is ready, it will notify us via the notification server. + const daemon = spawn(daemonBin, daemonCliFlags, opts); const pidFile = path$1.join(daemonDir, 'daemon.pid'); await fs$2.writeFile(pidFile, `${daemon.pid}`); coreExports.info("Waiting for magic-nix-cache to start..."); From 995fe155b26ad3ece894e13c90c3fb9de5a1fcef Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Mon, 25 Mar 2024 17:54:54 -0300 Subject: [PATCH 3/3] Enable Actions debugging --- .github/workflows/ci.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9fdff01..eeb77b8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,6 +41,8 @@ jobs: permissions: id-token: "write" contents: "read" + env: + ACTIONS_STEP_DEBUG: true steps: - uses: actions/checkout@v3 - name: Install Nix @@ -61,6 +63,8 @@ jobs: permissions: id-token: "write" contents: "read" + env: + ACTIONS_STEP_DEBUG: true steps: - uses: actions/checkout@v3 - name: Install Nix @@ -82,6 +86,8 @@ jobs: permissions: id-token: "write" contents: "read" + env: + ACTIONS_STEP_DEBUG: true steps: - uses: actions/checkout@v3 - name: Install Nix