Skip to content

Commit

Permalink
Merge pull request #173 from dmvict/js_action
Browse files Browse the repository at this point in the history
READY: Add test for option `pre_retry_command` to commands
  • Loading branch information
dmvict authored Nov 5, 2024
2 parents 912f561 + 35921f9 commit be260df
Showing 1 changed file with 122 additions and 48 deletions.
170 changes: 122 additions & 48 deletions test/Command.test.s
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,9 @@ function retryWithOptionCurrentPath( test )

//

function retryWithMultilineCommand( test )
function retryWithOptionRetryConditionAndCheckOfStepOutput( test )
{
let context = this;

if( process.platform === 'win32' )
return test.true( true );

const a = test.assetFor( false );
const actionPath = a.abs( '_action/actions/wretry.action/v1' );
const execPath = `node ${ a.path.nativize( a.abs( actionPath, 'src/Main.js' ) ) }`;
Expand All @@ -330,9 +326,12 @@ function retryWithMultilineCommand( test )
{
test.case = 'multiline command';
if( process.platform === 'win32' )
core.exportVariable( `INPUT_COMMAND`, '|\n echo `\n str' );
core.exportVariable( `INPUT_COMMAND`, '|\necho $Env:GITHUB_OUTPUT\necho "foo=bar" >> $Env:GITHUB_OUTPUT\nexit 1' );
else
core.exportVariable( `INPUT_COMMAND`, '|\n echo \\\n str' );
core.exportVariable( `INPUT_COMMAND`, '|\necho $GITHUB_OUTPUT\necho "foo=bar" >> $GITHUB_OUTPUT\nexit 1' );
core.exportVariable( `INPUT_STEPS_CONTEXT`, '{}' );
core.exportVariable( `INPUT_RETRY_CONDITION`, `steps._this.outputs.foo == 'bar'` );
core.exportVariable( `GITHUB_OUTPUT`, `${ a.path.nativize( a.abs( actionPath, 'github_output' ) ) }` );
core.exportVariable( `INPUT_ATTEMPT_LIMIT`, '4' );
return null;
});
Expand All @@ -342,22 +341,25 @@ function retryWithMultilineCommand( test )
a.shellNonThrowing({ currentPath : actionPath, execPath });
a.ready.then( ( op ) =>
{
test.identical( op.exitCode, 0 );
console.log( op.output );
test.notIdentical( op.exitCode, 0 );
test.identical( _.strCount( op.output, '::error::Please, specify Github action name' ), 0 );
test.identical( _.strCount( op.output, 'Attempts exhausted, made 4 attempts' ), 0 );
test.identical( _.strCount( op.output, 'str' ), 1 );
test.identical( _.strCount( op.output, 'Attempts exhausted, made 4 attempts' ), 1 );
return null;
});

//
/* */

a.ready.then( () =>
{
test.case = 'several multiline command';
test.case = 'multiline command';
if( process.platform === 'win32' )
core.exportVariable( `INPUT_COMMAND`, '|\n echo `\n str\n echo `\n bar' );
core.exportVariable( `INPUT_COMMAND`, '|\necho $Env:GITHUB_OUTPUT\necho "foo=bar" >> $Env:GITHUB_OUTPUT\nexit 1' );
else
core.exportVariable( `INPUT_COMMAND`, '|\n echo \\\n str\n echo \\\n bar' );
core.exportVariable( `INPUT_COMMAND`, '|\necho $GITHUB_OUTPUT\necho "foo=bar" >> $GITHUB_OUTPUT\nexit 1' );
core.exportVariable( `INPUT_STEPS_CONTEXT`, '{}' );
core.exportVariable( `INPUT_RETRY_CONDITION`, `steps._this.outputs.foo == 'foo'` );
core.exportVariable( `GITHUB_OUTPUT`, `${ a.path.nativize( a.abs( actionPath, 'github_output' ) ) }` );
core.exportVariable( `INPUT_ATTEMPT_LIMIT`, '4' );
return null;
});
Expand All @@ -367,11 +369,21 @@ function retryWithMultilineCommand( test )
a.shellNonThrowing({ currentPath : actionPath, execPath });
a.ready.then( ( op ) =>
{
test.identical( op.exitCode, 0 );
test.notIdentical( op.exitCode, 0 );
test.identical( _.strCount( op.output, '::error::Please, specify Github action name' ), 0 );
test.identical( _.strCount( op.output, 'Attempts exhausted, made 4 attempts' ), 0 );
test.identical( _.strCount( op.output, 'str' ), 1 );
test.identical( _.strCount( op.output, 'bar' ), 1 );
return null;
});

