From efe7e2133b6dd292c413e7dc5fa7f366e7175877 Mon Sep 17 00:00:00 2001 From: Omar Muscatello <115794104+omar-muscatello-zupit@users.noreply.github.com> Date: Sat, 18 Nov 2023 12:34:12 +0100 Subject: [PATCH] feat: add .net lint action (#49) --- .github/actions/dotnet/lint/action.yml | 25 +++++++++++ .github/workflows/dotnet-workflow-common.yml | 5 +++ README.md | 47 +++++++++++++++++--- 3 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 .github/actions/dotnet/lint/action.yml diff --git a/.github/actions/dotnet/lint/action.yml b/.github/actions/dotnet/lint/action.yml new file mode 100644 index 00000000..9aea868c --- /dev/null +++ b/.github/actions/dotnet/lint/action.yml @@ -0,0 +1,25 @@ +name: .NET lint + +# Note: this action requires .NET 6+ SDK + +inputs: + WORKING_DIRECTORY: + required: true + type: string + SHELL: + required: false + type: string + default: 'bash' + +runs: + using: composite + steps: + - name: .NET lint style + shell: ${{ inputs.SHELL }} + run: dotnet format style --verify-no-changes + working-directory: ${{ inputs.WORKING_DIRECTORY }} + + - name: .NET lint analyzers + shell: ${{ inputs.SHELL }} + run: dotnet format analyzers --verify-no-changes + working-directory: ${{ inputs.WORKING_DIRECTORY }} diff --git a/.github/workflows/dotnet-workflow-common.yml b/.github/workflows/dotnet-workflow-common.yml index 65dd7b9a..f35ba948 100644 --- a/.github/workflows/dotnet-workflow-common.yml +++ b/.github/workflows/dotnet-workflow-common.yml @@ -44,6 +44,11 @@ jobs: WORKING_DIRECTORY: ${{ inputs.WORKING_DIRECTORY }} BUILD_CONFIG: "Debug" + - name: Lint + uses: zupit-it/pipeline-templates/.github/actions/dotnet/lint@1.9.0 + with: + WORKING_DIRECTORY: ${{ inputs.WORKING_DIRECTORY }} + - name: Run tests uses: zupit-it/pipeline-templates/.github/actions/dotnet/test@v1.9.0 with: diff --git a/README.md b/README.md index 7310b614..2cd4b616 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,10 @@ If you would like to get more details of these tasks, just look at this [doc](do 1. [Install](#net-action---install) 2. [Build](#net-action---build) 3. [Format](#net-action---format) - 4. [Test](#net-action---test) - 5. [Publish](#net-action---publish) - 6. [Release](#net-action---release) + 4. [Lint](#net-action---lint) + 5. [Test](#net-action---test) + 6. [Publish](#net-action---publish) + 7. [Release](#net-action---release) 5. [Azure](#azure-action) 1. [App Service](#azure-action---app-service---deploy) 2. [Storage Account](#azure-action---storage-account---deploy) @@ -327,6 +328,41 @@ steps: CSHARPIER_VERSION: "0.25.0" ``` +#### .NET Action - Lint + +This action: +- run the `dotnet format` command on the `WORKING_DIRECTORY`. + +###### Requirements + +- The `WORKING_DIRECTORY` directory must contain a solution or a project file. +- The correct .NET (6+) version must be installed. + +_This workflow doesn't download the codebase. You have to check out the repo by yourself._ + +###### Action + +**.github/actions/dotnet/lint** is the action that lints the code of a .NET solution. + +It requires these inputs: + +- **WORKING_DIRECTORY**: The directory where the runner can execute all the commands. It must contain a solution (`.sln`) or a project (`.csproj`) file. + +In addition, it is possible to specify this optional input: + +- **SHELL**: The shell type to use. By default, it is **bash**. + +This is an example to show how data should be formatted. + +```yaml +steps: + - name: Build + uses: zupit-it/pipeline-templates/.github/actions/dotnet/lint@v1.9.0 + with: + WORKING_DIRECTORY: "backend" + SHELL: "bash" +``` + #### .NET Action - Test This action: @@ -1308,13 +1344,14 @@ This workflow is based on the following actions: - [.NET - Install](#net-action---install) - [.NET - Build](#net-action---build) - [.NET - Format](#net-action---format) +- [.NET - Lint](#net-action---lint) - [.NET - Test](#net-action---test) Check these actions requirements before using this workflow. ###### Workflow -**dotnet-workflow-common.yml** is the reusable workflow to check that the code is correctly linted and that all tests pass. +**dotnet-workflow-common.yml** is the reusable workflow to check that the code is correctly linted, formatted, and that all tests pass. It requires these inputs: @@ -1329,7 +1366,7 @@ jobs: common: uses: zupit-it/pipeline-templates/.github/workflows/dotnet-workflow-common.yml@v1.9.0 with: - WORKING_DIRECTORY: "back-end" + WORKING_DIRECTORY: "backend" DOTNET_IMAGE: "'mcr.microsoft.com/dotnet/sdk:7.0" CONTAINER_CI_LABELS: "['team', 'pipeline', 'container']" ```