Skip to content

Commit

Permalink
Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ArturWincenciak committed Jan 8, 2023
1 parent 18a43bb commit 09c1798
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 12 deletions.
1 change: 1 addition & 0 deletions .github/workflows/cleanup_code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
commit_message: 'Cleanup code by ReSharper CLI CleanupCode GitHub Action'
commit_creator_email: 'cleanupcode@github.action'
commit_creator_name: 'CleanupCode Action'

inspection:
runs-on: ubuntu-latest
name: Inspect Code
Expand Down
136 changes: 124 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# GitHub Action of ReSharper CLI CleanupCode Demo
# ReSharper CLI CleanupCode GitHub Action Demo

#### Action in Marketplace: [ReSharper CLI CleanupCode](https://TODO)
#### Action in Marketplace: [ReSharper CLI CleanupCode](https://github.com/marketplace/actions/resharper-cli-cleanupcode)
#### Action in Repository: [ArturWincenciak/ReSharper_CleanupCode@v2.0](https://github.com/ArturWincenciak/ReSharper_CleanupCode)

## Try your self
Expand All @@ -16,8 +16,8 @@ That is a project uses a GitHub Action that allows you to run
automatically apply code style rules and reformat code in a project. The action is triggered on a push event, and it
cleans up the code using the specified profile, and commits the changes with a specified commit message.

Note that this code includes an example class `DemoClass` that break some style rules and a unit test class `DemoUnitTests`,
which also brake rules but is used to demonstrate how the action can be configured to exclude certain types of code from being
Note that this code includes an example class `DemoClass` that breaks some style rules and a unit test class `DemoUnitTests`,
which also breaks rules but is used to demonstrate how the action can be configured to exclude certain types of code from being
cleaned up.

## Usage [cleanup_code.yml](https://github.com/ArturWincenciak/ReSharper_CleanupCode_Demo/blob/main/.github/workflows/cleanup_code.yml)
Expand Down Expand Up @@ -89,14 +89,16 @@ steps:
solution: 'ReSharperCleanupCodeDemo.sln'
```

### To learn more, please visit [specification in the marketplace](TODO)
**To learn more, please visit [specification in the marketplace](https://github.com/marketplace/actions/resharper-cli-cleanupcode).**

## Shared team configuration

### Solution team-shared settings in `*.sln.DotSettings`

All your setting should be saved in ['Solution team-shared' layer](https://www.jetbrains.com/help/rider/Sharing_Configuration_Options.html#solution-team-shared-layer).
In this project here is the file: [ReSharperCleanupCodeDemo.sln.DotSettings](https://github.com/ArturWincenciak/ReSharper_CleanupCode_Demo/blob/main/ReSharperCleanupCodeDemo.sln.DotSettings).
All your settings should be saved in
[Solution Team-Shared Layer](https://www.jetbrains.com/help/rider/Sharing_Configuration_Options.html#solution-team-shared-layer)
you can find this project here in that file
[ReSharperCleanupCodeDemo.sln.DotSettings](https://github.com/ArturWincenciak/ReSharper_CleanupCode_Demo/blob/main/ReSharperCleanupCodeDemo.sln.DotSettings).

### Export code style settings to `.editorconfig`

Expand All @@ -106,7 +108,7 @@ Read more here:

I suggest exporting all settings, including default settings, to a [.editorconfig](https://github.com/ArturWincenciak/ReSharper_CleanupCode_Demo/blob/main/.editorconfig) file. It is important to explicitly
save all default settings to avoid potential issues in the future caused by changes in default settings in newer
versions of the software. It is important to explicitly save all default settings in a transparent manner.
versions of the command-line tool software. It is important to explicitly save all default settings in a transparent manner.

### Set up your `--profile`

Expand All @@ -121,7 +123,7 @@ jb_cleanup_code_arg: '--verbosity=INFO --profile=Almost Full Cleanup --exclude=*

one of the settings is the `--profile` flag. I have set my profile to be named `Almost Full Cleanup`.

I have configured my profile to exclude `*.md` files and the `.editorconfig` file from the cleanup."
I have configured my profile to exclude `*.md` files and the `.editorconfig` file from the cleaning up.

![Code Cleanup Profiles](assets/code_cleanup_profiles.png)

Expand All @@ -130,7 +132,9 @@ I have configured my profile to exclude `*.md` files and the `.editorconfig` fil
Read more here:
- [Rearrange members with file and type layout patterns](https://www.jetbrains.com/help/rider/File_and_Type_Layout.html)

My current favorite setting looks like this ([ReSharperCleanupCodeDemo.sln.DotSettings](https://github.com/ArturWincenciak/ReSharper_CleanupCode_Demo/blob/main/ReSharperCleanupCodeDemo.sln.DotSettings)):
My current favorite setting
[ReSharperCleanupCodeDemo.sln.DotSettings](https://github.com/ArturWincenciak/ReSharper_CleanupCode_Demo/blob/main/ReSharperCleanupCodeDemo.sln.DotSettings)
looks like that:

![Code Cleanup File Layout](assets/code_cleanup_file_layout.png)

Expand All @@ -150,7 +154,9 @@ The commit with the changes will be created automatically.

Feel free to use the script and perform clean up your code locally with a fully automated commit and save your time.

_That script can be configured as git commit hook but ... TBD_
> _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 the `pre-push` git hook instead._

### How to run the script

Expand All @@ -173,4 +179,110 @@ cc

```bash
cc -a no
```
```

