Skip to content

Commit

Permalink
Merge pull request #181 from dmvict/js_action
Browse files Browse the repository at this point in the history
READY: Add support of local actions
  • Loading branch information
dmvict authored Jan 9, 2025
2 parents 27fa3b1 + 0db20fb commit b6c26de
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Retry.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,23 @@ function retry( scriptType )

process.env.RETRY_ACTION = actionName;
const token = core.getInput( 'github_token' );
const remoteActionPath = common.remotePathForm( actionName, token );
const localActionDir = _.path.nativize( _.path.join( __dirname, '../../../', remoteActionPath.repo ) );

const localIs = actionName.startsWith( './' );

let remoteActionPath = null;
if( !localIs )
remoteActionPath = common.remotePathForm( actionName, token );

const localActionDir = localIs ?
_.path.nativize( _.path.join( process.env.GITHUB_WORKSPACE, actionName ) ) :
_.path.nativize( _.path.join( __dirname, '../../../', remoteActionPath.repo ) );

if( !localIs )
con.then( () => common.actionClone( localActionDir, remoteActionPath ) );

con.then( () =>
{
const actionFileDir = _.path.nativize( _.path.join( localActionDir, remoteActionPath.localVcsPath ) );
const actionFileDir = localIs ? localActionDir : _.path.nativize( _.path.join( localActionDir, remoteActionPath.localVcsPath ) );
const config = common.actionConfigRead( actionFileDir );

if( common.shouldExit( config, scriptType ) )
Expand Down
69 changes: 69 additions & 0 deletions test/Action.test.s
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,74 @@ function retryWithActionAndCommand( test )

//

function retryLocalAction( test )
{
const 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 repoWithWorkflowDir = a.abs( 'test.action' );
const localActionRepo = 'https://github.com/dmvict/test.action.git';
const testAction = './.github/actions';

/* - */

a.ready.then( () =>
{
test.case = 'enought attempts';
core.exportVariable( `INPUT_ACTION`, testAction );
core.exportVariable( `INPUT_WITH`, 'value : 0' );
core.exportVariable( `INPUT_ATTEMPT_LIMIT`, '4' );
core.exportVariable( `GITHUB_WORKSPACE`, repoWithWorkflowDir );
return null;
});

actionSetup();

a.shellNonThrowing({ currentPath : actionPath, execPath });
a.ready.then( ( op ) =>
{
test.identical( op.exitCode, 0 );
if( !_.process.insideTestContainer() )
test.ge( _.strCount( op.output, '::set-env' ), 3 );
test.identical( _.strCount( op.output, '::error::Wrong attempt' ), 3 );
test.identical( _.strCount( op.output, /::error::undefined.*Attempts exhausted, made 4 attempts/ ), 0 );
test.identical( _.strCount( op.output, 'Success' ), 1 );
return null;
});

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

/* - */

return a.ready;

/* */

function actionSetup()
{
a.ready.then( () =>
{
a.fileProvider.filesDelete( a.abs( '.' ) );
a.fileProvider.dirMake( actionPath );
a.fileProvider.dirMake( repoWithWorkflowDir );
return null;
});
a.shell( `git clone ${ a.path.nativize( context.actionDirPath ) } ${ a.path.nativize( actionPath ) }` );
a.shell( `git clone ${ localActionRepo } ${ a.path.nativize( repoWithWorkflowDir ) }` );
a.shell({ currentPath : repoWithWorkflowDir, execPath : 'git checkout local_action' });
a.shell( `node ${ a.path.nativize( a.abs( actionPath, 'src/Pre.js' ) ) }` );
return a.ready;
}
}

//

function retryFetchActionWithoutTagOrHash( test )
{
const context = this;
Expand Down Expand Up @@ -1946,6 +2014,7 @@ const Proto =
retryWithUnsupportedAction,
retryWithActionAndCommand,

retryLocalAction,
retryFetchActionWithoutTagOrHash,
retryFetchActionWithTag,
retryFetchActionWithHash,
Expand Down

0 comments on commit b6c26de

Please sign in to comment.