darwin: reliably wait for daemon connection

This commit is contained in:
Domen Kožar 2020-02-24 12:13:30 +01:00
parent 39c9ce7c86
commit 033d472283
No known key found for this signature in database
GPG key ID: C2FFBCAFD2C24246
2 changed files with 31 additions and 2 deletions

View file

@ -3,6 +3,8 @@ import * as exec from '@actions/exec';
import * as tc from '@actions/tool-cache';
import {execFileSync} from 'child_process';
import {type} from 'os';
import {exit} from 'process';
import {createConnection} from 'net';
async function nixConf() {
// 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');
// TODO: nc doesn't work correctly on macOS :(
await exec.exec("sleep", ["10"]);
await awaitSocket();
}
} catch (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();