diff --git a/README.md b/README.md index 61bb141..b17dcb0 100644 --- a/README.md +++ b/README.md @@ -20,11 +20,14 @@ A GitHub action for styling files with [prettier](https://prettier.io). | prettier_version | :x: | false | Specific prettier version (by default use latest) | | prettier_options | :x: | `--write **/*.js` | Prettier options (by default it applies to the whole repository) | | commit_options | :x: | - | Custom git commit options | +| same_commit | :x: | False | Whether to merge into the current commit instead of creating a new one | | commit_message | :x: | Prettified Code! | Custom git commit message | | file_pattern | :x: | * | Custom git add file pattern, can't be used with only_changed! | | branch (depreciated with 3.0)| :white_check_mark: | - | Always set this to `${{ github.head_ref }}` in order to work both with pull requests and push events | | only_changed | :x: | false | Only prettify changed files, can't be used with file_pattern! This command works only with the checkout action set to fetch depth '0' (Example 2)| +> Note: using the same_commit option may lead to problems if other actions are relying on the commit being the same before and after the prettier action has ran. Keep this in mind. + ### Example Config #### Example 1 (run on push in master) diff --git a/action.yml b/action.yml index 684b0f6..920f90c 100644 --- a/action.yml +++ b/action.yml @@ -8,6 +8,10 @@ inputs: description: Commit message required: false default: 'Prettified Code!' + same_commit: + description: Whether to use the current commit instead of creating a new one + required: false + default: false commit_options: description: Commit options required: false diff --git a/entrypoint.sh b/entrypoint.sh index 08fb28e..9b2eb5e 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -59,7 +59,12 @@ if _git_changed; then git add "${INPUT_FILE_PATTERN}" || echo "Problem adding your files with pattern ${INPUT_FILE_PATTERN}" fi # 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"} || echo "No files added to commit" + if $INPUT_SAME_COMMIT; then + echo "Amending the current commit..." + git commit --amend --no-edit + else + git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" ${INPUT_COMMIT_OPTIONS:+"$INPUT_COMMIT_OPTIONS"} || echo "No files added to commit" + fi git push origin echo "Changes pushed successfully." fi