diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f1a67e2..288c4e9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,50 +11,56 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true +env: + TEST_DIRECTORY: test + jobs: test: - name: Test + name: Test on '${{ matrix.platform }}' [standalone = ${{ matrix.use-standalone-tool }}] runs-on: ${{ matrix.platform }} strategy: fail-fast: false matrix: platform: [ubuntu-latest, macos-latest, windows-latest] + use-standalone-tool: [false, true] steps: - name: Checkout uses: actions/checkout@v3 - # Mitigate an issue with the current `macOS` runner-image as of 22/12/2022 where - # the `dotnet-format` command fails with 'Unable to locate MSBuild'.. - - name: 'Create "global.json"' - if: runner.os == 'macOS' - shell: bash - run: | - cat <> global.json - { - "sdk": { - "version": "6.0.100", - "allowPrerelease": false, - "rollForward": "latestFeature" - } - } - EOF - - name: .NET Setup uses: zyactions/dotnet-setup@v1 + with: + global-json-file: ${{ env.TEST_DIRECTORY }}/global.json + + - name: .NET Setup (SDK 8) + if: matrix.use-standalone-tool + uses: zyactions/dotnet-setup@v1 + with: + dotnet-version: '8.x.x' + + - name: Install latest .NET Format tool + if: matrix.use-standalone-tool + shell: bash + run: | + dotnet tool install -g dotnet-format --version "8.*" --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json - name: .NET Restore uses: zyactions/dotnet-restore@v1 with: - workspace: test + # TODO: Use working-directory instead + workspace: ${{ env.TEST_DIRECTORY }} - name: .NET Lint continue-on-error: true uses: ./ with: - workspace: test + working-directory: ${{ env.TEST_DIRECTORY }} + use-standalone-tool: ${{ matrix.use-standalone-tool }} - name: .NET Lint Project continue-on-error: true uses: ./ with: - workspace: test/Test.csproj + working-directory: ${{ env.TEST_DIRECTORY }} + workspace: Test.csproj + use-standalone-tool: ${{ matrix.use-standalone-tool }} diff --git a/README.md b/README.md index 6babaa6..3665bfc 100644 --- a/README.md +++ b/README.md @@ -79,11 +79,23 @@ steps: ## Inputs +### `working-directory` + +The working-directory for the action. + +Defaults to the repository root directory (`github.workspace`). + +> **Note** +> +> If a specific .NET SDK version is to be used, the working directory must point to the directory that contains the `global.json` or a subdirectory of it. + ### `workspace` The Visual Studio workspace (directory, project- or solution-file). -The `dotnet restore` command automatically searches for a Visual Studio Solution file (`*.sln`) in the specified workspace directory, if no explicit solution- or project- file is specified. +This path is relative to the `working-directory` unless an absolute path is used. + +The `dotnet format` command automatically searches for a Visual Studio Solution file (`*.sln`) in the specified workspace directory, if no explicit solution- or project- file is specified. Example values: @@ -121,6 +133,10 @@ Produces a JSON report in the specified directory. Execute an implicit restore before linting. +### `use-standalone-tool` + +Uses the standalone version of the `dotnet-format` tool instead of the version bundled with the .NET SDK. + ### `pipe` An optional pipe input from which the `include` or `exclude` filenames are to be read. diff --git a/action.yml b/action.yml index 35cc59f..07fe017 100644 --- a/action.yml +++ b/action.yml @@ -8,8 +8,22 @@ branding: color: purple inputs: + working-directory: + description: > + The working-directory for the action. + + Defaults to the repository root directory (`github.workspace`). + + If a specific .NET SDK version is to be used, the working directory must point to the + directory that contains the `global.json` or a subdirectory of it. + type: string + required: false + default: ${{ github.workspace }} workspace: - description: The Visual Studio workspace (directory, project- or solution-file). + description: > + The Visual Studio workspace (directory, project- or solution-file). + + This path is relative to the `working-directory` unless an absolute path is used. type: string required: false default: '' @@ -65,6 +79,13 @@ inputs: type: boolean required: false default: false + use-standalone-tool: + description: > + Uses the standalone version of the `dotnet-format` tool instead of the version bundled + with the .NET SDK. + type: boolean + required: false + default: false pipe: description: > An optional pipe input from which the `include` or `exclude` filenames are to be read. @@ -88,8 +109,9 @@ runs: echo "::add-matcher::${{ github.action_path }}/problem-matcher.json" - name: .NET Lint - uses: zyactions/dotnet-format@36814a884879e7dafb9c74df549777e7297659c2 # v1.0.0 + uses: zyactions/dotnet-format@059ebd22ce2c9b54ee5efc30e65dde422547dadf # v1.1.0 with: + working-directory: ${{ inputs.working-directory }} workspace: ${{ inputs.workspace }} diagnostics: ${{ inputs.diagnostics }} severity: ${{ inputs.severity }} @@ -97,6 +119,7 @@ runs: include: ${{ inputs.include }} exclude: ${{ inputs.exclude }} implicit-restore: ${{ inputs.implicit-restore }} + use-standalone-tool: ${{ inputs.use-standalone-tool }} pipe: ${{ inputs.pipe }} - name: Remove Problem Matcher diff --git a/test/Directory.Build.props b/test/Directory.Build.props new file mode 100644 index 0000000..cc5b8b2 --- /dev/null +++ b/test/Directory.Build.props @@ -0,0 +1,21 @@ + + + + + latest + enable + disable + + + true + + + true + + + latest-all + true + true + true + + diff --git a/test/Test.csproj b/test/Test.csproj index 8b1666f..5bc431d 100644 --- a/test/Test.csproj +++ b/test/Test.csproj @@ -1,24 +1,17 @@ - net6 + net7 - true Exe false false - - latest-all - - - - diff --git a/test/global.json b/test/global.json new file mode 100644 index 0000000..c59b0c7 --- /dev/null +++ b/test/global.json @@ -0,0 +1,7 @@ +{ + "sdk": { + "version": "7.0.103", + "allowPrerelease": false, + "rollForward": "latestPatch" + } +} diff --git a/test/packages.lock.json b/test/packages.lock.json index c84fcfb..2712a54 100644 --- a/test/packages.lock.json +++ b/test/packages.lock.json @@ -1,21 +1,6 @@ { "version": 1, "dependencies": { - "net7.0": { - "ZySharp.Validation": { - "type": "Direct", - "requested": "[1.3.1, )", - "resolved": "1.3.1", - "contentHash": "hPuTlGBUmk5an/CLFhzYtPexYxeDB9SmuglAES+nwPJhbm6hRHnByPUdZENk3lwA90CeAgLmRIAVMTL8HK7c9A==", - "dependencies": { - "JetBrains.Annotations": "2022.3.1" - } - }, - "JetBrains.Annotations": { - "type": "Transitive", - "resolved": "2022.3.1", - "contentHash": "11nsS3+lFICGkztVs9PP2NRItxf9fF+qD6xEW/T0YGto52zj07wseUeBdMAU1ah9HNVTDZyRC1u4NWdtJScwhw==" - } - } + "net7.0": {} } } \ No newline at end of file