Skip to content

Commit

Permalink
Merge pull request #134 from dmvict/js_action
Browse files Browse the repository at this point in the history
READY: Improve realization of action configurations
  • Loading branch information
dmvict authored Mar 6, 2024
2 parents 38a526c + 9d23774 commit 5fe5493
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 167 deletions.
14 changes: 1 addition & 13 deletions .github/workflows/JsActionPublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,11 @@ jobs :
- name : ${{ matrix.node-version }}
uses : Wandalen/wretry.action@master
with :
action : actions/setup-node@v2
action : actions/setup-node@v4
with : |
node-version : ${{ matrix.node-version }}
attempt_limit : 3
attempt_delay: 1000
- name : Save npm version
id : getnpmver
run : |
echo "npmver=$(npm -v)" >> $GITHUB_OUTPUT
- name : Update npm if current version is 6
if : "startsWith( steps.getnpmver.outputs.npmver, '6.' )"
run : npm install -g npm@latest-6
- name : Update node-gyp
if: ${{ matrix.os == 'windows-latest' && matrix.node-version != '18.x' }}
run : |
npm install --global node-gyp@9.0.0
npm prefix -g | % {npm config set node_gyp "$_\node_modules\node-gyp\bin\node-gyp.js"}
- name : Install willbe
uses : Wandalen/wretry.action@master
with :
Expand Down
12 changes: 1 addition & 11 deletions .github/workflows/JsActionPullRequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,11 @@ jobs :
- name : ${{ matrix.node-version }}
uses : Wandalen/wretry.action@master
with :
action : actions/setup-node@v2
action : actions/setup-node@v4
with : |
node-version : ${{ matrix.node-version }}
attempt_limit : 3
attempt_delay: 1000
- name : Update npm
if : ${{ matrix.os == 'windows-latest' && matrix.node-version > '14.x' }}
run : |
npm install --global --production npm-windows-upgrade
npm-windows-upgrade --npm-version latest
- name : Update node-gyp
if: ${{ matrix.os == 'windows-latest' && matrix.node-version != '18.x' }}
run : |
npm install --global node-gyp@9.0.0
npm prefix -g | % {npm config set node_gyp "$_\node_modules\node-gyp\bin\node-gyp.js"}
- name : Install willbe
uses : Wandalen/wretry.action@master
with :
Expand Down
14 changes: 1 addition & 13 deletions .github/workflows/JsActionPush.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,11 @@ jobs :
- name : ${{ matrix.node-version }}
uses : Wandalen/wretry.action@master
with :
action : actions/setup-node@v2
action : actions/setup-node@v4
with : |
node-version : ${{ matrix.node-version }}
attempt_limit : 3
attempt_delay: 1000
- name : Save npm version
id : getnpmver
run : |
echo "npmver=$(npm -v)" >> $GITHUB_OUTPUT
- name : Update npm if current version is 6
if : "startsWith( steps.getnpmver.outputs.npmver, '6.' )"
run : npm install -g npm@latest-6
- name : Update node-gyp
if: ${{ matrix.os == 'windows-latest' && matrix.node-version != '18.x' }}
run : |
npm install --global node-gyp@9.0.0
npm prefix -g | % {npm config set node_gyp "$_\node_modules\node-gyp\bin\node-gyp.js"}
- name : Install willbe
uses : Wandalen/wretry.action@master
with :
Expand Down
90 changes: 3 additions & 87 deletions src/Common.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ function commandsForm( command )

if( process.platform === 'win32' )
{
command.push( 'if ((Test-Path -LiteralPath variable:\LASTEXITCODE)) { exit $LASTEXITCODE }' );
command.unshift( `$ErrorActionPreference = 'stop'` );
command.push( 'if ((Test-Path -LiteralPath variable:\LASTEXITCODE)) { exit $LASTEXITCODE }' );
}

return command;
Expand Down Expand Up @@ -99,92 +99,8 @@ function actionConfigRead( actionDir )

function actionOptionsParse( src )
{
src = src.split( '\n' );

const result = Object.create( null );
for( let i = 0 ; i < src.length ; i++ )
{
const splits = _.strStructureParse({ src : src[ i ], toNumberMaybe : 0 });
for( let key in splits )
if( splits[ key ] === '|' && i + 1 < src.length )
{
let keySpacesNumber = src[ i ].search( /\S/ );
let spacesNumber = src[ i + 1 ].search( /\S/ );

let prefix = [];
if( spacesNumber == -1 )
{
i += 1;
while( i < src.length )
{
let entryPosition = src[ i ].search( /\S/ );
if( entryPosition === -1 )
{
prefix.push( '\n' );
i += 1;
}
else if( entryPosition > keySpacesNumber )
{
spacesNumber = entryPosition;
break;
}
else if ( entryPosition <= keySpacesNumber )
{
break;
}
}
i -= 1;
}

if( spacesNumber > keySpacesNumber )
{
i += 1;
splits[ key ] = '';
let multilineSplits = splits;
let multileneKey= key;
let multilineKeyIs = true;
while( multilineKeyIs && i < src.length )
{
let positionEntry = src[ i ].search( /\S/ );
if( positionEntry >= spacesNumber )
{
multilineSplits[ multileneKey ] += `\n${ src[ i ].substring( spacesNumber ) }`;
i += 1;
}
else if( positionEntry === -1 )
{
multilineSplits[ multileneKey ] += `\n${ src[ i ] }`;
i += 1;
}
else
{
let pref = prefix.join( '' );
multilineSplits[ multileneKey ] = multilineSplits[ multileneKey ].substring( 1 );
multilineSplits[ multileneKey ] = `${ pref }${ multilineSplits[ multileneKey ] }`;
_.map.extend( result, multilineSplits );
multilineKeyIs = false;
i -= 1;
}
}
if( i === src.length && multilineKeyIs )
{
let pref = prefix.join( '\n' );
multilineSplits[ multileneKey ] = multilineSplits[ multileneKey ].substring( 1 );
multilineSplits[ multileneKey ] = `${ pref }${ multilineSplits[ multileneKey ] }`;
_.map.extend( result, multilineSplits );
}
}
else
{
_.map.extend( result, splits );
}
}
else
{
_.map.extend( result, splits );
}
}
return result;
const jsYaml = require( 'js-yaml' );
return jsYaml.load( src ) || {};
}

