darwin: reliably wait for daemon connection
This commit is contained in:
parent
39c9ce7c86
commit
033d472283
17
lib/main.js
17
lib/main.js
@ -21,6 +21,8 @@ const exec = __importStar(require("@actions/exec"));
|
|||||||
const tc = __importStar(require("@actions/tool-cache"));
|
const tc = __importStar(require("@actions/tool-cache"));
|
||||||
const child_process_1 = require("child_process");
|
const child_process_1 = require("child_process");
|
||||||
const os_1 = require("os");
|
const os_1 = require("os");
|
||||||
|
const process_1 = require("process");
|
||||||
|
const net_1 = require("net");
|
||||||
function nixConf() {
|
function nixConf() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
// Workaround a segfault: https://github.com/NixOS/nix/issues/2733
|
// Workaround a segfault: https://github.com/NixOS/nix/issues/2733
|
||||||
@ -56,7 +58,7 @@ function run() {
|
|||||||
// macOS needs certificates hints
|
// macOS needs certificates hints
|
||||||
core.exportVariable('NIX_SSL_CERT_FILE', '/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt');
|
core.exportVariable('NIX_SSL_CERT_FILE', '/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt');
|
||||||
// TODO: nc doesn't work correctly on macOS :(
|
// TODO: nc doesn't work correctly on macOS :(
|
||||||
yield exec.exec("sleep", ["10"]);
|
yield awaitSocket();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
@ -65,4 +67,17 @@ function run() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
function awaitSocket() {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const daemonSocket = net_1.createConnection({ path: '/nix/var/nix/daemon-socket/socket' });
|
||||||
|
daemonSocket.on('error', () => __awaiter(this, void 0, void 0, function* () {
|
||||||
|
console.log('Waiting for daemon socket to be available, reconnecting...');
|
||||||
|
yield new Promise(resolve => setTimeout(resolve, 500));
|
||||||
|
yield awaitSocket();
|
||||||
|
}));
|
||||||
|
daemonSocket.on('connect', () => {
|
||||||
|
process_1.exit(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
run();
|
run();
|
||||||
|
16
src/main.ts
16
src/main.ts
@ -3,6 +3,8 @@ import * as exec from '@actions/exec';
|
|||||||
import * as tc from '@actions/tool-cache';
|
import * as tc from '@actions/tool-cache';
|
||||||
import {execFileSync} from 'child_process';
|
import {execFileSync} from 'child_process';
|
||||||
import {type} from 'os';
|
import {type} from 'os';
|
||||||
|
import {exit} from 'process';
|
||||||
|
import {createConnection} from 'net';
|
||||||
|
|
||||||
async function nixConf() {
|
async function nixConf() {
|
||||||
// Workaround a segfault: https://github.com/NixOS/nix/issues/2733
|
// Workaround a segfault: https://github.com/NixOS/nix/issues/2733
|
||||||
@ -46,7 +48,7 @@ async function run() {
|
|||||||
core.exportVariable('NIX_SSL_CERT_FILE', '/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt');
|
core.exportVariable('NIX_SSL_CERT_FILE', '/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt');
|
||||||
|
|
||||||
// TODO: nc doesn't work correctly on macOS :(
|
// TODO: nc doesn't work correctly on macOS :(
|
||||||
await exec.exec("sleep", ["10"]);
|
await awaitSocket();
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(`Action failed with error: ${error}`);
|
core.setFailed(`Action failed with error: ${error}`);
|
||||||
@ -54,4 +56,16 @@ async function run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function awaitSocket() {
|
||||||
|
const daemonSocket = createConnection({ path: '/nix/var/nix/daemon-socket/socket' });
|
||||||
|
daemonSocket.on('error', async () => {
|
||||||
|
console.log('Waiting for daemon socket to be available, reconnecting...');
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 500));
|
||||||
|
await awaitSocket();
|
||||||
|
});
|
||||||
|
daemonSocket.on('connect', () => {
|
||||||
|
exit(0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
Loading…
Reference in New Issue
Block a user