Skip to content

Commit

Permalink
Merge pull request #130 from dmvict/js_action
Browse files Browse the repository at this point in the history
READY: Improve commands handler, fix tests
  • Loading branch information
dmvict authored Feb 27, 2024
2 parents 8bf67e7 + ef1172d commit 14acfaa
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 23 deletions.
19 changes: 7 additions & 12 deletions src/Common.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,21 @@ function commandsForm( command )
{
_.assert( command.length > 0, 'Please, specify Github action name or shell command.' );

const commands = [ command[ 0 ] ];
let i = 1;
if( command[ 0 ] === '|' )
{
_.assert( command.length > 1, 'Expected multiline command.' );
commands[ 0 ] = command[ 1 ];
i = 2;
command.shift();
}

for( i ; i < command.length ; i++ )
_.assert( !_.str.ends( command[ command.length - 1 ], /\s\\/ ), 'Last command should have no continuation.' );

if( process.platform === 'win32' )
{
if( _.str.ends( commands[ commands.length - 1 ], /\s\\/ ) )
commands[ commands.length - 1 ] = `${ commands[ commands.length - 1 ] }\n${ command[ i ] }`;
else
commands.push( command[ i ] );
command.push( 'if ((Test-Path -LiteralPath variable:\LASTEXITCODE)) { exit $LASTEXITCODE }' );
command.unshift( `$ErrorActionPreference = 'stop'` );
}

_.assert( !_.str.ends( commands[ commands.length - 1 ], /\s\\/ ), 'Last command should have no continuation.' );

return commands;
return command;
}

//
Expand Down
5 changes: 0 additions & 5 deletions src/Retry.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ function retry( scriptType )
if( !actionName )
{
const commands = common.commandsForm( command );
if( process.platform === 'win32' )
{
commands.push( 'if ((Test-Path -LiteralPath variable:\LASTEXITCODE)) { exit $LASTEXITCODE }' );
commands.unshift( `$ErrorActionPreference = 'stop'` );
}
const commandsScriptPath = _.path.join( __dirname, process.platform === 'win32' ? 'script.ps1' : 'script.sh' );
_.fileProvider.fileWrite( commandsScriptPath, commands.join( '\n' ) );

Expand Down
2 changes: 1 addition & 1 deletion test/Action.test.s
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ function retryFetchActionWithoutTagOrHash( test )
test.ge( _.strCount( op.output, '::set-env' ), 1 );
test.identical( _.strCount( op.output, '::error::Wrong attempt' ), 0 );
test.identical( _.strCount( op.output, /::error::.*Attempts exhausted, made 4 attempts/ ), 0 );
test.identical( _.strCount( op.output, 'Hello test!' ), 1 );
test.identical( _.strCount( op.output, 'Hello, test!' ), 1 );
return null;
});

Expand Down
8 changes: 4 additions & 4 deletions test/Common.test.s
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ function commandsForm( test )

test.case = 'multiline command with backslash';
var got = common.commandsForm( [ 'echo \\', 'foo' ] );
test.identical( got, [ 'echo \\\nfoo' ] );
test.identical( got, [ 'echo \\', 'foo' ] );

test.case = 'multiline command with bar and backslash';
var got = common.commandsForm( [ '|', 'echo \\', 'foo' ] );
test.identical( got, [ 'echo \\\nfoo' ] );
test.identical( got, [ 'echo \\', 'foo' ] );

test.case = 'multiline command with bar and backslash, several commands';
var got = common.commandsForm( [ '|', 'echo \\', 'foo', 'echo bar' ] );
test.identical( got, [ 'echo \\\nfoo', 'echo bar' ] );
test.identical( got, [ 'echo \\', 'foo', 'echo bar' ] );

test.case = 'multiline commands with bar and backslash, several commands';
var got = common.commandsForm( [ '|', 'echo \\', 'foo', 'echo \\', 'bar' ] );
test.identical( got, [ 'echo \\\nfoo', 'echo \\\nbar' ] );
test.identical( got, [ 'echo \\', 'foo', 'echo \\', 'bar' ] );

/* - */

Expand Down
2 changes: 1 addition & 1 deletion will.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ submodule:
path: 'npm:///@actions/core!1.10.0'
enabled: 0
github-actions-parser:
path: 'npm:///github-actions-parser!0.26.0'
path: 'npm:///github-actions-parser!dmvict/github-actions-parser'
enabled: 0
wgittools:
path: 'npm:///wgittools!alpha'
Expand Down

0 comments on commit 14acfaa

Please sign in to comment.