use sane version of split

This commit is contained in:
Domen Kožar 2019-10-01 12:10:07 +02:00
commit c97af141f3
No known key found for this signature in database
GPG key ID: C2FFBCAFD2C24246
3 changed files with 15 additions and 7 deletions

View file

@ -1,8 +1,13 @@
import {extrasperse} from '../src/utils' import {extrasperse, saneSplit} from '../src/utils'
test('extrasperse', async() => { test('extrasperse', async() => {
expect(extrasperse('-A', ["foo", "bar"])).toEqual(["-A", "foo", "-A", "bar"]); expect(extrasperse('-A', ["foo", "bar"])).toEqual(["-A", "foo", "-A", "bar"]);
expect(extrasperse('-A', [])).toEqual([]) expect(extrasperse('-A', [])).toEqual([]);
}); });
test('saneSplit', async() => {
expect(saneSplit("", /\s+/)).toEqual([]);
expect(saneSplit("foo bar", /\s+/)).toEqual(["foo", "bar"]);
})
// TODO: hopefully github actions will support integration tests // TODO: hopefully github actions will support integration tests

View file

@ -3,7 +3,7 @@ import * as exec from '@actions/exec';
import * as tc from '@actions/tool-cache'; import * as tc from '@actions/tool-cache';
import {homedir} from 'os'; import {homedir} from 'os';
import {existsSync} from 'fs'; import {existsSync} from 'fs';
import {extrasperse} from './utils'; import {extrasperse, saneSplit} from './utils';
async function run() { async function run() {
try { try {
@ -50,12 +50,12 @@ async function run() {
}, },
} }
}; };
const args = extrasperse('-A', attributes.split(/\s/)).concat([file || "default.nix"]); const args = extrasperse('-A', saneSplit(attributes, /\s/)).concat([file || "default.nix"]);
await exec.exec('nix-build', args, options); await exec.exec('nix-build', args, options);
core.endGroup() core.endGroup()
core.startGroup(`Pushing to Cachix ` + cachixPush); core.startGroup(`Pushing to Cachix ` + cachixPush);
await exec.exec('cachix', ['push', cachixPush].concat(paths.split(/\s/).join(' '))); await exec.exec('cachix', ['push', cachixPush].concat(saneSplit(paths, /\s/).join(' ')));
core.endGroup() core.endGroup()
} catch (error) { } catch (error) {
core.setFailed(`Action failed with error: ${error}`); core.setFailed(`Action failed with error: ${error}`);

View file

@ -1,5 +1,8 @@
export function extrasperse (elem: string, array: string[]) { export function extrasperse (elem: string, array: string[]): string[] {
const init: string[] = []; const init: string[] = [];
return array.reduce((r, a) => r.concat(elem, a), init) return array.reduce((r, a) => r.concat(elem, a), init)
}; };
export function saneSplit (str: string, separator): string[] {
return str.split(separator).filter(word => word != "")
}