Skip to content

Commit

Permalink
Merge pull request #56 from dmvict/context
Browse files Browse the repository at this point in the history
READY : Add trivial implementation of `job` context
  • Loading branch information
Wandalen authored Jun 18, 2022
2 parents 174870e + 03d69b9 commit 17e0b37
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 38 deletions.
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ inputs:
description: 'Setup working directory for the action. Works with only commands. Default is `github.workspace` path.'
required: false
github_token:
description: 'Get runner secret key. Extends context `github` if it required. Not documented in file `Readme.md`.'
description: 'Get runner secret key. It is autooption to extends context `github` for an external action. Not documented in file `Readme.md`.'
required: false
default: ${{ github.token }}
job_status:
description: 'Get job status. It is autooption to extends context `job` for an external action. Not documented in file `Readme.md`.'
required: false
default: ${{ job.status }}
attempt_limit:
description: 'Number of attempts'
required: false
Expand Down
80 changes: 45 additions & 35 deletions src/Common.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,54 +110,64 @@ function envOptionsFrom( options, inputs )

function getContext( contextName )
{
if( contextName === "env" )
if( contextName === 'env' )
{
return process.env;
}
else if( contextName === "github" )
else if( contextName === 'github' )
{
if( ActionsGithub === null )
{
ActionsGithub = require( '@actions/github' );

const remoteActionPath = remotePathFromActionName( process.env.RETRY_ACTION );
const localActionPath = _.path.nativize( _.path.join( __dirname, '../../../', remoteActionPath.repo ) );
ActionsGithub.context.action_path = localActionPath;
ActionsGithub.context.action_ref = remoteActionPath.tag;
ActionsGithub.context.action_repository = process.env.GITHUB_ACTION_REPOSITORY;
// ActionsGithub.context.action_status = undefined;
ActionsGithub.context.api_url = ActionsGithub.context.apiUrl;
ActionsGithub.context.base_ref = process.env.GITHUB_BASE_REF;
ActionsGithub.context.env = process.env.GITHUB_ENV;
ActionsGithub.context.event = ActionsGithub.context.payload;
ActionsGithub.context.event_name = ActionsGithub.context.eventName;
ActionsGithub.context.event_path = process.env.GITHUB_EVENT_PATH;
ActionsGithub.context.graphql_url = ActionsGithub.context.graphqlUrl;
ActionsGithub.context.head_ref = process.env.GITHUB_HEAD_REF;
ActionsGithub.context.job = process.env.GITHUB_JOB;
ActionsGithub.context.ref_name = process.env.GITHUB_REF_NAME;
ActionsGithub.context.ref_protected = process.env.GITHUB_REF_PROTECTED;
ActionsGithub.context.ref_type = process.env.GITHUB_REF_TYPE;
ActionsGithub.context.path = process.env.GITHUB_PATH;
ActionsGithub.context.repository = process.env.GITHUB_REPOSITORY;
ActionsGithub.context.repository_owner = process.env.GITHUB_REPOSITORY_OWNER;
ActionsGithub.context.repositoryUrl = `https://github.com/${process.env.GITHUB_REPOSITORY}.git`;
ActionsGithub.context.retention_days = process.env.GITHUB_RETENTION_DAYS;
ActionsGithub.context.run_id = ActionsGithub.context.runId;
ActionsGithub.context.run_number = ActionsGithub.context.runNumber;
ActionsGithub.context.run_attempt = process.env.GITHUB_RUN_ATTEMPT;
ActionsGithub.context.server_url = ActionsGithub.context.serverUrl;
ActionsGithub.context.sha = ActionsGithub.context.sha;
ActionsGithub.context.token = core.getInput( "github_token" );
ActionsGithub.context.workflow = ActionsGithub.context.workflow;
ActionsGithub.context.workspace = process.env.GITHUB_WORKSPACE;
setupGithubContext( ActionsGithub );
}

return ActionsGithub.context;
}
else if( contextName === 'job' )
{
const status = core.getInput( 'job_status' );
return { status };
}

_.assert( false, `The requested context "${ contextName }" does not supported by action.` );
}

/* */

function setupGithubContext( github )
{
const remoteActionPath = remotePathFromActionName( process.env.RETRY_ACTION );
const localActionPath = _.path.nativize( _.path.join( __dirname, '../../../', remoteActionPath.repo ) );
github.context.action_path = localActionPath;
github.context.action_ref = remoteActionPath.tag;
github.context.action_repository = process.env.GITHUB_ACTION_REPOSITORY;
// github.context.action_status = undefined;
github.context.api_url = github.context.apiUrl;
github.context.base_ref = process.env.GITHUB_BASE_REF;
github.context.env = process.env.GITHUB_ENV;
github.context.event = github.context.payload;
github.context.event_name = github.context.eventName;
github.context.event_path = process.env.GITHUB_EVENT_PATH;
github.context.graphql_url = github.context.graphqlUrl;
github.context.head_ref = process.env.GITHUB_HEAD_REF;
github.context.job = process.env.GITHUB_JOB;
github.context.ref_name = process.env.GITHUB_REF_NAME;
github.context.ref_protected = process.env.GITHUB_REF_PROTECTED;
github.context.ref_type = process.env.GITHUB_REF_TYPE;
github.context.path = process.env.GITHUB_PATH;
github.context.repository = process.env.GITHUB_REPOSITORY;
github.context.repository_owner = process.env.GITHUB_REPOSITORY_OWNER;
github.context.repositoryUrl = `https://github.com/${process.env.GITHUB_REPOSITORY}.git`;
github.context.retention_days = process.env.GITHUB_RETENTION_DAYS;
github.context.run_id = github.context.runId;
github.context.run_number = github.context.runNumber;
github.context.run_attempt = process.env.GITHUB_RUN_ATTEMPT;
github.context.server_url = github.context.serverUrl;
github.context.sha = github.context.sha;
github.context.token = core.getInput( 'github_token' );
github.context.workflow = github.context.workflow;
github.context.workspace = process.env.GITHUB_WORKSPACE;
}
}

//
Expand Down
5 changes: 3 additions & 2 deletions src/Retry.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ function retry( scriptType )
const optionsStrings = core.getMultilineInput( 'with' );
const options = common.actionOptionsParse( optionsStrings );
_.map.sureHasOnly( options, config.inputs );
const envOptions = common.envOptionsFrom( options, config.inputs );
common.envOptionsSetup( envOptions );

if( _.strBegins( config.runs.using, 'node' ) )
{
const envOptions = common.envOptionsFrom( options, config.inputs );
common.envOptionsSetup( envOptions );

const runnerPath = _.path.nativize( _.path.join( __dirname, 'Runner.js' ) );
const scriptPath = _.path.nativize( _.path.join( localActionPath, config.runs[ scriptType ] ) );
routine = () =>
Expand Down

0 comments on commit 17e0b37

Please sign in to comment.