Skip to content

Commit b6c26de

Browse files
authored
Merge pull request #181 from dmvict/js_action
READY: Add support of local actions
2 parents 27fa3b1 + 0db20fb commit b6c26de

File tree

2 files changed

+82
-3
lines changed

2 files changed

+82
-3
lines changed

src/Retry.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,23 @@ function retry( scriptType )
6767

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

71+
const localIs = actionName.startsWith( './' );
72+
73+
let remoteActionPath = null;
74+
if( !localIs )
75+
remoteActionPath = common.remotePathForm( actionName, token );
76+
77+
const localActionDir = localIs ?
78+
_.path.nativize( _.path.join( process.env.GITHUB_WORKSPACE, actionName ) ) :
79+
_.path.nativize( _.path.join( __dirname, '../../../', remoteActionPath.repo ) );
80+
81+
if( !localIs )
7382
con.then( () => common.actionClone( localActionDir, remoteActionPath ) );
83+
7484
con.then( () =>
7585
{
76-
const actionFileDir = _.path.nativize( _.path.join( localActionDir, remoteActionPath.localVcsPath ) );
86+
const actionFileDir = localIs ? localActionDir : _.path.nativize( _.path.join( localActionDir, remoteActionPath.localVcsPath ) );
7787
const config = common.actionConfigRead( actionFileDir );
7888

7989
if( common.shouldExit( config, scriptType ) )

test/Action.test.s

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,74 @@ function retryWithActionAndCommand( test )
203203

204204
//
205205

206+
function retryLocalAction( test )
207+
{
208+
const context = this;
209+
const a = test.assetFor( false );
210+
const actionPath = a.abs( '_action/actions/wretry.action/v1' );
211+
const execPath = `node ${ a.path.nativize( a.abs( actionPath, 'src/Main.js' ) ) }`;
212+
213+
const repoWithWorkflowDir = a.abs( 'test.action' );
214+
const localActionRepo = 'https://github.com/dmvict/test.action.git';
215+
const testAction = './.github/actions';
216+
217+
/* - */
218+
219+
a.ready.then( () =>
220+
{
221+
test.case = 'enought attempts';
222+
core.exportVariable( `INPUT_ACTION`, testAction );
223+
core.exportVariable( `INPUT_WITH`, 'value : 0' );
224+
core.exportVariable( `INPUT_ATTEMPT_LIMIT`, '4' );
225+
core.exportVariable( `GITHUB_WORKSPACE`, repoWithWorkflowDir );
226+
return null;
227+
});
228+
229+
actionSetup();
230+
231+
a.shellNonThrowing({ currentPath : actionPath, execPath });
232+
a.ready.then( ( op ) =>
233+
{
234+
test.identical( op.exitCode, 0 );
235+
if( !_.process.insideTestContainer() )
236+
test.ge( _.strCount( op.output, '::set-env' ), 3 );
237+
test.identical( _.strCount( op.output, '::error::Wrong attempt' ), 3 );
238+
test.identical( _.strCount( op.output, /::error::undefined.*Attempts exhausted, made 4 attempts/ ), 0 );
239+
test.identical( _.strCount( op.output, 'Success' ), 1 );
240+
return null;
241+
});
242+
243+
a.ready.finally( () =>
244+
{
245+
delete process.env.GITHUB_WORKSPACE;
246+
return null;
247+
});
248+
249+
/* - */
250+
251+
return a.ready;
252+
253+
/* */
254+
255+
function actionSetup()
256+
{
257+
a.ready.then( () =>
258+
{
259+
a.fileProvider.filesDelete( a.abs( '.' ) );
260+
a.fileProvider.dirMake( actionPath );
261+
a.fileProvider.dirMake( repoWithWorkflowDir );
262+
return null;
263+
});
264+
a.shell( `git clone ${ a.path.nativize( context.actionDirPath ) } ${ a.path.nativize( actionPath ) }` );
265+
a.shell( `git clone ${ localActionRepo } ${ a.path.nativize( repoWithWorkflowDir ) }` );
266+
a.shell({ currentPath : repoWithWorkflowDir, execPath : 'git checkout local_action' });
267+
a.shell( `node ${ a.path.nativize( a.abs( actionPath, 'src/Pre.js' ) ) }` );
268+
return a.ready;
269+
}
270+
}
271+
272+
//
273+
206274
function retryFetchActionWithoutTagOrHash( test )
207275
{
208276
const context = this;
@@ -1946,6 +2014,7 @@ const Proto =
19462014
retryWithUnsupportedAction,
19472015
retryWithActionAndCommand,
19482016

2017+
retryLocalAction,
19492018
retryFetchActionWithoutTagOrHash,
19502019
retryFetchActionWithTag,
19512020
retryFetchActionWithHash,

0 commit comments

Comments
 (0)