Zaoszczędź swój czas, niech kod wyczyści się sam – ReSharper CLI CleanupCode GitHub Action
GitHub Action automatically cleans up your code and creates a commit with the changes in your remote repository.
Save your time from having to do a code review and make corrections and also from having to enter a commit message each time. The commit with the changes is created automatically.
That is a GitHub Action that allows you to run ReSharper's CleanupCode Command-Line Tool in order to automatically apply code style rules and fix code issues in your project.
CleanupCode will read the following preferences from DotSettings files:
The following input parameters can be passed to the action:
Solution or project file to be cleaned up.
- Required:
true
Determines whether the action should fail if the code needs to be reformatted.
- Required:
false
- Default:
no
- Accepted values:
yes
,no
Additional arguments to pass to the ReSharper's CleanupCode Command-Line Tool
. Configure the tool with command-line parameters,
e.g.: --verbosity=INFO --profile=Built-in: Full Cleanup --exclude=**UnitTests/**.*
.
- See more here in that clear and concise specification
- Notice: Never use quotation marks
"
even if the value contains spaces. The command separator is--
(two hyphens in a row) and this is enough to split arguments. If you use quotation marks, the behavior is undefined. - Required:
false
- Default:
--verbosity=WARN
In that demo project, you will find all the knowledge you need to effectively start using this action.
- Go to the demo project
- Fork this repo
- Create a Pull Request
- Go to
Actions
and observe the action in action - Check out history of your repo and see newly created commit
steps:
- name: Cleanup Code
uses: ArturWincenciak/[email protected]
with:
solution: 'ReSharperCleanupCodeDemo.sln'
steps:
- name: Cleanup Code
uses: ArturWincenciak/[email protected]
with:
solution: 'ReSharperCleanupCodeDemo.sln'
fail_on_reformat_needed: 'yes'
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.
steps:
- name: Cleanup Code
uses: ArturWincenciak/[email protected]
with:
solution: 'ReSharperCleanupCodeDemo.sln'
fail_on_reformat_needed: 'no'
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.
For such a case, I have prepared a ready-made script that you can run locally. This script will perform clean up code and create a commit with the changes in your local repository. This will save your time from having to enter a commit message each time. The commit with the changes will be created automatically.
This script can be attached to the git hooks, however, attaching this script to the
pre-commit
git hook is not advisable as it may slow down our work considerably due to the lengthy clean up code process. It may be more beneficial to add this script to thepre-push
git hook instead.
name: ReSharper CLI CleanupCode
on: [ push ]
jobs:
cleanup:
runs-on: ubuntu-latest
name: Cleanup Code
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Restore Dependencies
run: dotnet restore ReSharperCleanupCodeDemo.sln
- name: Cleanup Code
id: cleanup
uses: ArturWincenciak/[email protected]
with:
solution: 'ReSharperCleanupCodeDemo.sln'
fail_on_reformat_needed: 'no'
jb_cleanup_code_arg: '--verbosity=INFO --profile=Built-in: Full Cleanup --exclude=**UnitTests/**.*'
Checkout
: download the source code from the current repository where the Action was initiatedSetup .NET
: install the specified version of .NET on the virtual machine where the Action is runRestore Dependencies
: restore all project dependencies, such as NuGet librariesCleanup Code
clean up the code
There are situations where Cleanup Code does not do the entire job for us, but we can still greatly help ourselves and speed up ours Code Review process by adding an additional automatic step that performs an inspection of the code and, adds a comments to the submitted Pull Request on our behalf.
Here in that demo project
ReSharper CLI CleanupCode GitHub Action Demo,
I show you how to combine ReSharper CLI CleanupCode
and ReSharper CLI InspectCode
using GitHub Action Definition
that contains two jobs: cleanup
and inspection
.
Refer to the demo project and gain all the knowledge on how to speed up your daily development process.
name: ReSharper CLI CleanupCode
on: [ push ]
jobs:
cleanup:
runs-on: ubuntu-latest
name: Cleanup Code
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Restore Dependencies
run: dotnet restore ReSharperCleanupCodeDemo.sln
- name: Cleanup Code
id: cleanup
uses: ArturWincenciak/[email protected]
with:
solution: 'ReSharperCleanupCodeDemo.sln'
fail_on_reformat_needed: 'no'
jb_cleanup_code_arg: '--verbosity=INFO --profile=Almost Full Cleanup --exclude=**UnitTests/**.*'
inspection:
runs-on: ubuntu-latest
name: Inspect Code
needs: cleanup
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Restore Dependencies
run: dotnet restore ReSharperCleanupCodeDemo.sln
- name: Inspect code
uses: muno92/[email protected]
with:
solutionPath: ./ReSharperCleanupCodeDemo.sln
failOnIssue: 1
minimumSeverity: notice
solutionWideAnalysis: true
ReSharper CLI InspectCode - that one I've found in the Marketplace and used in the demo project, it was an inspiration for me to create my own
ReSharper CLI CleanupCode
the second tool in this toolkit. These two tools complement each other well and produce nice results.