From 2916488031a70f69234a8b588d773fba59c0d50e Mon Sep 17 00:00:00 2001 From: dmvict Date: Fri, 12 Apr 2024 08:25:18 +0300 Subject: [PATCH 1/4] Extend routine `contextGet`, add resolving of `steps` context --- src/Common.js | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/Common.js b/src/Common.js index 4afaafb8..fcd032a1 100644 --- a/src/Common.js +++ b/src/Common.js @@ -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 From ce1cceb7480fb4e2baaa64aa2f04887b1577765a Mon Sep 17 00:00:00 2001 From: dmvict Date: Fri, 12 Apr 2024 08:25:32 +0300 Subject: [PATCH 2/4] Add context `steps` to action declaration --- action.yml | 8 ++++++-- main/action.yml | 8 ++++++-- post/action.yml | 8 ++++++-- pre/action.yml | 8 ++++++-- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/action.yml b/action.yml index d11e8b47..c2e12927 100644 --- a/action.yml +++ b/action.yml @@ -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 resolve all inputs. If you need valid context `inputs`, then add option as described in `Readme.md`.' + required: false + default: '{}' job_context: description: 'Pass context `job` into an external action. Default is context `job` of a job.' required: false @@ -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: diff --git a/main/action.yml b/main/action.yml index afd8d488..c509fd2f 100644 --- a/main/action.yml +++ b/main/action.yml @@ -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 resolve all inputs. If you need valid context `inputs`, then add option as described in `Readme.md`.' + required: false + default: '{}' job_context: description: 'Pass context `job` into an external action. Default is context `job` of a job.' required: false @@ -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: diff --git a/post/action.yml b/post/action.yml index 51d4381e..4ec066c4 100644 --- a/post/action.yml +++ b/post/action.yml @@ -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 resolve all inputs. If you need valid context `inputs`, then add option as described in `Readme.md`.' + required: false + default: '{}' job_context: description: 'Pass context `job` into an external action. Default is context `job` of a job.' required: false @@ -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: diff --git a/pre/action.yml b/pre/action.yml index 599335bc..c2e7889d 100644 --- a/pre/action.yml +++ b/pre/action.yml @@ -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 resolve all inputs. If you need valid context `inputs`, then add option as described in `Readme.md`.' + required: false + default: '{}' job_context: description: 'Pass context `job` into an external action. Default is context `job` of a job.' required: false @@ -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: From 7c2cc396bc3d67ef33e91f1c29713d567fec51db Mon Sep 17 00:00:00 2001 From: dmvict Date: Fri, 12 Apr 2024 08:39:19 +0300 Subject: [PATCH 3/4] Update action description, add info about steps context, update action descriptions --- Readme.md | 10 +++++++++- action.yml | 2 +- main/action.yml | 2 +- post/action.yml | 2 +- pre/action.yml | 2 +- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Readme.md b/Readme.md index 61223c75..0792eb64 100644 --- a/Readme.md +++ b/Readme.md @@ -33,7 +33,7 @@ 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`. - Retries actions with defined number of attempts ( default is 2 ). - Retries actions with defined delay between attempts ( default is 0 ). @@ -89,6 +89,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. @@ -97,6 +101,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. diff --git a/action.yml b/action.yml index c2e12927..23f41dbb 100644 --- a/action.yml +++ b/action.yml @@ -28,7 +28,7 @@ inputs: required: false default: ${{ toJSON( github ) }} 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`.' + 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: diff --git a/main/action.yml b/main/action.yml index c509fd2f..8e53d873 100644 --- a/main/action.yml +++ b/main/action.yml @@ -28,7 +28,7 @@ inputs: required: false default: ${{ toJSON( github ) }} 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`.' + 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: diff --git a/post/action.yml b/post/action.yml index 4ec066c4..743447d0 100644 --- a/post/action.yml +++ b/post/action.yml @@ -28,7 +28,7 @@ inputs: required: false default: ${{ toJSON( github ) }} 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`.' + 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: diff --git a/pre/action.yml b/pre/action.yml index c2e7889d..3a55ed3e 100644 --- a/pre/action.yml +++ b/pre/action.yml @@ -28,7 +28,7 @@ inputs: required: false default: ${{ toJSON( github ) }} 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`.' + 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: From bd0d1b8843af9925b0fcf634a9a63692a6571f3e Mon Sep 17 00:00:00 2001 From: dmvict Date: Mon, 15 Apr 2024 07:31:35 +0300 Subject: [PATCH 4/4] Update file `Readme`, add new feature description --- Readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Readme.md b/Readme.md index 0792eb64..a31aba81 100644 --- a/Readme.md +++ b/Readme.md @@ -34,6 +34,7 @@ It is a cause of failed jobs. For this case, the action `wretry.action` can retr - 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`, `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 ).