Initial commit

This commit is contained in:
Domen Kožar 2019-09-29 21:52:02 +02:00 committed by Domen Kožar
commit a6de7cd0c2
No known key found for this signature in database
GPG key ID: C2FFBCAFD2C24246
14 changed files with 4063 additions and 0 deletions

43
src/main.ts Normal file
View file

@ -0,0 +1,43 @@
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import {homedir} from 'os';
import {extrasperse} from './utils';
async function run() {
try {
const file = core.getInput('file');
const attributes = core.getInput('attributes');
const cachixPush = core.getInput('cachixPush', { required: true });
// required for macos
core.exportVariable('NIX_SSL_CERT_FILE', '/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt');
console.log(`Installing Cachix ...`);
await exec.exec(homedir() + '/.nix-profile/bin/nix-env', ['-iA', 'cachix', '-f', 'https://cachix.org/api/v1/install']);
// TODO: cachix use --watch-store
console.log(`Setting up cache ` + cachixPush + `...`);
await exec.exec(homedir() + '/.nix-profile/bin/cachix', ['use', cachixPush]);
console.log(`Invoking nix-build...`);
let paths = '';
const options = {
listeners: {
stdout: (data: Buffer) => {
paths += data.toString();
},
}
};
const args = ['-f', file || "default.nix"].concat(extrasperse('-A', attributes.split(/\s/)));
await exec.exec(homedir() + '/.nix-profile/bin/nix-build', args, options);
console.log(`Pushing to cache ` + cachixPush + `...`);
await exec.exec(homedir() + '/.nix-profile/bin/cachix', ['push', cachixPush].concat(paths.split(/\s/).join(' ')));
} catch (error) {
core.setFailed(`Action faield with error: ${error}`);
throw(error);
}
}
run();

5
src/utils.ts Normal file
View file

@ -0,0 +1,5 @@
export function extrasperse (elem: string, array: string[]) {
const init: string[] = [];
return array.reduce((r, a) => r.concat(elem, a), init)
};