a.ready.finally( () =>
{
core.exportVariable( `INPUT_RETRY_CONDITION`, true );
return null;
});

a.ready.finally( () =>
{
delete process.env.GITHUB_OUTPUT;
return null;
});

Expand Down Expand Up @@ -406,22 +418,21 @@ function retryWithMultilineCommand( test )

//

function retryAndCheckRuntimeEnvironments( test )
function retryWithOptionPreRetryCommand( test )
{
let context = this;
const a = test.assetFor( false );
const actionPath = a.abs( '_action/actions/wretry.action/v1' );
const execPath = `node ${ a.path.nativize( a.abs( actionPath, 'src/Main.js' ) ) }`;
const command = 'exit 1';

/* - */

a.ready.then( () =>
{
test.case = 'multiline command';
if( process.platform === 'win32' )
core.exportVariable( `INPUT_COMMAND`, '|\n $FOO="foo" \n $BAR="bar" \n echo $FOO$BAR' );
else
core.exportVariable( `INPUT_COMMAND`, '|\n export FOO=foo \n export BAR=bar \n echo $FOO$BAR' );
test.case = 'without current path';
core.exportVariable( `INPUT_COMMAND`, command );
core.exportVariable( `INPUT_PRE_RETRY_COMMAND`, 'echo "Executing pre_retry_command"' );
core.exportVariable( `INPUT_ATTEMPT_LIMIT`, '4' );
return null;
});
Expand All @@ -431,10 +442,19 @@ function retryAndCheckRuntimeEnvironments( test )
a.shellNonThrowing({ currentPath : actionPath, execPath });
a.ready.then( ( op ) =>
{
test.identical( op.exitCode, 0 );
console.log( op.output );
test.notIdentical( op.exitCode, 0 );
test.identical( _.strCount( op.output, '::error::Please, specify Github action name' ), 0 );
test.identical( _.strCount( op.output, 'Attempts exhausted, made 4 attempts' ), 0 );
test.identical( _.strCount( op.output, 'foobar' ), 1 );
test.identical( _.strCount( op.output, 'Attempts exhausted, made 4 attempts' ), 1 );
test.identical( _.strCount( op.output, 'Executing pre_retry_command' ), 4 );
return null;
});

/* */

a.ready.finally( () =>
{
delete process.env.INPUT_PRE_RETRY_COMMAND;
return null;
});

Expand Down Expand Up @@ -469,9 +489,13 @@ function retryAndCheckRuntimeEnvironments( test )

//

function retryWithOptionRetryConditionAndCheckOfStepOutput( test )
function retryWithMultilineCommand( test )
{
let context = this;

if( process.platform === 'win32' )
return test.true( true );

const a = test.assetFor( false );
const actionPath = a.abs( '_action/actions/wretry.action/v1' );
const execPath = `node ${ a.path.nativize( a.abs( actionPath, 'src/Main.js' ) ) }`;
Expand All @@ -482,12 +506,9 @@ function retryWithOptionRetryConditionAndCheckOfStepOutput( test )
{
test.case = 'multiline command';
if( process.platform === 'win32' )
core.exportVariable( `INPUT_COMMAND`, '|\necho $Env:GITHUB_OUTPUT\necho "foo=bar" >> $Env:GITHUB_OUTPUT\nexit 1' );
core.exportVariable( `INPUT_COMMAND`, '|\n echo `\n str' );
else
core.exportVariable( `INPUT_COMMAND`, '|\necho $GITHUB_OUTPUT\necho "foo=bar" >> $GITHUB_OUTPUT\nexit 1' );
core.exportVariable( `INPUT_STEPS_CONTEXT`, '{}' );
core.exportVariable( `INPUT_RETRY_CONDITION`, `steps._this.outputs.foo == 'bar'` );
core.exportVariable( `GITHUB_OUTPUT`, `${ a.path.nativize( a.abs( actionPath, 'github_output' ) ) }` );
core.exportVariable( `INPUT_COMMAND`, '|\n echo \\\n str' );
core.exportVariable( `INPUT_ATTEMPT_LIMIT`, '4' );
return null;
});
Expand All @@ -497,25 +518,22 @@ function retryWithOptionRetryConditionAndCheckOfStepOutput( test )
a.shellNonThrowing({ currentPath : actionPath, execPath });
a.ready.then( ( op ) =>
{
console.log( op.output );
test.notIdentical( op.exitCode, 0 );
test.identical( op.exitCode, 0 );
test.identical( _.strCount( op.output, '::error::Please, specify Github action name' ), 0 );
test.identical( _.strCount( op.output, 'Attempts exhausted, made 4 attempts' ), 1 );
test.identical( _.strCount( op.output, 'Attempts exhausted, made 4 attempts' ), 0 );
test.identical( _.strCount( op.output, 'str' ), 1 );
return null;
});

/* */
//

a.ready.then( () =>
{
test.case = 'multiline command';
test.case = 'several multiline command';
if( process.platform === 'win32' )
core.exportVariable( `INPUT_COMMAND`, '|\necho $Env:GITHUB_OUTPUT\necho "foo=bar" >> $Env:GITHUB_OUTPUT\nexit 1' );
core.exportVariable( `INPUT_COMMAND`, '|\n echo `\n str\n echo `\n bar' );
else
core.exportVariable( `INPUT_COMMAND`, '|\necho $GITHUB_OUTPUT\necho "foo=bar" >> $GITHUB_OUTPUT\nexit 1' );
core.exportVariable( `INPUT_STEPS_CONTEXT`, '{}' );
core.exportVariable( `INPUT_RETRY_CONDITION`, `steps._this.outputs.foo == 'foo'` );
core.exportVariable( `GITHUB_OUTPUT`, `${ a.path.nativize( a.abs( actionPath, 'github_output' ) ) }` );
core.exportVariable( `INPUT_COMMAND`, '|\n echo \\\n str\n echo \\\n bar' );
core.exportVariable( `INPUT_ATTEMPT_LIMIT`, '4' );
return null;
});
Expand All @@ -525,21 +543,74 @@ function retryWithOptionRetryConditionAndCheckOfStepOutput( test )
a.shellNonThrowing({ currentPath : actionPath, execPath });
a.ready.then( ( op ) =>
{
test.notIdentical( op.exitCode, 0 );
test.identical( op.exitCode, 0 );
test.identical( _.strCount( op.output, '::error::Please, specify Github action name' ), 0 );
test.identical( _.strCount( op.output, 'Attempts exhausted, made 4 attempts' ), 0 );
test.identical( _.strCount( op.output, 'str' ), 1 );
test.identical( _.strCount( op.output, 'bar' ), 1 );
return null;
});

a.ready.finally( () =>
/* - */

return a.ready;

/* */

function actionSetup()
{
core.exportVariable( `INPUT_RETRY_CONDITION`, true );
a.ready.then( () =>
{
a.fileProvider.filesDelete( a.abs( '.' ) );
a.fileProvider.dirMake( actionPath );
return null;
});
a.ready.then( () =>
{
return __.git.repositoryClone
({
localPath : actionPath,
remotePath : __.git.path.normalize( context.actionDirPath ),
attemptLimit : 4,
attemptDelay : 250,
attemptDelayMultiplier : 4,
});
});
return a.ready;
}
}

//

function retryAndCheckRuntimeEnvironments( test )
{
let context = this;
const a = test.assetFor( false );
const actionPath = a.abs( '_action/actions/wretry.action/v1' );
const execPath = `node ${ a.path.nativize( a.abs( actionPath, 'src/Main.js' ) ) }`;

/* - */

a.ready.then( () =>
{
test.case = 'multiline command';
if( process.platform === 'win32' )
core.exportVariable( `INPUT_COMMAND`, '|\n $FOO="foo" \n $BAR="bar" \n echo $FOO$BAR' );
else
core.exportVariable( `INPUT_COMMAND`, '|\n export FOO=foo \n export BAR=bar \n echo $FOO$BAR' );
core.exportVariable( `INPUT_ATTEMPT_LIMIT`, '4' );
return null;
});

a.ready.finally( () =>
actionSetup();

a.shellNonThrowing({ currentPath : actionPath, execPath });
a.ready.then( ( op ) =>
{
delete process.env.GITHUB_OUTPUT;
test.identical( op.exitCode, 0 );
test.identical( _.strCount( op.output, '::error::Please, specify Github action name' ), 0 );
test.identical( _.strCount( op.output, 'Attempts exhausted, made 4 attempts' ), 0 );
test.identical( _.strCount( op.output, 'foobar' ), 1 );
return null;
});

Expand Down Expand Up @@ -758,10 +829,13 @@ const Proto =
retryWithoutCommand,
retryWithWrongCommand,
retryWithValidCommand,

retryWithOptionCurrentPath,
retryWithOptionRetryConditionAndCheckOfStepOutput,
retryWithOptionPreRetryCommand,

retryWithMultilineCommand,
retryAndCheckRuntimeEnvironments,
retryWithOptionRetryConditionAndCheckOfStepOutput,
retryCheckRetryTime,
},
};
Expand Down

0 comments on commit be260df

Please sign in to comment.