# Cleanup Code works perfectly with Inspect 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 Code Review by adding an additional step that performs an inspection of the code and, if it sees anything
concerning, adds a comment to the submitted Pull Request on our behalf.

Below, I demonstrate how to combine [ReSharper CLI CleanupCode](https://github.com/marketplace/actions/resharper-cli-cleanupcode)
and [ReSharper CLI InspectCode](https://github.com/marketplace/actions/resharper-cli-inspectcode) using
[GitHub Action](https://github.com/ArturWincenciak/ReSharper_CleanupCode_Demo/blob/main/.github/workflows/cleanup_code.yml)
that contains two jobs: `cleanup` and `inspection`.

- **Marketplace: [ReSharper CLI CleanupCode](https://github.com/marketplace/actions/resharper-cli-cleanupcode)**
- _that one I've created by my self_
- **Marketplace: [ReSharper CLI InspectCode](https://github.com/marketplace/actions/resharper-cli-inspectcode)**
- _that one I've found in the Marketplace and used it here, it was an inspiration for me to create my own action up above_

```yaml
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/ReSharper_CleanupCode@v2.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: 'cleanupcode@github.action'
commit_creator_name: 'CleanupCode Action'
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/resharper_inspectcode@1.6.5
with:
solutionPath: ./ReSharperCleanupCodeDemo.sln
failOnIssue: 1
minimumSeverity: notice
solutionWideAnalysis: true
```
---

Let's look at the following screenshots to see how the jobs have been configured and utilized in this project.

## Branch protection rule
![Branch protection rule](assets/code_cleanup_branch_protection_rule.png)

## Cleanup job is in progress
![Cleanup job in progress](assets/code_cleanup_pr_action_jobs_first_in_progress.png)

## Cleanup job is done
![Cleanup job done](assets/code_cleanup_pr_action_jobs_second_in_progress.png)

## Commit has been made and pushed into the branch by the Cleanup job
![Commit has been made and pushed into the branch by the Cleanup job](assets/code_cleanup_pr_auto-commit_v2.png)

## Details of the auto-commit
![Details of the auto-commit](assets/code_cleanup_pr_auto-commit-review_v2.png)

## Inspection job is in progress
![Inspection job in progress](assets/code_cleanup_pr_action_jobs_second_in_progress.png)

## Inspection job is done
![Inspection job done](assets/code_cleanup_pr_action_jobs_second_result.png)

## Review code has been made by the Inspection job
![Review code has been made by the Inspection job](assets/code_cleanup_pr_files_changes_v2.png)

## Pull Request checks were not successful
![Pull Request checks were not successful](assets/code_cleanup_pr_checks_were_no_successful.png)
Binary file added assets/code_cleanup_branch_protection_rule.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/code_cleanup_pr_auto-commit-review.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/code_cleanup_pr_auto-commit-review_v2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/code_cleanup_pr_auto-commit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/code_cleanup_pr_auto-commit_v2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/code_cleanup_pr_files_changes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/code_cleanup_pr_files_changes_v2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 09c1798

Please sign in to comment.