Skip to content

Commit d950d8c

Browse files
authored
Update to dotnet 8 (#105)
1 parent cba5a2a commit d950d8c

File tree

16 files changed

+91
-79
lines changed

16 files changed

+91
-79
lines changed

.github/workflows/build-test.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ jobs:
2020
name: Build and test
2121
permissions:
2222
contents: read
23-
runs-on: ubuntu-latest
23+
strategy:
24+
fail-fast: false # don't fail if one of the matrix jobs fails. Example: try to run the windows matrix even if the ubuntu matrix fails.
25+
matrix:
26+
os: [ubuntu-latest, windows-latest]
27+
runs-on: ${{ matrix.os }}
2428
env:
2529
SLN_DIR: MarkdownLinkCheckLogParser
2630
SLN_FILENAME: MarkdownLinkCheckLogParser.sln
@@ -93,7 +97,7 @@ jobs:
9397
}
9498
- name: Set run even if tests fail condition
9599
id: even-if-tests-fail
96-
if: always()
100+
if: matrix.os == 'ubuntu-latest' && always()
97101
run: |
98102
# Some of the steps below provide feedback on the test run and I want to run them even if
99103
# some of the previous steps failed. For that I need:
@@ -109,7 +113,7 @@ jobs:
109113
Write-Output "condition is set to $condition"
110114
- name: Generate code coverage report
111115
id: code-coverage-report-generator
112-
if: steps.even-if-tests-fail.outputs.condition == 'true' && always()
116+
if: matrix.os == 'ubuntu-latest' && steps.even-if-tests-fail.outputs.condition == 'true' && always()
113117
run: |
114118
$testCoverageReportDir = $(Join-Path -Path ${{ steps.dotnet-test.outputs.test-coverage-dir }} -ChildPath "report")
115119
Write-Output "test-coverage-report-dir=$testCoverageReportDir" >> $env:GITHUB_OUTPUT
@@ -118,24 +122,26 @@ jobs:
118122
"-targetdir:$testCoverageReportDir" `
119123
-reportTypes:htmlInline
120124
- name: Upload code coverage report to artifacts
121-
if: steps.even-if-tests-fail.outputs.condition == 'true' && always()
125+
if: matrix.os == 'ubuntu-latest' && steps.even-if-tests-fail.outputs.condition == 'true' && always()
122126
uses: actions/upload-artifact@v3
123127
with:
124128
name: ${{ env.CODE_COVERAGE_ARTIFACT_NAME }}
125129
path: ${{ steps.code-coverage-report-generator.outputs.test-coverage-report-dir }}
126130
- name: Upload test results to artifacts
127-
if: steps.even-if-tests-fail.outputs.condition == 'true' && always()
131+
if: matrix.os == 'ubuntu-latest' && steps.even-if-tests-fail.outputs.condition == 'true' && always()
128132
uses: actions/upload-artifact@v3
129133
with:
130134
name: ${{ env.TEST_RESULTS_ARTIFACT_NAME }}
131135
path: ${{ steps.dotnet-test.outputs.test-results-dir }}
132136
- name: Upload test coverage to Codecov
137+
if: matrix.os == 'ubuntu-latest'
133138
uses: codecov/codecov-action@v3
134139
with:
135140
token: ${{ secrets.CODECOV_TOKEN }} # even though it's not required for public repos it helps with intermittent failures caused by https://community.codecov.com/t/upload-issues-unable-to-locate-build-via-github-actions-api/3954, https://github.com/codecov/codecov-action/issues/598
136141
files: ${{ steps.dotnet-test.outputs.test-coverage-file }}
137142
fail_ci_if_error: true
138143
- name: Log Codecov info
144+
if: matrix.os == 'ubuntu-latest'
139145
run: |
140146
$codeCoveUrl = "https://app.codecov.io/gh/${{ github.repository }}/"
141147
Write-Output "::notice title=Code coverage (${{ runner.os }})::Code coverage has been uploaded to Codecov at $codeCoveUrl. You can download the code coverage report from the workflow artifact named: ${{ env.CODE_COVERAGE_ARTIFACT_NAME }}."

Dockerfile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
1+
# See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
2+
# See https://hub.docker.com/_/microsoft-dotnet-runtime/ for list of tags for dotnet runtime
3+
# See https://hub.docker.com/_/microsoft-dotnet-sdk for list of tags for dotnet sdk
24

3-
FROM mcr.microsoft.com/dotnet/runtime:7.0-alpine AS base
5+
FROM mcr.microsoft.com/dotnet/runtime:8.0-alpine AS base
46
# install powershell as per https://docs.microsoft.com/en-us/powershell/scripting/install/install-alpine
5-
ARG PWSH_VERSION=7.3.6
7+
ARG PWSH_VERSION=7.4.0
68
RUN apk add --no-cache \
79
ca-certificates \
810
less \
@@ -18,14 +20,14 @@ RUN apk add --no-cache \
1820
icu-libs \
1921
curl
2022
RUN apk -X https://dl-cdn.alpinelinux.org/alpine/edge/main add --no-cache lttng-ust
21-
RUN curl -L https://github.com/PowerShell/PowerShell/releases/download/v${PWSH_VERSION}/powershell-${PWSH_VERSION}-linux-alpine-x64.tar.gz -o /tmp/powershell.tar.gz
23+
RUN curl -L https://github.com/PowerShell/PowerShell/releases/download/v${PWSH_VERSION}/powershell-${PWSH_VERSION}-linux-musl-x64.tar.gz -o /tmp/powershell.tar.gz
2224
RUN mkdir -p /opt/microsoft/powershell/7
2325
RUN tar zxf /tmp/powershell.tar.gz -C /opt/microsoft/powershell/7
2426
RUN chmod +x /opt/microsoft/powershell/7/pwsh
2527
RUN ln -s /opt/microsoft/powershell/7/pwsh /usr/bin/pwsh
2628
# end of install powershell
2729

28-
FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build
30+
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
2931
WORKDIR /markdown-link-check-log-parser
3032
COPY ["MarkdownLinkCheckLogParser/NuGet.Config", "MarkdownLinkCheckLogParser/"]
3133
COPY ["MarkdownLinkCheckLogParser/src/MarkdownLinkCheckLogParserCli/MarkdownLinkCheckLogParserCli.csproj", "MarkdownLinkCheckLogParser/src/MarkdownLinkCheckLogParserCli/"]

MarkdownLinkCheckLogParser/.editorconfig

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -104,32 +104,22 @@ dotnet_diagnostic.CA2007.severity = none # CA2007: Do not directly await
104104
dotnet_diagnostic.CA2234.severity = silent # CA2234: Pass System.Uri objects instead of strings
105105

106106
##########################################
107-
# Language Rules
108-
# https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/language-rules
107+
# .NET code refactoring options
108+
# https://learn.microsoft.com/en-us/visualstudio/ide/reference/code-styles-refactoring-options?view=vs-2022
109109
##########################################
110-
# .NET Style Rules
111-
# https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/language-rules#net-style-rules
112110
[*.cs]
113-
# Parentheses preferences
114-
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion
115-
# Expression-level preferences
116-
dotnet_diagnostic.IDE0010.severity = silent # Add missing cases to switch statement (IDE0010)
117-
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
118-
dotnet_diagnostic.IDE0045.severity = suggestion # Use conditional expression for assignment (IDE0045)
119-
dotnet_style_prefer_conditional_expression_over_return = true:silent
120-
dotnet_diagnostic.IDE0046.severity = none # Use conditional expression for return (IDE0046)
121-
# Undocumented
122111
dotnet_style_operator_placement_when_wrapping = beginning_of_line
123112

124-
# C# Style Rules
125-
# https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/language-rules#c-style-rules
113+
##########################################
114+
# Language and unnecessary rules
115+
# https://learn.microsoft.com/en-gb/dotnet/fundamentals/code-analysis/style-rules/language-rules
116+
##########################################
126117
[*.cs]
127-
# 'var' preferences
128-
dotnet_diagnostic.IDE0008.severity = none # IDE0008: Use explicit type instead of 'var'
129-
csharp_style_var_for_built_in_types = true:warning
130-
csharp_style_var_when_type_is_apparent = true:warning
131-
csharp_style_var_elsewhere = true:warning
132-
# Expression-bodied members
118+
119+
# Code-block preferences https://learn.microsoft.com/en-gb/dotnet/fundamentals/code-analysis/style-rules/language-rules#code-block-preferences
120+
dotnet_diagnostic.IDE0290.severity = silent # Use primary constructor (IDE0290)
121+
122+
# Expression-bodied members https://learn.microsoft.com/en-gb/dotnet/fundamentals/code-analysis/style-rules/language-rules#expression-bodied-members
133123
csharp_style_expression_bodied_methods = true:silent
134124
dotnet_diagnostic.IDE0022.severity = silent # Use expression body for methods (IDE0022)
135125
csharp_style_expression_bodied_operators = true:silent
@@ -144,18 +134,27 @@ csharp_style_expression_bodied_lambdas = true:silent
144134
dotnet_diagnostic.IDE0053.severity = silent # Use expression body for lambdas (IDE0053)
145135
csharp_style_expression_bodied_local_functions = true:silent
146136
dotnet_diagnostic.IDE0061.severity = silent # Use expression body for local functions (IDE0061)
147-
# Expression-level preferences
137+
138+
# Expression-level preferences https://learn.microsoft.com/en-gb/dotnet/fundamentals/code-analysis/style-rules/language-rules#expression-level-preferences
139+
dotnet_diagnostic.IDE0010.severity = silent # Add missing cases to switch statement (IDE0010)
140+
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
141+
dotnet_diagnostic.IDE0045.severity = suggestion # Use conditional expression for assignment (IDE0045)
142+
dotnet_style_prefer_conditional_expression_over_return = true:silent
143+
dotnet_diagnostic.IDE0046.severity = none # Use conditional expression for return (IDE0046)
148144
dotnet_diagnostic.IDE0057.severity = none # Use range operator (IDE0057)
145+
csharp_style_unused_value_expression_statement_preference = discard_variable:silent
146+
dotnet_diagnostic.IDE0058.severity = silent # Remove unnecessary expression value (IDE0058)
149147
csharp_style_implicit_object_creation_when_type_is_apparent = false:silent
150148
dotnet_diagnostic.IDE0090.severity = suggestion # Simplify new expression (IDE0090)
151149

152-
##########################################
153-
# Unnecessary Code Rules
154-
# https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/unnecessary-code-rules
155-
##########################################
156-
[*.cs]
157-
csharp_style_unused_value_expression_statement_preference = discard_variable:silent
158-
dotnet_diagnostic.IDE0058.severity = silent # Remove unnecessary expression value (IDE0058)
150+
# Parentheses preferences https://learn.microsoft.com/en-gb/dotnet/fundamentals/code-analysis/style-rules/language-rules#parentheses-preferences
151+
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion
152+
153+
# 'var' preferences https://learn.microsoft.com/en-gb/dotnet/fundamentals/code-analysis/style-rules/language-rules#var-preferences
154+
dotnet_diagnostic.IDE0008.severity = none # IDE0008: Use explicit type instead of 'var'
155+
csharp_style_var_for_built_in_types = true:warning
156+
csharp_style_var_when_type_is_apparent = true:warning
157+
csharp_style_var_elsewhere = true:warning
159158

160159
##########################################
161160
# Formatting Rules
@@ -498,7 +497,7 @@ dotnet_diagnostic.SA1006.severity = suggestion # SA1006: Preprocessor keywords
498497
dotnet_diagnostic.SA1007.severity = suggestion # SA1007: Operator keyword should be followed by space
499498
dotnet_diagnostic.SA1008.severity = suggestion # SA1008: Opening parenthesis should be spaced correctly
500499
dotnet_diagnostic.SA1009.severity = suggestion # SA1009: Closing parenthesis should be spaced correctly
501-
dotnet_diagnostic.SA1010.severity = suggestion # SA1010: Opening square brackets should be spaced correctly
500+
dotnet_diagnostic.SA1010.severity = none # SA1010: Opening square brackets should be spaced correctly # TODO review this, temporarily disabled until https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3687 is resolved. Hopefully soon by merging https://github.com/DotNetAnalyzers/StyleCopAnalyzers/pull/3729
502501
dotnet_diagnostic.SA1011.severity = suggestion # SA1011: Closing square brackets should be spaced correctly
503502
dotnet_diagnostic.SA1012.severity = suggestion # SA1012: Opening braces should be spaced correctly
504503
dotnet_diagnostic.SA1013.severity = suggestion # SA1013: Closing braces should be spaced correctly

MarkdownLinkCheckLogParser/global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "7.0.x",
3+
"version": "8.0.x",
44
"rollForward": "disable",
55
"allowPrerelease": false
66
}

MarkdownLinkCheckLogParser/src/MarkdownLinkCheckLogParserCli/CliCommands/ParseLog/Outputs/JsonConsoleOutputFormat.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ namespace MarkdownLinkCheckLogParserCli.CliCommands.ParseLog.Outputs;
22

33
internal sealed class JsonConsoleOutputFormat : IOutputFormat
44
{
5+
private static readonly JsonSerializerOptions _serializeOptions = new JsonSerializerOptions
6+
{
7+
WriteIndented = true,
8+
};
9+
510
private readonly IConsole _console;
611

712
public JsonConsoleOutputFormat(IConsole console)
@@ -12,11 +17,7 @@ public JsonConsoleOutputFormat(IConsole console)
1217
public async Task WriteAsync(MarkdownLinkCheckOutput output)
1318
{
1419
output.NotNull();
15-
var serializeOptions = new JsonSerializerOptions
16-
{
17-
WriteIndented = true,
18-
};
19-
var outputAsJson = JsonSerializer.Serialize(output, serializeOptions);
20+
var outputAsJson = JsonSerializer.Serialize(output, _serializeOptions);
2021
await _console.Output.WriteLineAsync(outputAsJson);
2122
}
2223
}

MarkdownLinkCheckLogParser/src/MarkdownLinkCheckLogParserCli/CliCommands/ParseLog/Outputs/JsonFileOutputFormat.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ namespace MarkdownLinkCheckLogParserCli.CliCommands.ParseLog.Outputs;
22

33
internal sealed class JsonFileOutputFormat : IOutputFormat
44
{
5+
private static readonly JsonSerializerOptions _serializeOptions = new JsonSerializerOptions
6+
{
7+
WriteIndented = true,
8+
};
9+
510
private readonly IFile _file;
611
private readonly OutputJsonFilepath _filepath;
712

@@ -14,11 +19,7 @@ public JsonFileOutputFormat(IFile file, OutputJsonFilepath filepath)
1419
public async Task WriteAsync(MarkdownLinkCheckOutput output)
1520
{
1621
output.NotNull();
17-
var serializeOptions = new JsonSerializerOptions
18-
{
19-
WriteIndented = true,
20-
};
21-
var outputAsJson = JsonSerializer.Serialize(output, serializeOptions);
22+
var outputAsJson = JsonSerializer.Serialize(output, _serializeOptions);
2223
try
2324
{
2425
await _file.WriteAllTextAsync(filename: _filepath, text: outputAsJson);

MarkdownLinkCheckLogParser/src/MarkdownLinkCheckLogParserCli/CliCommands/ParseLog/Outputs/Types/OutputOptions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ namespace MarkdownLinkCheckLogParserCli.CliCommands.ParseLog.Outputs.Types;
22

33
internal sealed class OutputOptions
44
{
5-
private readonly List<OutputOptionsTypes> _values;
5+
private readonly List<OutputOptionsTypes> _values = [];
66

77
public OutputOptions(string outputOptions)
88
{
99
outputOptions.NotNullOrWhiteSpace();
10-
_values = new List<OutputOptionsTypes>();
1110
var outputOptionsSplit = outputOptions.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
1211
if (outputOptionsSplit.Contains("step-json", StringComparer.InvariantCulture))
1312
{

MarkdownLinkCheckLogParser/src/MarkdownLinkCheckLogParserCli/CliCommands/ParseLog/ParseLogCommand.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,35 @@ public ParseLogCommand(HttpClient httpClient, IFile file)
2121
[CommandOption(
2222
"auth-token",
2323
IsRequired = true,
24-
Validators = new Type[] { typeof(NotNullOrWhitespaceOptionValidator) },
24+
Validators = [typeof(NotNullOrWhitespaceOptionValidator)],
2525
Description = "GitHub token used to access workflow run logs.")]
2626
public string AuthToken { get; init; } = default!;
2727

2828
[CommandOption(
2929
"repo",
3030
IsRequired = true,
31-
Validators = new Type[] { typeof(NotNullOrWhitespaceOptionValidator) },
31+
Validators = [typeof(NotNullOrWhitespaceOptionValidator)],
3232
Description = "The repository for the workflow run in the format of {owner}/{repo}.")]
3333
public string Repo { get; init; } = default!;
3434

3535
[CommandOption(
3636
"run-id",
3737
IsRequired = true,
38-
Validators = new Type[] { typeof(NotNullOrWhitespaceOptionValidator) },
38+
Validators = [typeof(NotNullOrWhitespaceOptionValidator)],
3939
Description = "The unique identifier of the workflow run that contains the markdown link check step.")]
4040
public string RunId { get; init; } = default!;
4141

4242
[CommandOption(
4343
"job-name",
4444
IsRequired = true,
45-
Validators = new Type[] { typeof(NotNullOrWhitespaceOptionValidator) },
45+
Validators = [typeof(NotNullOrWhitespaceOptionValidator)],
4646
Description = "The name of the job that contains the markdown link check step.")]
4747
public string JobName { get; init; } = default!;
4848

4949
[CommandOption(
5050
"step-name",
5151
IsRequired = true,
52-
Validators = new Type[] { typeof(NotNullOrWhitespaceOptionValidator) },
52+
Validators = [typeof(NotNullOrWhitespaceOptionValidator)],
5353
Description = "The name of the markdown link check step.")]
5454
public string StepName { get; init; } = default!;
5555

@@ -58,7 +58,7 @@ public ParseLogCommand(HttpClient httpClient, IFile file)
5858

5959
[CommandOption(
6060
"output",
61-
Validators = new Type[] { typeof(OutputOptionValidator) },
61+
Validators = [typeof(OutputOptionValidator)],
6262
Description = "How to output the markdown file check result. It must be one of or a comma separated list of the following values: step-json,step-md,file-json,file-md.")]
6363
public string OutputOptions { get; init; } = "step-json";
6464

MarkdownLinkCheckLogParser/src/MarkdownLinkCheckLogParserCli/MarkdownLinkCheck/MarkdownFileCheck.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ namespace MarkdownLinkCheckLogParserCli.MarkdownLinkCheck;
22

33
internal sealed class MarkdownFileCheck
44
{
5-
private readonly List<MarkdownLinkError> _errors;
5+
private readonly List<MarkdownLinkError> _errors = [];
66

77
public MarkdownFileCheck(string filename)
88
{
99
Filename = filename.NotNull();
10-
_errors = new List<MarkdownLinkError>();
1110
}
1211

1312
public string Filename { get; }

MarkdownLinkCheckLogParser/src/MarkdownLinkCheckLogParserCli/MarkdownLinkCheck/MarkdownLinkCheckOutput.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ public MarkdownLinkCheckOutput(IReadOnlyList<MarkdownFileCheck> files, bool capt
77
files.NotNull();
88
var orderedByFilename = files.OrderBy(x => x.Filename, StringComparer.InvariantCulture);
99
Files = captureErrorsOnly
10-
? orderedByFilename.Where(x => x.HasErrors).ToList()
11-
: orderedByFilename.ToList();
10+
? [.. orderedByFilename.Where(x => x.HasErrors)]
11+
: [.. orderedByFilename];
1212
TotalFilesChecked = files.Count;
1313
TotalLinksChecked = files.Sum(x => x.LinksChecked);
1414
TotalErrors = files.Sum(x => x.ErrorCount);

0 commit comments

Comments
 (0)