Support private caches

This commit is contained in:
Domen Kožar 2019-10-03 11:48:23 +02:00
commit 453bd5c328
No known key found for this signature in database
GPG key ID: C2FFBCAFD2C24246
6 changed files with 56 additions and 29 deletions

View file

@ -18,26 +18,30 @@ 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 tc = __importStar(require("@actions/tool-cache"));
const os_1 = require("os");
const utils_1 = require("./utils");
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
// inputs
const file = core.getInput('file');
const attributes = core.getInput('attributes');
const cachixPush = core.getInput('cachixPush', { required: true });
console.log(`Installing Nix ...`);
const nixInstall = yield tc.downloadTool('https://nixos.org/nix/install');
yield exec.exec(nixInstall);
// required for macos
core.exportVariable('NIX_SSL_CERT_FILE', '/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt');
console.log(`Installing Cachix ...`);
yield exec.exec(os_1.homedir() + '/.nix-profile/bin/nix-env', ['-iA', 'cachix', '-f', 'https://cachix.org/api/v1/install']);
const push = core.getInput('push', { required: true });
const signingKey = core.getInput('signingKey', { required: true });
const authToken = core.getInput('authToken');
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']);
core.endGroup();
// for private caches
if (authToken !== "") {
yield exec.exec('cachix', ['authtoken', authToken]);
}
core.startGroup(`Cachix: using ` + push);
yield exec.exec('cachix', ['use', push]);
core.endGroup();
core.exportVariable('CACHIX_SIGNING_KEY', signingKey);
// TODO: cachix use --watch-store
console.log(`Setting up cache ` + cachixPush + `...`);
yield exec.exec(os_1.homedir() + '/.nix-profile/bin/cachix', ['use', cachixPush]);
console.log(`Invoking nix-build...`);
core.startGroup(`Invoking nix-build`);
let paths = '';
const options = {
listeners: {
@ -46,10 +50,12 @@ function run() {
},
}
};
const args = ['-f', file || "default.nix"].concat(utils_1.extrasperse('-A', attributes.split(/\s/)));
yield exec.exec(os_1.homedir() + '/.nix-profile/bin/nix-build', args, options);
console.log(`Pushing to cache ` + cachixPush + `...`);
yield exec.exec(os_1.homedir() + '/.nix-profile/bin/cachix', ['push', cachixPush].concat(paths.split(/\s/).join(' ')));
const args = utils_1.extrasperse('-A', utils_1.saneSplit(attributes, /\s/)).concat([file || "default.nix"]);
yield exec.exec('nix-build', args, options);
core.endGroup();
core.startGroup(`Cachix: pushing to ` + push);
yield exec.exec('cachix', ['push', push].concat(utils_1.saneSplit(paths, /\s/).join(' ')));
core.endGroup();
}
catch (error) {
core.setFailed(`Action failed with error: ${error}`);

View file

@ -6,3 +6,7 @@ function extrasperse(elem, array) {
}
exports.extrasperse = extrasperse;
;
function saneSplit(str, separator) {
return str.split(separator).filter(word => word != "");
}
exports.saneSplit = saneSplit;