Skip to content

Commit

Permalink
Use the latest daemon during development
Browse files Browse the repository at this point in the history
  • Loading branch information
sandydoo committed Oct 24, 2023
1 parent b235119 commit 6fcc092
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 22 deletions.
41 changes: 30 additions & 11 deletions dist/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7755,6 +7755,19 @@ async function setup() {
if (cachixBin !== "") {
core.debug(`Using Cachix executable from input: ${cachixBin}`);
}
else if (useDaemon) {
// TODO: remove once stable and the daemon has been released
cachixBin = await execToVariable('nix', [
'build',
'--show-trace',
'--print-out-paths',
'--accept-flake-config',
'--extra-experimental-features',
'nix-command flakes',
'github:cachix/cachix/feature/daemon',
]).then((storePath) => `${storePath.trimEnd()}/bin/cachix`);
core.info(`Daemon mode is enabled. Using the latest Cachix executable from github:cachix/cachix/feature/daemon: ${cachixBin}`);
}
else {
// Find the Cachix executable in PATH
let resolvedCachixBin = which_1.default.sync('cachix', { nothrow: true });
Expand All @@ -7774,16 +7787,8 @@ async function setup() {
// Print the executable version.
// Also verifies that the binary exists and is executable.
core.startGroup('Cachix: checking version');
let stdout = '';
const options = {
listeners: {
stdout: (data) => {
stdout += data.toString();
},
},
};
await exec.exec(cachixBin, ['--version'], options);
let cachixVersion = semver_1.default.coerce(stdout.split(" ")[1]);
let cachixVersion = await execToVariable(cachixBin, ['--version'])
.then((res) => semver_1.default.coerce(res.split(" ")[1]));
core.endGroup();
// for managed signing key and private caches
if (authToken !== "") {
Expand All @@ -7809,6 +7814,7 @@ async function setup() {
if (signingKey !== "") {
core.exportVariable('CACHIX_SIGNING_KEY', signingKey);
}
// TODO: update the final release bounds
let daemonSupported = (cachixVersion) ? semver_1.default.gte(cachixVersion, '1.6.0') : false;
core.saveState('daemonSupported', daemonSupported);
if (useDaemon && !daemonSupported) {
Expand All @@ -7821,6 +7827,7 @@ async function setup() {
const daemon = (0, node_child_process_1.spawn)(cachixBin, [
'daemon', 'run',
'--socket', `${daemonDir}/daemon.sock`,
name,
], {
stdio: ['ignore', daemonLog.fd, daemonLog.fd],
detached: true,
Expand Down Expand Up @@ -7848,7 +7855,7 @@ async function setup() {
exec ${cachixBin} daemon push \
--socket ${daemonDir}/daemon.sock \
${name} $OUT_PATHS
$OUT_PATHS
`,
// Make the post-build-hook executable
{ mode: 0o755 });
Expand Down Expand Up @@ -7942,6 +7949,18 @@ async function upload() {
function pidFilePath(daemonDir) {
return path.join(daemonDir, 'daemon.pid');
}
// Exec a command and return the stdout as a string.
async function execToVariable(command, args) {
let res = '';
const options = {
listeners: {
stdout: (data) => {
res += data.toString();
},
},
};
return exec.exec(command, args, options).then(() => res);
}
// Get the paths to the user config files.
function getUserConfigFiles() {
const userConfigDirs = getUserConfigDirs();
Expand Down
47 changes: 36 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ async function setup() {

if (cachixBin !== "") {
core.debug(`Using Cachix executable from input: ${cachixBin}`);
} else if (useDaemon) {
// TODO: remove once stable and the daemon has been released
cachixBin = await execToVariable(
'nix',
[
'build',
'--show-trace',
'--print-out-paths',
'--accept-flake-config',
'--extra-experimental-features',
'nix-command flakes',
'github:cachix/cachix/feature/daemon',
],
).then((storePath) => `${storePath.trimEnd()}/bin/cachix`);
core.info(`Daemon mode is enabled. Using the latest Cachix executable from github:cachix/cachix/feature/daemon: ${cachixBin}`);
} else {
// Find the Cachix executable in PATH
let resolvedCachixBin = which.sync('cachix', { nothrow: true });
Expand All @@ -53,16 +68,9 @@ async function setup() {
// Print the executable version.
// Also verifies that the binary exists and is executable.
core.startGroup('Cachix: checking version')
let stdout = '';
const options = {
listeners: {
stdout: (data: Buffer) => {
stdout += data.toString();
},
},
};
await exec.exec(cachixBin, ['--version'], options);
let cachixVersion = semver.coerce(stdout.split(" ")[1]);
let cachixVersion =
await execToVariable(cachixBin, ['--version'])
.then((res) => semver.coerce(res.split(" ")[1]));
core.endGroup()

// for managed signing key and private caches
Expand Down Expand Up @@ -92,6 +100,7 @@ async function setup() {
core.exportVariable('CACHIX_SIGNING_KEY', signingKey);
}

// TODO: update the final release bounds
let daemonSupported = (cachixVersion) ? semver.gte(cachixVersion, '1.6.0') : false;
core.saveState('daemonSupported', daemonSupported);

Expand All @@ -109,6 +118,7 @@ async function setup() {
[
'daemon', 'run',
'--socket', `${daemonDir}/daemon.sock`,
name,
],
{
stdio: ['ignore', daemonLog.fd, daemonLog.fd],
Expand Down Expand Up @@ -140,7 +150,7 @@ async function setup() {
exec ${cachixBin} daemon push \
--socket ${daemonDir}/daemon.sock \
${name} $OUT_PATHS
$OUT_PATHS
`,
// Make the post-build-hook executable
{ mode: 0o755 }
Expand Down Expand Up @@ -252,6 +262,21 @@ function pidFilePath(daemonDir: string): string {
return path.join(daemonDir, 'daemon.pid');
}

// Exec a command and return the stdout as a string.
async function execToVariable(command: string, args: string[]): Promise<string> {
let res = '';

const options = {
listeners: {
stdout: (data: Buffer) => {
res += data.toString();
},
},
};

return exec.exec(command, args, options).then(() => res);
}

// Get the paths to the user config files.
function getUserConfigFiles(): string[] {
const userConfigDirs = getUserConfigDirs();
Expand Down

0 comments on commit 6fcc092

Please sign in to comment.