Skip to content

Commit

Permalink
Merge pull request #154 from dmvict/master
Browse files Browse the repository at this point in the history
READY: Add alternative action files related to `js_action` branch
  • Loading branch information
dmvict authored Apr 11, 2024
2 parents 7afe8a7 + c265e65 commit b7882d3
Show file tree
Hide file tree
Showing 8 changed files with 266 additions and 8 deletions.
29 changes: 28 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ It is a cause of failed jobs. For this case, the action `wretry.action` can retr
- Retries shell commands. Uses default shells to run commands.
- Can retry single action or single command ( multiline command ), but not both simultaneously.
- Retries `main`, `pre` and `post` stages of external actions.
- Always has `pre` and `post` stages. If external action has `pre` or/and `post` stage, then action run it also.
- 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`.
- Retries actions with defined number of attempts ( default is 2 ).
Expand Down Expand Up @@ -148,6 +149,32 @@ jobs:
To setup job output we access output `outputs` of the step `my-action`. In the job `job2` we parse this output to JSON. The environment variable `OUPUT1` represents full JSON and the variable `OUPUT2` represents key `foo` of the parsed JSON.

## How to skip `pre` or/and `post` stages

The repository provides three subdirectories, each containing a different setup for action retries:

- `pre`: This directory retries the `pre` and `main` stages.
- `post`: This directory retries the `main` and `post` stages.
- `main`: This directory retries only the `main` stage.

It is crucial to note that, regardless of the retried action specification, the actions in the repository will only execute the declared stages. This behavior can disrupt your workflow, so please use the actions with caution.

### Selecting the Alternative Action

You have a few options for obtaining a compatible action implementation:
- Run the workflow with the required action, but without the `wretry.action`, and check the stages in the workflow run.
- Open the action directory and review the `action.yml` file. Look for any extra stages listed besides `main`.
- If you run command, then you can get `main` action that skips `pre` and `post` stages.

### Declaration of alternative action

To choose an alternative action add the action subdirectory in declaration of `wretry.action`. For example, the declaration with `main` subdirectory:
```yml
- uses: Wandalen/wretry.action/main@master
```

You can choose either method based on your preference. If you prefer not to perform additional manipulations, you can select the default `wretry.action` that retries all available stages of the external action.

## Example usage

### Retry action
Expand Down
5 changes: 5 additions & 0 deletions main/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner2-direct.svg)](https://stand-with-ukraine.pp.ua)

# action::retry [![status](https://github.com/Wandalen/wretry.action/actions/workflows/wRetryActionPublish.yml/badge.svg)](https://github.com/Wandalen/wretry.action/actions/workflows/wRetryActionPublish.yml) [![stable](https://img.shields.io/badge/stability-stable-brightgreen.svg)](https://github.com/emersion/stability-badges#stable)

An alternative [action](../Readme.md) declaration that skips `pre` and `post` stages. It is useful for retrying actions with only `main` stage.
70 changes: 70 additions & 0 deletions main/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: retry action
author: |
Wandalen <[email protected]>
dmvict <[email protected]>
branding:
icon: activity
color: white
description: Retries an Github Action step on failure
inputs:
action:
description: 'Github action name. Should be defined action or command, not both.'
required: false
command:
description: 'Command to run. Should be defined action or command, not both.'
required: false
with:
description: An options map for Github action
required: false
current_path:
description: >-
Setup working directory for the action. Works with only commands. Default
is `github.workspace` path.
required: false
attempt_limit:
description: Number of attempts
required: false
default: 2
attempt_delay:
description: A delay between attempts in ms
required: false
default: 0
time_out:
description: >-
Set time out in ms for entire step including all retries. By default
actions sets no time out.
required: false
default: false
retry_condition:
description: >-
Use any valid expression to decide the continuation of retries. Default
value is true.
required: false
default: true
github_token:
description: A token to access private actions. Does not required for public actions.
required: false
outputs:
outputs:
description: A pretty print JSON map with outputs from the wrapped action.
value: '${{ toJSON( steps.retry.outputs ) }}'
runs:
using: composite
steps:
- name: retry
id: retry
uses: Wandalen/wretry.action/main@js_action
with:
action: '${{ inputs.action }}'
command: '${{ inputs.command }}'
with: '${{ inputs.with }}'
current_path: '${{ inputs.current_path }}'
attempt_limit: '${{ inputs.attempt_limit }}'
attempt_delay: '${{ inputs.attempt_delay }}'
retry_condition: '${{ inputs.retry_condition }}'
env_context: '${{ toJSON( env ) }}'
github_context: '${{ toJSON( github ) }}'
job_context: '${{ toJSON( job ) }}'
matrix_context: '${{ toJSON( matrix ) }}'
time_out: '${{ inputs.time_out }}'
github_token: '${{ inputs.github_token }}'
5 changes: 5 additions & 0 deletions post/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner2-direct.svg)](https://stand-with-ukraine.pp.ua)

# action::retry [![status](https://github.com/Wandalen/wretry.action/actions/workflows/wRetryActionPublish.yml/badge.svg)](https://github.com/Wandalen/wretry.action/actions/workflows/wRetryActionPublish.yml) [![stable](https://img.shields.io/badge/stability-stable-brightgreen.svg)](https://github.com/emersion/stability-badges#stable)

An alternative [action](../Readme.md) declaration that skips `pre` stage. It is useful for retrying actions with `post` stage.
70 changes: 70 additions & 0 deletions post/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: retry action
author: |
Wandalen <[email protected]>
dmvict <[email protected]>
branding:
icon: activity
color: white
description: Retries an Github Action step on failure
inputs:
action:
description: 'Github action name. Should be defined action or command, not both.'
required: false
command:
description: 'Command to run. Should be defined action or command, not both.'
required: false
with:
description: An options map for Github action
required: false
current_path:
description: >-
Setup working directory for the action. Works with only commands. Default
is `github.workspace` path.
required: false
attempt_limit:
description: Number of attempts
required: false
default: 2
attempt_delay:
description: A delay between attempts in ms
required: false
default: 0
time_out:
description: >-
Set time out in ms for entire step including all retries. By default
actions sets no time out.
required: false
default: false
retry_condition:
description: >-
Use any valid expression to decide the continuation of retries. Default
value is true.
required: false
default: true
github_token:
description: A token to access private actions. Does not required for public actions.
required: false
outputs:
outputs:
description: A pretty print JSON map with outputs from the wrapped action.
value: '${{ toJSON( steps.retry.outputs ) }}'
runs:
using: composite
steps:
- name: retry
id: retry
uses: Wandalen/wretry.action/post@js_action
with:
action: '${{ inputs.action }}'
command: '${{ inputs.command }}'
with: '${{ inputs.with }}'
current_path: '${{ inputs.current_path }}'
attempt_limit: '${{ inputs.attempt_limit }}'
attempt_delay: '${{ inputs.attempt_delay }}'
retry_condition: '${{ inputs.retry_condition }}'
env_context: '${{ toJSON( env ) }}'
github_context: '${{ toJSON( github ) }}'
job_context: '${{ toJSON( job ) }}'
matrix_context: '${{ toJSON( matrix ) }}'
time_out: '${{ inputs.time_out }}'
github_token: '${{ inputs.github_token }}'
5 changes: 5 additions & 0 deletions pre/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner2-direct.svg)](https://stand-with-ukraine.pp.ua)

# action::retry [![status](https://github.com/Wandalen/wretry.action/actions/workflows/wRetryActionPublish.yml/badge.svg)](https://github.com/Wandalen/wretry.action/actions/workflows/wRetryActionPublish.yml) [![stable](https://img.shields.io/badge/stability-stable-brightgreen.svg)](https://github.com/emersion/stability-badges#stable)

An alternative [action](../Readme.md) declaration that skips `post` stage. It is useful for retrying actions with `pre` stage.
70 changes: 70 additions & 0 deletions pre/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: retry action
author: |
Wandalen <[email protected]>
dmvict <[email protected]>
branding:
icon: activity
color: white
description: Retries an Github Action step on failure
inputs:
action:
description: 'Github action name. Should be defined action or command, not both.'
required: false
command:
description: 'Command to run. Should be defined action or command, not both.'
required: false
with:
description: An options map for Github action
required: false
current_path:
description: >-
Setup working directory for the action. Works with only commands. Default
is `github.workspace` path.
required: false
attempt_limit:
description: Number of attempts
required: false
default: 2
attempt_delay:
description: A delay between attempts in ms
required: false
default: 0
time_out:
description: >-
Set time out in ms for entire step including all retries. By default
actions sets no time out.
required: false
default: false
retry_condition:
description: >-
Use any valid expression to decide the continuation of retries. Default
value is true.
required: false
default: true
github_token:
description: A token to access private actions. Does not required for public actions.
required: false
outputs:
outputs:
description: A pretty print JSON map with outputs from the wrapped action.
value: '${{ toJSON( steps.retry.outputs ) }}'
runs:
using: composite
steps:
- name: retry
id: retry
uses: Wandalen/wretry.action/pre@js_action
with:
action: '${{ inputs.action }}'
command: '${{ inputs.command }}'
with: '${{ inputs.with }}'
current_path: '${{ inputs.current_path }}'
attempt_limit: '${{ inputs.attempt_limit }}'
attempt_delay: '${{ inputs.attempt_delay }}'
retry_condition: '${{ inputs.retry_condition }}'
env_context: '${{ toJSON( env ) }}'
github_context: '${{ toJSON( github ) }}'
job_context: '${{ toJSON( job ) }}'
matrix_context: '${{ toJSON( matrix ) }}'
time_out: '${{ inputs.time_out }}'
github_token: '${{ inputs.github_token }}'
20 changes: 13 additions & 7 deletions step/ActionWrite.s
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@ function actionWrite( frame )

/* */

const actionPath = fileProvider.path.join( module.dirPath, 'action.yml' );
const action = fileProvider.fileReadUnknown( actionPath );
action.runs.steps[ 0 ].uses = `Wandalen/wretry.action@v${ module.about.version }_js_action`;

logger.log( `Updating action. Setup used action version to "Wandalen/wretry.action@v${ module.about.version }_js_action".` );

fileProvider.fileWrite({ filePath : actionPath, data : action, encoding : 'yaml' });
const subdirectories = [ '', 'main', 'pre', 'post' ];
for( let i = 0 ; i < subdirectories.length ; i++ )
{
const slash = subdirectories[ i ] === '' ? '' : '/';
const actionRelativePath = `${ subdirectories[ i ] }${ slash }action.yml`;
const actionPath = fileProvider.path.join( module.dirPath, actionRelativePath );
const action = fileProvider.fileReadUnknown( actionPath );
action.runs.steps[ 0 ].uses = `Wandalen/wretry.action${ slash }${ subdirectories[ i ] }@v${ module.about.version }_js_action`;

logger.log( `Updating action file "${ actionRelativePath }". Setup action version to "${ action.runs.steps[ 0 ].uses }".` );

fileProvider.fileWrite({ filePath : actionPath, data : action, encoding : 'yaml' });
}
}

module.exports = actionWrite;

0 comments on commit b7882d3

Please sign in to comment.