Skip to content

Commit

Permalink
Remove auto commit functionality (#4)
Browse files Browse the repository at this point in the history
* Remove out-commit functionality

* Update README.md
  • Loading branch information
ArturWincenciak authored Apr 2, 2024
1 parent aecb1b5 commit d376cea
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 190 deletions.
71 changes: 3 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ Determines whether the action should fail if the code needs to be reformatted.
- Default: `no`
- Accepted values: `yes`, `no`

## `auto_commit`

Determines whether the action should automatically commit the changes made by the `ReSharper's CleanupCode Command-Line Tool`.

- Required: `false`
- Default: `yes`
- Accepted values: `yes`, `no`

## `jb_cleanup_code_arg`

Additional arguments to pass to the `ReSharper's CleanupCode Command-Line Tool`. Configure the tool with command-line parameters,
Expand All @@ -57,27 +49,6 @@ e.g.: `--verbosity=INFO --profile=Built-in: Full Cleanup --exclude=**UnitTests/*
- Required: `false`
- Default: `--verbosity=WARN`

## `commit_message`

The commit message to use if `auto_commit` is set to `yes`.

- Required: `false`
- Default: `Cleanup code`

## `commit_creator_email`

The email address to use for the git user who creates the commit if `auto_commit` is set to `yes`.

- Required: `false`
- Default: `[email protected]`

## `commit_creator_name`

The name to use for the git user who creates the commit if `auto_commit` is set to `yes`.

- Required: `false`
- Default: `CleanupCode GitHub Action`

# [ReSharper CLI CleanupCode GitHub Action Demo Usage](https://github.com/ArturWincenciak/ReSharper_CleanupCode_Demo)

In that demo project, you will find all the knowledge you need to effectively start using this action.
Expand All @@ -99,26 +70,6 @@ steps:
solution: 'ReSharperCleanupCodeDemo.sln'
```
That configuration means that the action does clean up and all cleaned up code will be committed and pushed into remote repo.
Commit will be performed with default commit message, git user email and name.
- default commit message: `Clean up code by ReSharper CLI CleanupCode Tool`
- default git user email: `[email protected]`
- default git user name: `CleanupCode Action`

## Change commit message, git user email and name

```yaml
steps:
- name: Cleanup Code
uses: ArturWincenciak/[email protected]
with:
solution: 'ReSharperCleanupCodeDemo.sln'
commit_message: 'Clean up the code'
commit_creator_email: '[email protected]'
commit_creator_name: 'Knuth Conway'
```

## Interrupt your CI/CD pipeline if Cleanup detected the code needs to be cleaned up
```yaml
Expand All @@ -133,7 +84,7 @@ steps:
If this setting is enabled, the process will stop and return an error code if it finds that the code needs to be cleaned
up. This can be helpful for stopping the pipeline from continuing if there are problems with the code.
## No interrupt and no clean up
## No interrupt your CI/CD pipeline if Cleanup detected the code needs to be cleaned up
```yaml
steps:
Expand All @@ -142,18 +93,10 @@ steps:
with:
solution: 'ReSharperCleanupCodeDemo.sln'
fail_on_reformat_needed: 'no'
auto_commit: 'no'
```
At times, you may want to disable automatic clean up code and continue with the execution of your CI/CD pipeline, for
instance, when you need to debug subsequent steps without performing clean up.

## Interrupt the pipeline vs Clean up code
Note that if you set the action to automatically clean up code (which can be very helpful), you risk encountering the
need to resolve conflicts later if you forget to pull the automatically-committed changes.
For some, interrupting the CI/CD pipeline and performing code cleanup locally in your IDE or by console command
may be a more convenient option.
At times, you may want to disable the interruption and continue with the execution of your CI/CD pipeline, for instance, when you need to debug subsequent steps without performing clean up.
### Perform clean up your code locally with a fully automated commit and save your time
Expand Down Expand Up @@ -198,11 +141,7 @@ jobs:
with:
solution: 'ReSharperCleanupCodeDemo.sln'
fail_on_reformat_needed: 'no'
auto_commit: 'yes'
jb_cleanup_code_arg: '--verbosity=INFO --profile=Built-in: Full Cleanup --exclude=**UnitTests/**.*'
commit_message: 'Cleanup code by ReSharper CLI CleanupCode GitHub Action'
commit_creator_email: '[email protected]'
commit_creator_name: 'Clean Up'
```
### Sequence of actions performed by the prepared GitHub Action
- `Checkout`: download the source code from the current repository where the Action was
Expand Down Expand Up @@ -252,15 +191,11 @@ jobs:
- name: Cleanup Code
id: cleanup
uses: ArturWincenciak/ReSharper_CleanupCode@v2.0
uses: ArturWincenciak/ReSharper_CleanupCode@v3.0
with:
solution: 'ReSharperCleanupCodeDemo.sln'
fail_on_reformat_needed: 'no'
auto_commit: 'yes'
jb_cleanup_code_arg: '--verbosity=INFO --profile=Almost Full Cleanup --exclude=**UnitTests/**.*'
commit_message: 'Cleanup code by ReSharper CLI CleanupCode GitHub Action'
commit_creator_email: '[email protected]'
commit_creator_name: 'CleanupCode Action'
inspection:
runs-on: ubuntu-latest
Expand Down
18 changes: 1 addition & 17 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,14 @@ inputs:
description: 'Determines whether the action should fail if the code needs to be reformatted'
required: false
default: 'no'
auto_commit:
description: 'Determines whether the action should automatically commit the changes made by the ReSharpers CleanupCode Command-Line Tool'
required: false
default: 'yes'
jb_cleanup_code_arg:
description: 'Additional arguments to pass to the ReSharpers CleanupCode Command-Line Tool. Configure the tool with command-line parameters e.g. --verbosity=INFO --profile=Built-in: Full Cleanup --exclude=**UnitTests/**.*'
required: false
default: '--verbosity=WARN'
commit_message:
description: 'The commit message to use if auto_commit is set to yes'
required: false
default: "Clean up code by ReSharper CLI CleanupCode Tool"
commit_creator_email:
description: 'The email address to use for the git user who creates the commit if auto_commit is set to yes'
required: false
default: "[email protected]"
commit_creator_name:
description: 'The name to use for the git user who creates the commit if auto_commit is set to yes'
required: false
default: "CleanupCode Action"

runs:
using: composite
steps:
- name: Run Script
run: ${GITHUB_ACTION_PATH}/entrypoint.sh "${{ inputs.solution }}" "${{ inputs.fail_on_reformat_needed }}" "${{ inputs.auto_commit }}" "${{ inputs.jb_cleanup_code_arg }}" "${{ inputs.commit_message }}" "${{ inputs.commit_creator_email }}" "${{ inputs.commit_creator_name }}"
run: ${GITHUB_ACTION_PATH}/entrypoint.sh "${{ inputs.solution }}" "${{ inputs.fail_on_reformat_needed }}" "${{ inputs.jb_cleanup_code_arg }}"
shell: bash
107 changes: 2 additions & 105 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,15 @@ EXIT_WITH_FAST_FAIL=2

INPUT_SOLUTION=$1
INPUT_FAIL_ON_REFORMAT_NEEDED=$2
INPUT_AUTO_COMMIT=$3
INPUT_JB_CLEANUP_CODE_ARG=$4
INPUT_COMMIT_MESSAGE=$5
INPUT_COMMIT_CREATOR_EMAIL=$6
INPUT_COMMIT_CREATOR_NAME=$7
INPUT_JB_CLEANUP_CODE_ARG=$3

echo ""
echo "--- --- ---"
echo "Alright GitHub Action Cleanup Code Command-Line Tool"
echo "Your setup:"
echo "- Solution: [${INPUT_SOLUTION}]"
echo "- Fail on re-format needed: [${INPUT_FAIL_ON_REFORMAT_NEEDED}]"
echo "- Auto commit re-formatted code: [${INPUT_AUTO_COMMIT}]"
echo "- ReSharper CLI CleanupCode arguments: [${INPUT_JB_CLEANUP_CODE_ARG}]"
echo "- Commit message: [${INPUT_COMMIT_MESSAGE}]"
echo "- Commit creator (git user) e-mail: [${INPUT_COMMIT_CREATOR_EMAIL}]"
echo "- Commit creator (git user) name: [${INPUT_COMMIT_CREATOR_NAME}]"
if [ "${INPUT_FAIL_ON_REFORMAT_NEEDED}" = "yes" ] && [ "${INPUT_AUTO_COMMIT}" = "yes" ]; then
echo "NOTICE: you have set that the execution will fast fail on re-format needed"
echo "NOTICE: auto commit will not be executed because the execution will terminate with fail when re-format is needed"
echo "NOTICE: if you want to auto commit execute call the script with '-f no -a yes' arguments"
fi
echo "--- --- ---"
echo ""

Expand All @@ -49,16 +36,6 @@ if [ "${INPUT_FAIL_ON_REFORMAT_NEEDED}" != "yes" ] && [ "${INPUT_FAIL_ON_REFORMA
exit ${INVALID_ARGUMENT_ERROR}
fi

if [ "${INPUT_AUTO_COMMIT}" != "yes" ] && [ "${INPUT_AUTO_COMMIT}" != "no" ]; then
echo ""
echo "--- --- ---"
echo "INVALID ARGUMENT OF '-a' equals '${INPUT_AUTO_COMMIT}'"
echo "Set 'yes' or 'no' or omit to use default equals 'no'"
echo "--- --- ---"
echo ""
exit ${INVALID_ARGUMENT_ERROR}
fi

#
# Parse arguments and put them into an array to call command
# I'm at a loss for words to describe how I managed to nail this function
Expand Down Expand Up @@ -119,84 +96,4 @@ if [ "${INPUT_FAIL_ON_REFORMAT_NEEDED}" = "yes" ]; then
exit ${EXIT_WITH_FAST_FAIL}
fi

if [ "${INPUT_AUTO_COMMIT}" = "no" ]; then
echo ""
echo "--- --- ---"
echo "There is re-formatted code but it will not be auto committed"
echo "--- --- ---"
echo ""
exit ${SUCCESS}
fi

echo ""
echo "--- --- ---"
echo "There is re-formatted code to be committed"
echo "--- --- ---"
echo ""

git diff --name-only

echo ""
echo "--- --- ---"
echo "Git Diff"
echo "--- --- ---"
echo ""

git diff

echo ""
echo "--- --- ---"
echo "Add all changes to stage"
echo "--- --- ---"
echo ""

git add .

echo ""
echo "--- --- ---"
echo "Staged files to be committed"
echo "--- --- ---"
echo ""

git diff --staged --name-only

echo ""
echo "--- --- ---"
echo "Creating commit"
echo "--- --- ---"
echo ""

git config --global user.email "${INPUT_COMMIT_CREATOR_EMAIL}"
git config --global user.name "${INPUT_COMMIT_CREATOR_NAME}"
git commit -m "${INPUT_COMMIT_MESSAGE}"

echo ""
echo "--- --- ---"
echo "Commit has been created"
echo "--- --- ---"
echo ""

git status

echo ""
echo "--- --- ---"
echo "Push the commit"
echo "--- --- ---"
echo ""

git push

echo ""
echo "--- --- ---"
echo "Commit has been pushed"
echo "--- --- ---"
echo ""

git status

echo ""
echo "--- --- ---"
echo "All re-formatted code has been committed and pushed with success"
echo "--- --- ---"
echo ""
exit ${SUCCESS}
exit ${SUCCESS}

0 comments on commit d376cea

Please sign in to comment.