Allow skipping nix-build

This commit is contained in:
Domen Kožar 2019-12-18 15:37:40 +01:00
commit 074294984a
No known key found for this signature in database
GPG key ID: C2FFBCAFD2C24246
4 changed files with 98 additions and 48 deletions

View file

@ -18,51 +18,68 @@ var __importStar = (this && this.__importStar) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const exec = __importStar(require("@actions/exec"));
const os_1 = require("os");
const strings_1 = require("./strings");
function home() {
if (os_1.type() == "Darwin") {
return "/Users/runner";
}
else {
return "/home/runner";
}
}
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
// inputs
const file = core.getInput('file');
const skipNixBuild = core.getInput('skipNixBuild');
const attributes = core.getInput('attributes');
const name = core.getInput('name', { required: true });
const signingKey = core.getInput('signingKey');
const authToken = core.getInput('authToken');
const cachixExecutable = "/nix/var/nix/profiles/per-user/runner/profile/bin/cachix";
core.startGroup('Installing Cachix');
// TODO: use cachix official installation link
yield exec.exec('nix-env', ['-iA', 'cachix', '-f', 'https://github.com/NixOS/nixpkgs/tarball/ab5863afada3c1b50fc43bf774b75ea71b287cde']);
yield exec.exec('nix-env', ['-iA', 'cachix', '-f', 'https://cachix.org/api/v1/install']);
core.endGroup();
// for private caches
if (authToken !== "") {
yield exec.exec('cachix', ['authtoken', authToken]);
yield exec.exec(cachixExecutable, ['authtoken', authToken]);
}
core.startGroup(`Cachix: using ` + name);
yield exec.exec('cachix', ['use', name]);
core.endGroup();
if (signingKey !== "") {
core.startGroup('Cachix: Configuring push');
yield exec.exec("sudo", ["sh", "-c", `echo export HOME=${home()} > /etc/nix/cachix-push.sh`]);
yield exec.exec("sudo", ["sh", "-c", `echo export CACHIX_SIGNING_KEY=${signingKey} >> /etc/nix/cachix-push.sh`]);
yield exec.exec("sudo", ["sh", "-c", `echo ${cachixExecutable} push ${name} \$OUT_PATHS >> /etc/nix/cachix-push.sh`]);
yield exec.exec("sudo", ["sh", "-c", `chmod +x /etc/nix/cachix-push.sh`]);
yield exec.exec("sudo", ["sh", "-c", `echo post-build-hook = /etc/nix/cachix-push.sh >> /etc/nix/nix.conf`]);
core.exportVariable('CACHIX_SIGNING_KEY', signingKey);
}
// TODO: cachix use --watch-store
core.startGroup(`Invoking nix-build`);
let paths = '';
const options = {
listeners: {
stdout: (data) => {
paths += data.toString();
},
// Reload nix-daemon
if (os_1.type() == "Darwin") {
// kickstart awaits nix-daemon to get up again
yield exec.exec("sudo", ["launchctl", "kickstart", "-k", "system/org.nixos.nix-daemon"]);
}
else {
yield exec.exec("sudo", ["pkill", "-HUP", "nix-daemon"]);
}
};
const args = strings_1.prependEach('-A', strings_1.nonEmptySplit(attributes, /\s+/)).concat([file || "default.nix"]);
yield exec.exec('nix-build', args, options);
core.endGroup();
// Needed for PRs
if (signingKey !== "") {
core.startGroup(`Cachix: pushing to ` + name);
yield exec.exec('cachix', ['push', name].concat(strings_1.nonEmptySplit(paths, /\s+/)));
core.endGroup();
}
else {
console.log("No signing key. Assuming it's a pull request, nothing will be pushed.");
if (skipNixBuild !== 'true') {
core.startGroup(`Invoking nix-build`);
let paths = '';
const options = {
listeners: {
stdout: (data) => {
paths += data.toString();
},
}
};
const args = strings_1.prependEach('-A', strings_1.nonEmptySplit(attributes, /\s+/)).concat([file || "default.nix"]);
yield exec.exec('nix-build', args, options);
core.endGroup();
}
}
catch (error) {