From 552eff98a594685751b934af73a8a0929cb81483 Mon Sep 17 00:00:00 2001 From: Conrad Date: Wed, 6 May 2020 10:12:17 +0200 Subject: [PATCH] Added dry run parameter --- README.md | 2 ++ action.yml | 4 ++++ entrypoint.sh | 24 ++++++++++++++---------- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index b9a570c..aeee7ab 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ The following parameters can be used in your custom action configuration. | branch | :white_check_mark: | - | The specific branch you want to merge into. Use ${{ github.head_ref }} if you want to use this with pull requests. | | checkpath | :x: | '.' | The path autopep8 checks | | autoparameters | :x: | ' ' | Parameters to use with autopep8 | +| dry | :x: | false | Dry-run the action to fail when detecting PEP-8 uncompliant files, instead of automatically fixing them. | + ### Example diff --git a/action.yml b/action.yml index f45f6dc..2e82558 100644 --- a/action.yml +++ b/action.yml @@ -30,6 +30,10 @@ inputs: description: Parameters for autopep8 required: false default: '' + dry: + description: Should this script apply autopep8 directly or just warn? + required: false + default: false runs: using: 'docker' diff --git a/entrypoint.sh b/entrypoint.sh index 4555503..05a1f65 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -32,16 +32,20 @@ autopep8 -i -r $INPUT_CHECKPATH $INPUT_AUTOPARAMETERS || echo "Problem running a if ! git diff --quiet then - echo "Commiting and pushing changes." - # Calling method to configure the git environemnt - git_setup - # Switch to the actual branch - git checkout $INPUT_BRANCH - - git add "${INPUT_FILE_PATTERN}" - - git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" ${INPUT_COMMIT_OPTIONS:+"$INPUT_COMMIT_OPTIONS"} - git push --set-upstream origin "HEAD:$INPUT_BRANCH" + if $INPUT_DRY; then + echo "Found non-compliant files!" + exit 1 + else + # Calling method to configure the git environemnt + _git_setup + echo "Commiting and pushing changes..." + # Add changes to git + git add "${INPUT_FILE_PATTERN}" || echo "Problem adding your files with pattern ${INPUT_FILE_PATTERN}" + # Commit and push changes back + git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" ${INPUT_COMMIT_OPTIONS:+"$INPUT_COMMIT_OPTIONS"} + git push origin + echo "Changes pushed successfully." + fi else echo "Nothing to commit. Exiting." fi