//
Expand Down
10 changes: 5 additions & 5 deletions test/Action.test.s
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ function retryFetchActionWithSubdirectory( test )
{
test.case = 'subdirectory, action with tag';
core.exportVariable( `INPUT_ACTION`, `${ testAction }/subaction@v0.0.11` );
core.exportVariable( `INPUT_WITH`, 'multiline: |\n one\n two,\nstring : |' );
core.exportVariable( `INPUT_WITH`, 'multiline: |\n one\n two,\nstring : "|"' );
core.exportVariable( `INPUT_ATTEMPT_LIMIT`, '4' );
return null;
});
Expand All @@ -436,7 +436,7 @@ function retryFetchActionWithSubdirectory( test )
{
test.case = 'subdirectory, action with tag';
core.exportVariable( `INPUT_ACTION`, `${ testAction }/subaction@366f895` );
core.exportVariable( `INPUT_WITH`, 'multiline: |\n one\n two,\nstring : |' );
core.exportVariable( `INPUT_WITH`, 'multiline: |\n one\n two,\nstring : "|"' );
core.exportVariable( `INPUT_ATTEMPT_LIMIT`, '4' );
return null;
});
Expand Down Expand Up @@ -492,7 +492,7 @@ function retryWithMultilineOptionInOptionWith( test )
{
test.case = 'all inputs are valid - multiline string has two or more lines, string is |';
core.exportVariable( `INPUT_ACTION`, testAction );
core.exportVariable( `INPUT_WITH`, 'multiline: |\n one\n two,\nstring : |' );
core.exportVariable( `INPUT_WITH`, 'multiline: |\n one\n two,\nstring : "|"' );
core.exportVariable( `INPUT_ATTEMPT_LIMIT`, '4' );
return null;
});
Expand All @@ -516,7 +516,7 @@ function retryWithMultilineOptionInOptionWith( test )
{
test.case = 'multiline string has single line';
core.exportVariable( `INPUT_ACTION`, testAction );
core.exportVariable( `INPUT_WITH`, 'multiline: |\n one,\nstring : |' );
core.exportVariable( `INPUT_WITH`, 'multiline: |\n one,\nstring : "|"' );
core.exportVariable( `INPUT_ATTEMPT_LIMIT`, '4' );
return null;
});
Expand Down Expand Up @@ -1214,7 +1214,7 @@ function retryActionWithDefaultInputs( test )
{
test.case = 'rewrite default bool value';
core.exportVariable( `INPUT_ACTION`, testAction );
core.exportVariable( `INPUT_WITH`, 'value: some\nbool: false\nbool_default:false' );
core.exportVariable( `INPUT_WITH`, 'value: some\nbool: false\nbool_default: false' );
core.exportVariable( `INPUT_ATTEMPT_LIMIT`, '4' );
return null;
});
Expand Down
24 changes: 17 additions & 7 deletions test/Command.test.s
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ function retryCheckRetryTime( test )
{
test.case = 'command is succeful and overflows time limit';
core.exportVariable( 'INPUT_COMMAND', '|\n sleep 10 \n echo str' );
core.exportVariable( 'INPUT_TIME_OUT', '5000' );
core.exportVariable( 'INPUT_TIME_OUT', '3000' );
core.exportVariable( 'INPUT_ATTEMPT_LIMIT', '4' );
return null;
});
Expand All @@ -523,11 +523,16 @@ function retryCheckRetryTime( test )
test.identical( op.exitCode, 1 );
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' ), 0 );
if( process.platform === 'win32' )
test.identical( _.strCount( op.output, '::error::Process returned exit code 1' ), 1 );
{
test.le( _.strCount( op.output, 'str' ), 1 );
test.identical( _.strCount( op.output, '::error::Process returned exit code 1' ), 1 );
}
else
test.identical( _.strCount( op.output, '::error::Process was killed by exit signal SIGTERM' ), 1 );
{
test.identical( _.strCount( op.output, 'str' ), 0 );
test.identical( _.strCount( op.output, '::error::Process was killed by exit signal SIGTERM' ), 1 );
}
return null;
});

Expand Down Expand Up @@ -579,11 +584,16 @@ function retryCheckRetryTime( test )
test.identical( op.exitCode, 1 );
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 );
if( process.platform === 'win32' )
test.identical( _.strCount( op.output, '::error::Process returned exit code 1' ), 1 );
{
test.le( _.strCount( op.output, 'str' ), 2 );
test.identical( _.strCount( op.output, '::error::Process returned exit code 1' ), 1 );
}
else
test.identical( _.strCount( op.output, '::error::Process was killed by exit signal SIGTERM' ), 1 );
{
test.identical( _.strCount( op.output, 'str' ), 1 );
test.identical( _.strCount( op.output, '::error::Process was killed by exit signal SIGTERM' ), 1 );
}
return null;
});

Expand Down
Loading

0 comments on commit 5fe5493

Please sign in to comment.