From 25c7416bc43e554f6bb3691eed194b58cbc6b282 Mon Sep 17 00:00:00 2001 From: "Federico M. Facca" Date: Wed, 28 Jun 2023 12:02:42 +0200 Subject: [PATCH 1/5] update action.yml to include dry_no_fail --- action.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/action.yml b/action.yml index 06b48d4..2a61bd8 100644 --- a/action.yml +++ b/action.yml @@ -34,6 +34,10 @@ inputs: description: Running the script in dry mode just shows whether there are files that should be prettified or not required: false default: false + dry_no_fail: + description: Dry mode do not exit the process in case of changes (so that other follow up actions can take care of commits) + required: false + default: false prettier_version: description: Specific version of prettier (by default just use the latest version) required: false @@ -76,6 +80,7 @@ runs: INPUT_FILE_PATTERN: ${{ inputs.file_pattern }} INPUT_PRETTIER_OPTIONS: ${{ inputs.prettier_options }} INPUT_DRY: ${{ inputs.dry }} + INPUT_DRY_NO_FAIL: ${{ inputs.dry_no_fail }} INPUT_PRETTIER_VERSION: ${{ inputs.prettier_version }} INPUT_ONLY_CHANGED: ${{ inputs.only_changed }} INPUT_PRETTIER_PLUGINS: ${{ inputs.prettier_plugins }} From 8c19a692a528f8d9a0f546ee72066d771821bf46 Mon Sep 17 00:00:00 2001 From: "Federico M. Facca" Date: Wed, 28 Jun 2023 12:05:57 +0200 Subject: [PATCH 2/5] Update entrypoint.sh to support dry_no_fail --- entrypoint.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index d32a8d5..f9ee855 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -79,8 +79,12 @@ if _git_changed; then if $INPUT_DRY; then echo "Unpretty Files Changes:" git diff - echo "Finishing dry-run. Exiting before committing." - exit 1 + if INPUT_DRY_NO_FAIL; then + echo "There are chaanges that won't be commited, you can use an external job to do so". + else + echo "Finishing dry-run. Exiting before committing." + exit 1 + fi else # Calling method to configure the git environemnt _git_setup From 14297a22653480d3a44078d90de474fe13466dd8 Mon Sep 17 00:00:00 2001 From: "Federico M. Facca" Date: Wed, 28 Jun 2023 12:07:34 +0200 Subject: [PATCH 3/5] document dry_no_fail --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 1fa212a..28dd35c 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ A GitHub action for styling files with [prettier](https://prettier.io). | Parameter | Required | Default | Description | | - | :-: | :-: | - | | dry | :x: | `false` | Runs the action in dry mode. Files wont get changed and the action fails if there are unprettified files. Recommended to use with prettier_options --check | +| dry_no_fail | :x: | `false` | Don't exit the process in case of changes. This allows the commit and push to a repo to be handled by a follow up step | | prettier_version | :x: | `latest` | Specific prettier version (by default use latest) | | working_directory | :x: | `${{ github.action_path }}` | Specify a directory to cd into before installing prettier and running it, use relative file path to the repository root for example `app/` | | prettier_options | :x: | `"--write **/*.js"` | Prettier options (by default it applies to the whole repository) | From f3c53282aaa8257962ec501b16a90671e31af01e Mon Sep 17 00:00:00 2001 From: "Federico M. Facca" Date: Wed, 28 Jun 2023 12:23:59 +0200 Subject: [PATCH 4/5] fix bug --- entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index f9ee855..2e4ce85 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -79,8 +79,8 @@ if _git_changed; then if $INPUT_DRY; then echo "Unpretty Files Changes:" git diff - if INPUT_DRY_NO_FAIL; then - echo "There are chaanges that won't be commited, you can use an external job to do so". + if $INPUT_DRY_NO_FAIL; then + echo "There are changes that won't be commited, you can use an external job to do so". else echo "Finishing dry-run. Exiting before committing." exit 1 From d7bee14f9900dd80e91d3d998ce037cd06ffa509 Mon Sep 17 00:00:00 2001 From: Conrad Date: Thu, 20 Jul 2023 16:38:23 +0200 Subject: [PATCH 5/5] Reworked DRY_NO_FAIL to NO_COMMIT option --- README.md | 2 +- action.yml | 6 +++--- entrypoint.sh | 9 +++++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 28dd35c..0df6c6f 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ A GitHub action for styling files with [prettier](https://prettier.io). | Parameter | Required | Default | Description | | - | :-: | :-: | - | | dry | :x: | `false` | Runs the action in dry mode. Files wont get changed and the action fails if there are unprettified files. Recommended to use with prettier_options --check | -| dry_no_fail | :x: | `false` | Don't exit the process in case of changes. This allows the commit and push to a repo to be handled by a follow up step | +| no_commit | :x: | `false` | Can be used to avoid committing the changes (useful when another workflow step commits after this one anyways; can be combined with dry mode) | | prettier_version | :x: | `latest` | Specific prettier version (by default use latest) | | working_directory | :x: | `${{ github.action_path }}` | Specify a directory to cd into before installing prettier and running it, use relative file path to the repository root for example `app/` | | prettier_options | :x: | `"--write **/*.js"` | Prettier options (by default it applies to the whole repository) | diff --git a/action.yml b/action.yml index 2a61bd8..c8232ef 100644 --- a/action.yml +++ b/action.yml @@ -34,8 +34,8 @@ inputs: description: Running the script in dry mode just shows whether there are files that should be prettified or not required: false default: false - dry_no_fail: - description: Dry mode do not exit the process in case of changes (so that other follow up actions can take care of commits) + no_commit: + description: Can be used to avoid committing the changes (can be combined with dry mode, useful when another workflow steps commits after this commit anyways) required: false default: false prettier_version: @@ -80,7 +80,7 @@ runs: INPUT_FILE_PATTERN: ${{ inputs.file_pattern }} INPUT_PRETTIER_OPTIONS: ${{ inputs.prettier_options }} INPUT_DRY: ${{ inputs.dry }} - INPUT_DRY_NO_FAIL: ${{ inputs.dry_no_fail }} + INPUT_DRY_NO_COMMIT: ${{ inputs.no_commit }} INPUT_PRETTIER_VERSION: ${{ inputs.prettier_version }} INPUT_ONLY_CHANGED: ${{ inputs.only_changed }} INPUT_PRETTIER_PLUGINS: ${{ inputs.prettier_plugins }} diff --git a/entrypoint.sh b/entrypoint.sh index 2e4ce85..c7e4588 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -79,8 +79,8 @@ if _git_changed; then if $INPUT_DRY; then echo "Unpretty Files Changes:" git diff - if $INPUT_DRY_NO_FAIL; then - echo "There are changes that won't be commited, you can use an external job to do so". + if $INPUT_NO_COMMIT; then + echo "There are changes that won't be commited, you can use an external job to do so." else echo "Finishing dry-run. Exiting before committing." exit 1 @@ -103,6 +103,11 @@ if _git_changed; then git add "${INPUT_FILE_PATTERN}" || echo "Problem adding your files with pattern ${INPUT_FILE_PATTERN}" fi + if $INPUT_NO_COMMIT; then + echo "There are changes that won't be commited, you can use an external job to do so." + exit 0 + fi + # Commit and push changes back if $INPUT_SAME_COMMIT; then echo "Amending the current commit..."