Skip to content

Commit

Permalink
Merge pull request #155 from dmvict/js_action
Browse files Browse the repository at this point in the history
READY: Add context `steps`
  • Loading branch information
dmvict committed Apr 16, 2024
2 parents 02960c7 + bd0d1b8 commit 7277ac9
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 22 deletions.
11 changes: 10 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ It is a cause of failed jobs. For this case, the action `wretry.action` can retr
- Default action always includes both `pre` and `post` stages. If an external action contains a `pre` and/or `post` stage, the action will also execute these stages.
- The repository includes subdirectories with alternative action setups that can skip the `pre` or/and `post` stages, as necessary.
- Action handles conditions in `JavaScript` and `Docker` actions ( fields `pre-if` and `post-if` ). Some conditions can be unsolvable and then action skips the stage.
- Resolves external action default inputs from next contexts : `github`, `env`, `job`, `matrix`, `inputs`.
- Resolves external action default inputs from next contexts : `github`, `env`, `job`, `matrix`, `steps`, `inputs`.
- Can resolve user-provided context `steps`.
- Retries actions with defined number of attempts ( default is 2 ).
- Retries actions with defined delay between attempts ( default is 0 ).

Expand Down Expand Up @@ -89,6 +90,10 @@ Pass context `env` into an external action. Action cannot resolve separate envir

Pass context `github` into an external action. Default is global context `github`.

### `inputs_context`

Pass context `inputs` into an external action. The action cannot resolve context `inputs` and resolves all inputs from passed options and action description. To pass correct inputs context you need to combine passed options into and stringified JSON object.

### `job_context`

Pass context `job` into an external action. Default is context `job` of a job.
Expand All @@ -97,6 +102,10 @@ Pass context `job` into an external action. Default is context `job` of a job.

Pass context `matrix` into an external action. Default is context `matrix` of a job.

### `steps_context`

Pass context `steps` into an external action. If you need valid context `steps`, then add option `steps_context : ${{ toJSON( steps ) }}`.

### `attempt_limit`

Set number of attempts. Default is 2.
Expand Down
8 changes: 6 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ inputs:
description: 'Pass context `github` into an external action. Default is global context `github`.'
required: false
default: ${{ toJSON( github ) }}
inputs_context:
description: 'Pass context `inputs` into an external action. The action cannot resolve context `inputs` and resolves all inputs from passed options and action description.'
required: false
default: '{}'
job_context:
description: 'Pass context `job` into an external action. Default is context `job` of a job.'
required: false
Expand All @@ -35,8 +39,8 @@ inputs:
description: 'Pass context `matrix` into an external action. Default is context `matrix` of a job.'
required: false
default: ${{ toJSON( matrix ) }}
inputs_context:
description: 'Pass context `inputs` into an external action. The action cannot resolve context `inputs` and resolve all inputs. If you need valid context `inputs`, then add option as described in `Readme.md`.'
steps_context:
description: 'Pass context `steps` into an external action. If you need valid context `steps`, then add option as described in `Readme.md`.'
required: false
default: '{}'
attempt_limit:
Expand Down
8 changes: 6 additions & 2 deletions main/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ inputs:
description: 'Pass context `github` into an external action. Default is global context `github`.'
required: false
default: ${{ toJSON( github ) }}
inputs_context:
description: 'Pass context `inputs` into an external action. The action cannot resolve context `inputs` and resolves all inputs from passed options and action description.'
required: false
default: '{}'
job_context:
description: 'Pass context `job` into an external action. Default is context `job` of a job.'
required: false
Expand All @@ -35,8 +39,8 @@ inputs:
description: 'Pass context `matrix` into an external action. Default is context `matrix` of a job.'
required: false
default: ${{ toJSON( matrix ) }}
inputs_context:
description: 'Pass context `inputs` into an external action. The action cannot resolve context `inputs` and resolve all inputs. If you need valid context `inputs`, then add option as described in `Readme.md`.'
steps_context:
description: 'Pass context `steps` into an external action. If you need valid context `steps`, then add option as described in `Readme.md`.'
required: false
default: '{}'
attempt_limit:
Expand Down
8 changes: 6 additions & 2 deletions post/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ inputs:
description: 'Pass context `github` into an external action. Default is global context `github`.'
required: false
default: ${{ toJSON( github ) }}
inputs_context:
description: 'Pass context `inputs` into an external action. The action cannot resolve context `inputs` and resolves all inputs from passed options and action description.'
required: false
default: '{}'
job_context:
description: 'Pass context `job` into an external action. Default is context `job` of a job.'
required: false
Expand All @@ -35,8 +39,8 @@ inputs:
description: 'Pass context `matrix` into an external action. Default is context `matrix` of a job.'
required: false
default: ${{ toJSON( matrix ) }}
inputs_context:
description: 'Pass context `inputs` into an external action. The action cannot resolve context `inputs` and resolve all inputs. If you need valid context `inputs`, then add option as described in `Readme.md`.'
steps_context:
description: 'Pass context `steps` into an external action. If you need valid context `steps`, then add option as described in `Readme.md`.'
required: false
default: '{}'
attempt_limit:
Expand Down
8 changes: 6 additions & 2 deletions pre/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ inputs:
description: 'Pass context `github` into an external action. Default is global context `github`.'
required: false
default: ${{ toJSON( github ) }}
inputs_context:
description: 'Pass context `inputs` into an external action. The action cannot resolve context `inputs` and resolves all inputs from passed options and action description.'
required: false
default: '{}'
job_context:
description: 'Pass context `job` into an external action. Default is context `job` of a job.'
required: false
Expand All @@ -35,8 +39,8 @@ inputs:
description: 'Pass context `matrix` into an external action. Default is context `matrix` of a job.'
required: false
default: ${{ toJSON( matrix ) }}
inputs_context:
description: 'Pass context `inputs` into an external action. The action cannot resolve context `inputs` and resolve all inputs. If you need valid context `inputs`, then add option as described in `Readme.md`.'
steps_context:
description: 'Pass context `steps` into an external action. If you need valid context `steps`, then add option as described in `Readme.md`.'
required: false
default: '{}'
attempt_limit:
Expand Down
16 changes: 3 additions & 13 deletions src/Common.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,10 @@ function contextGet( contextName )
githubContext = githubContextUpdate( githubContext );
return githubContext;
}
else if( contextName === 'job' )
else if( [ 'job', 'matrix', 'inputs', 'steps' ].includes( contextName ) )
{
const jobContext = JSON.parse( core.getInput( 'job_context' ) );
return jobContext;
}
else if( contextName === 'matrix' )
{
const matrixContext = JSON.parse( core.getInput( 'matrix_context' ) );
return matrixContext;
}
else if( contextName === 'inputs' )
{
const inputsContext = JSON.parse( core.getInput( 'inputs_context' ) );
return inputsContext;
const context = JSON.parse( core.getInput( `${ contextName }_context` ) );
return context;
}

_.sure
Expand Down

0 comments on commit 7277ac9

Please sign in to comment.