Smarter args parser and a few debug messages

This commit is contained in:
svartalf 2019-09-13 22:45:36 +03:00
parent de5e75cc84
commit 40cbaa365c
6 changed files with 27 additions and 15 deletions

View file

@ -1,7 +1,8 @@
import * as args from '../src/args' import * as input from '../src/input'
const testEnvVars = { const testEnvVars = {
INPUT_COMMAND: 'build', INPUT_COMMAND: 'build',
// There are few unnecessary spaces here to check that args parser works properly
INPUT_ARGS: ' --release --target x86_64-unknown-linux-gnu --no-default-features --features unstable ', INPUT_ARGS: ' --release --target x86_64-unknown-linux-gnu --no-default-features --features unstable ',
'INPUT_USE-CROSS': 'true', 'INPUT_USE-CROSS': 'true',
INPUT_TOOLCHAIN: '+nightly' INPUT_TOOLCHAIN: '+nightly'
@ -14,7 +15,7 @@ describe('actions-rs/check', () => {
}) })
it('Parses action input into cargo input', async () => { it('Parses action input into cargo input', async () => {
const result = args.parse(); const result = input.parse();
expect(result.command).toBe('build'); expect(result.command).toBe('build');
expect(result.args).toStrictEqual([ expect(result.args).toStrictEqual([

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

13
package-lock.json generated
View file

@ -1,13 +1,13 @@
{ {
"name": "cargo", "name": "cargo",
"version": "1.0.0", "version": "0.1.0",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
"@actions/core": { "@actions/core": {
"version": "1.0.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.0.0.tgz", "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.1.0.tgz",
"integrity": "sha512-aMIlkx96XH4E/2YZtEOeyrYQfhlas9jIRkfGPqMwXD095Rdkzo4lB6ZmbxPQSzD+e1M+Xsm98ZhuSMYGv/AlqA==" "integrity": "sha512-KKpo3xzo0Zsikni9tbOsEQkxZBGDsYSJZNkTvmo0gPSXrc98TBOcdTvKwwjitjkjHkreTggWdB1ACiAFVgsuzA=="
}, },
"@actions/exec": { "@actions/exec": {
"version": "1.0.1", "version": "1.0.1",
@ -4413,6 +4413,11 @@
"integrity": "sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks=", "integrity": "sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks=",
"dev": true "dev": true
}, },
"string-argv": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/string-argv/-/string-argv-0.3.1.tgz",
"integrity": "sha512-a1uQGz7IyVy9YwhqjZIZu1c8JO8dNIe20xBmSS6qu9kv++k3JGzCVmprbNN5Kn+BgzD5E7YYwg1CcjuJMRNsvg=="
},
"string-length": { "string-length": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/string-length/-/string-length-2.0.0.tgz", "resolved": "https://registry.npmjs.org/string-length/-/string-length-2.0.0.tgz",

View file

@ -28,9 +28,10 @@
"url": "https://github.com/actions-rs/cargo/issues" "url": "https://github.com/actions-rs/cargo/issues"
}, },
"dependencies": { "dependencies": {
"@actions/core": "^1.0.0", "@actions/core": "^1.0.1",
"@actions/exec": "^1.0.0", "@actions/exec": "^1.0.1",
"@actions/io": "^1.0.0" "@actions/io": "^1.0.1",
"string-argv": "^0.3.1"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^24.0.13", "@types/jest": "^24.0.13",

View file

@ -5,6 +5,8 @@
import * as core from '@actions/core'; import * as core from '@actions/core';
import * as exec from '@actions/exec'; import * as exec from '@actions/exec';
import stringArgv from 'string-argv';
// Workaround for a GH bug: https://github.com/actions/toolkit/issues/127 // Workaround for a GH bug: https://github.com/actions/toolkit/issues/127
// //
// For input `all-features: true` it will generate the `INPUT_ALL-FEATURES: true` // For input `all-features: true` it will generate the `INPUT_ALL-FEATURES: true`
@ -41,8 +43,7 @@ export interface Input {
export function parse(): Input { export function parse(): Input {
const command = getInput('command'); const command = getInput('command');
// TODO: This probably will strike back later const args = stringArgv(getInput('args'));
const args = getInput('args').split(' ');
let toolchain = getInput('toolchain'); let toolchain = getInput('toolchain');
if (toolchain.startsWith('+')) { if (toolchain.startsWith('+')) {
toolchain = toolchain.slice(1); toolchain = toolchain.slice(1);

View file

@ -10,10 +10,11 @@ async function getCross(): Promise<string> {
try { try {
return await io.which('cross', true); return await io.which('cross', true);
} catch (error) { } catch (error) {
core.warning('Unable to find cross, installing it now'); core.debug('Unable to find cross, installing it now');
} }
try { try {
core.startGroup('Install cross');
core.warning('Git version of cross will be installed, \ core.warning('Git version of cross will be installed, \
see https://github.com/actions-rs/cargo/issues/1'); see https://github.com/actions-rs/cargo/issues/1');
await exec.exec('cargo', [ await exec.exec('cargo', [
@ -25,6 +26,9 @@ async function getCross(): Promise<string> {
]); ]);
} catch (error) { } catch (error) {
core.setFailed(error.message); core.setFailed(error.message);
throw new Error(error);
} finally {
core.endGroup();
} }
// Expecting it to be in PATH already // Expecting it to be in PATH already