Skip to content

Commit

Permalink
Add working-directory and use-standalone-tool inputs (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
flobernd authored May 19, 2023
1 parent fc52e69 commit a86bc2e
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 47 deletions.
46 changes: 26 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF >> 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 }}
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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.
Expand Down
27 changes: 25 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ''
Expand Down Expand Up @@ -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.
Expand All @@ -88,15 +109,17 @@ 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 }}
verify-no-changes: true
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
Expand Down
21 changes: 21 additions & 0 deletions test/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- Language Features -->
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>disable</ImplicitUsings>

<!-- Restore Behavior -->
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>

<!-- Compiler Options -->
<Deterministic>true</Deterministic>

<!-- Analyzer Options -->
<AnalysisLevel>latest-all</AnalysisLevel>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
</PropertyGroup>
</Project>
9 changes: 1 addition & 8 deletions test/Test.csproj
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6</TargetFramework>
<TargetFramework>net7</TargetFramework>

<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<RestoreLockedMode Condition="'$(ContinuousIntegrationBuild)' == 'true'" />

<OutputType>Exe</OutputType>
<IsPublishable>false</IsPublishable>
<IsPackable>false</IsPackable>

<AnalysisLevel>latest-all</AnalysisLevel>
</PropertyGroup>

<ItemGroup>
<None Include="packages.lock.json" Visible="false" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="ZySharp.Validation" Version="1.3.1" />
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions test/global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"sdk": {
"version": "7.0.103",
"allowPrerelease": false,
"rollForward": "latestPatch"
}
}
17 changes: 1 addition & 16 deletions test/packages.lock.json
Original file line number Diff line number Diff line change
@@ -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": {}
}
}

0 comments on commit a86bc2e

Please sign in to comment.