Skip to content

Commit

Permalink
Upgrade to .NET 9
Browse files Browse the repository at this point in the history
  • Loading branch information
IEvangelist committed Dec 20, 2024
1 parent 66fa63f commit d37453a
Show file tree
Hide file tree
Showing 42 changed files with 396 additions and 141 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<TreatWarningsAsErrors Condition="'$(ContinuousIntegrationBuild)' == 'true' or '$(Configuration)' == 'Release'">true</TreatWarningsAsErrors>

<Authors>David Pine</Authors>
<Copyright>© 2022-2024 David Pine</Copyright>
<Copyright>© 2022-$([System.DateTime]::Now.ToString('yyyy')) David Pine</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageTags>dotnet;dotnetcore;csharp;github;actions;devops;</PackageTags>
Expand Down
9 changes: 5 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<DefaultTargetFrameworks>net8.0</DefaultTargetFrameworks>
<DefaultTargetFrameworks>net9.0</DefaultTargetFrameworks>
</PropertyGroup>
<ItemGroup>
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
Expand All @@ -15,7 +15,8 @@
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="9.0.0" />
<PackageVersion Include="GitHub.Octokit.SDK" Version="0.0.30" />
<PackageVersion Include="Pathological.Globbing" Version="8.0.4" />
<PackageVersion Include="GitHub.Octokit.SDK" Version="0.0.31" />
<PackageVersion Include="Pathological.Globbing" Version="9.0.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
</Project>
</Project>
4 changes: 4 additions & 0 deletions dotnet-github-actions-sdk.sln
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.github\workflows\build-and-test.yml = .github\workflows\build-and-test.yml
.github\workflows\codeql-analysis.yml = .github\workflows\codeql-analysis.yml
Directory.Build.props = Directory.Build.props
Directory.Build.targets = Directory.Build.targets
Directory.Packages.props = Directory.Packages.props
global.json = global.json
LICENSE = LICENSE
Expand All @@ -34,6 +35,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{C5358CA3-CAA9-43F6-9696-4AEFA18AD581}"
ProjectSection(SolutionItems) = preProject
samples\Directory.Build.props = samples\Directory.Build.props
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Actions.Core.Sample", "samples\Actions.Core.Sample\Actions.Core.Sample.csproj", "{2C5BDF3F-726C-4D1B-91D9-AB4209B9DD3C}"
EndProject
Expand Down
5 changes: 1 addition & 4 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"sdk": {
"version": "8.0.200",
"version": "9.0.100",
"rollForward": "major"
},
"tools": {
"dotnet": "8.0.200"
}
}
2 changes: 1 addition & 1 deletion playground/Octokit.Sandbox/Octokit.Sandbox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions samples/Actions.Core.Sample/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-jammy AS build
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:9.0-noble AS build
ARG TARGETARCH
WORKDIR /source

Expand All @@ -13,7 +13,7 @@ RUN dotnet restore "samples/Actions.Core.Sample/Actions.Core.Sample.csproj" -a $
COPY . .
RUN dotnet publish "samples/Actions.Core.Sample/Actions.Core.Sample.csproj" -a $TARGETARCH --no-restore -o /app

FROM mcr.microsoft.com/dotnet/runtime:8.0-jammy-chiseled
FROM mcr.microsoft.com/dotnet/runtime:9.0-noble-chiseled
WORKDIR /app
COPY --from=build /app .
USER root
Expand Down
4 changes: 2 additions & 2 deletions samples/Actions.Glob.Sample/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-jammy AS build
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:9.0-noble AS build
ARG TARGETARCH
WORKDIR /source

Expand All @@ -14,7 +14,7 @@ RUN dotnet restore "samples/Actions.Glob.Sample/Actions.Glob.Sample.csproj" -a $
COPY . .
RUN dotnet publish "samples/Actions.Glob.Sample/Actions.Glob.Sample.csproj" -a $TARGETARCH --no-restore -o /app

FROM mcr.microsoft.com/dotnet/runtime:8.0-jammy-chiseled
FROM mcr.microsoft.com/dotnet/runtime:9.0-noble-chiseled
WORKDIR /app
COPY --from=build /app .
USER root
Expand Down
2 changes: 1 addition & 1 deletion samples/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props, $(MSBuildThisFileDirectory)..))" />

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<OutputType>Exe</OutputType>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
6 changes: 4 additions & 2 deletions src/Actions.Core/Commands/CommandNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ internal static class CommandNames
SetOutput
]);

internal static bool IsConventional(string? command) =>
s_all.Value.Contains(command);
internal static bool IsConventional(string? command)
{
return s_all.Value.Contains(command);
}
}
4 changes: 3 additions & 1 deletion src/Actions.Core/Commands/DefaultCommandIssuer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ namespace Actions.Core.Commands;
internal sealed class DefaultCommandIssuer(IConsole console) : ICommandIssuer
{
/// <inheritdoc />
public void Issue(string commandName, string? message = default) =>
public void Issue(string commandName, string? message = default)
{
IssueCommand(commandName, null, message);
}

/// <inheritdoc />
public void IssueCommand(
Expand Down
2 changes: 2 additions & 0 deletions src/Actions.Core/EnvironmentVariables/Keys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace Actions.Core.EnvironmentVariables;
Justification = "These values correspond to environment variables and I want them to match exactly.")]
#if ACTIONS_CORE_ENVIRONMENTVARIABLES_PUBLIC
public
#else
internal
#endif
static class Keys
{
Expand Down
2 changes: 2 additions & 0 deletions src/Actions.Core/EnvironmentVariables/Prefixes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace Actions.Core.EnvironmentVariables;
Justification = "These values correspond to environment variables and I want them to match exactly.")]
#if ACTIONS_CORE_ENVIRONMENTVARIABLES_PUBLIC
public
#else
internal
#endif
static class Prefixes
{
Expand Down
2 changes: 2 additions & 0 deletions src/Actions.Core/EnvironmentVariables/Suffixes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace Actions.Core.EnvironmentVariables;
/// </summary>
#if ACTIONS_CORE_ENVIRONMENTVARIABLES_PUBLIC
public
#else
internal
#endif
static class Suffixes
{
Expand Down
10 changes: 6 additions & 4 deletions src/Actions.Core/Extensions/GenericExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Actions.Core.Extensions;

static class GenericExtensions
internal static class GenericExtensions
{
/// <summary>
/// Converts the specified object as:
Expand All @@ -17,8 +17,9 @@ static class GenericExtensions
/// <param name="value">The <paramref name="value"/> in context.</param>
/// <param name="typeInfo">The JSON type info, used to serialize the type.</param>
/// <returns>The string representation of the <paramref name="value"/>.</returns>
internal static string ToCommandValue<T>(this T? value, JsonTypeInfo<T>? typeInfo = null) =>
IsAnonymousType(typeof(T))
internal static string ToCommandValue<T>(this T? value, JsonTypeInfo<T>? typeInfo = null)
{
return IsAnonymousType(typeof(T))
? throw new ArgumentException("Generic type T, cannot be anonymous type!")
: value switch
{
Expand All @@ -28,6 +29,7 @@ internal static string ToCommandValue<T>(this T? value, JsonTypeInfo<T>? typeInf
_ when typeInfo is null => value?.ToString() ?? string.Empty,
_ => JsonSerializer.Serialize(value, typeInfo)
};
}

// From: https://stackoverflow.com/a/1650965/2410379
internal static bool IsAnonymousType(this Type type)
Expand All @@ -42,4 +44,4 @@ internal static bool IsAnonymousType(this Type type)
&& typeName.IndexOf("AnonymousType", StringComparison.Ordinal) > 0
};
}
}
}
6 changes: 4 additions & 2 deletions src/Actions.Core/Extensions/ObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ internal static class ObjectExtensions
/// <returns>A new dictionary, with a single key-value pair.</returns>
internal static Dictionary<string, string> ToCommandProperties<T>(
this T value,
[CallerArgumentExpression(nameof(value))] string? paramName = null) =>
new()
[CallerArgumentExpression(nameof(value))] string? paramName = null)
{
return new()
{
[paramName!] = value?.ToString() ?? string.Empty
};
}
}
4 changes: 3 additions & 1 deletion src/Actions.Core/Extensions/ProcessExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ namespace Actions.Core.Extensions;

internal static class ProcessExtensions
{
internal static void GracefulOrForcedShutdown(this int pid) =>
internal static void GracefulOrForcedShutdown(this int pid)
{
Process.GetProcessById(pid)
?.GracefulOrForcedShutdown();
}

internal static void GracefulOrForcedShutdown(this Process process)
{
Expand Down
1 change: 0 additions & 1 deletion src/Actions.Core/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT License.

global using System.Diagnostics;
global using System.Diagnostics.CodeAnalysis;
global using System.Globalization;
global using System.Runtime.CompilerServices;
global using System.Text;
Expand Down
20 changes: 15 additions & 5 deletions src/Actions.Core/Output/IConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,32 @@ namespace Actions.Core.Output;
public interface IConsole
{
/// <inheritdoc cref="Exit" />
void ExitWithCode(int exitCode = 0) =>
void ExitWithCode(int exitCode = 0)
{
Exit(Environment.ExitCode = exitCode);
}

/// <inheritdoc cref="Console.Write(string?)" />
void Write(string? message = null) =>
void Write(string? message = null)
{
Console.Write(message);
}

/// <inheritdoc cref="Console.WriteLine(string?)" />
void WriteLine(string? message = null) =>
void WriteLine(string? message = null)
{
Console.WriteLine(message);
}

/// <inheritdoc cref="TextWriter.Write(string?)" />
void WriteError(string message) =>
void WriteError(string message)
{
Console.Error.Write(message);
}

/// <inheritdoc cref="TextWriter.WriteLine(string?)" />
void WriteErrorLine(string message) =>
void WriteErrorLine(string message)
{
Console.Error.WriteLine(message);
}
}
43 changes: 32 additions & 11 deletions src/Actions.Core/Services/DefaultCoreService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,25 @@ public async ValueTask AddPathAsync(string path)
}

/// <inheritdoc />
public void WriteDebug(string message) =>
public void WriteDebug(string message)
{
commandIssuer.IssueCommand(
CommandNames.Debug, message: message);
}

/// <inheritdoc />
public void EndGroup() =>
public void EndGroup()
{
commandIssuer.Issue(
CommandNames.EndGroup, "");
}

/// <inheritdoc />
public void WriteError(string message, AnnotationProperties? properties = default) =>
public void WriteError(string message, AnnotationProperties? properties = default)
{
commandIssuer.IssueCommand(
CommandNames.Error, properties?.ToCommandProperties(), message);
}

/// <inheritdoc />
public async ValueTask ExportVariableAsync(string name, string value)
Expand Down Expand Up @@ -109,8 +115,10 @@ public string[] GetMultilineInput(string name, InputOptions? options = default)
}

/// <inheritdoc />
public string GetState(string name) =>
GetEnvironmentVariable($"{STATE_}{name}") ?? "";
public string GetState(string name)
{
return GetEnvironmentVariable($"{STATE_}{name}") ?? "";
}

/// <inheritdoc />
public async ValueTask<T> GroupAsync<T>(string name, Func<ValueTask<T>> task)
Expand All @@ -131,12 +139,17 @@ public async ValueTask<T> GroupAsync<T>(string name, Func<ValueTask<T>> task)
}

/// <inheritdoc />
public void WriteInfo(string message) => console.WriteLine(message);
public void WriteInfo(string message)
{
console.WriteLine(message);
}

/// <inheritdoc />
public void WriteNotice(string message, AnnotationProperties? properties = default) =>
public void WriteNotice(string message, AnnotationProperties? properties = default)
{
commandIssuer.IssueCommand(
CommandNames.Notice, properties?.ToCommandProperties(), message);
}

/// <inheritdoc />
public async ValueTask SaveStateAsync<T>(string name, T value, JsonTypeInfo<T>? typeInfo)
Expand All @@ -158,9 +171,11 @@ await fileCommandIssuer.IssueFileCommandAsync(
}

/// <inheritdoc />
public void SetCommandEcho(bool enabled) =>
public void SetCommandEcho(bool enabled)
{
commandIssuer.Issue(
CommandNames.Echo, enabled ? "on" : "off");
}

/// <inheritdoc />
public void SetFailed(string message)
Expand Down Expand Up @@ -191,17 +206,23 @@ await fileCommandIssuer.IssueFileCommandAsync(
}

/// <inheritdoc />
public void SetSecret(string secret) =>
public void SetSecret(string secret)
{
commandIssuer.IssueCommand(
CommandNames.AddMask, null, secret);
}

/// <inheritdoc />
public void StartGroup(string name) =>
public void StartGroup(string name)
{
commandIssuer.Issue(
CommandNames.Group, name);
}

/// <inheritdoc />
public void WriteWarning(string message, AnnotationProperties? properties = default) =>
public void WriteWarning(string message, AnnotationProperties? properties = default)
{
commandIssuer.IssueCommand(
CommandNames.Warning, properties?.ToCommandProperties(), message);
}
}
11 changes: 8 additions & 3 deletions src/Actions.Core/Summaries/Summary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,17 @@ public async Task<Summary> WriteAsync(SummaryWriteOptions? options = default)

/// <summary>Clears the summary buffer and wipes the summary file</summary>
/// <returns>The <c>Summary</c> instance</returns>
public Task<Summary> ClearAsync() =>
EmptyBuffer().WriteAsync(new(true));
public Task<Summary> ClearAsync()
{
return EmptyBuffer().WriteAsync(new(true));
}

/// <summary>Returns the current summary buffer as a string</summary>
/// <returns>A <c>string</c> representation of the summary buffer</returns>
public string Stringify() => _buffer.ToString();
public string Stringify()
{
return _buffer.ToString();
}

/// <summary>Resets the summary buffer without writing to summary file</summary>
/// <returns>The <c>Summary</c> instance</returns>
Expand Down
Loading

0 comments on commit d37453a

Please sign in to comment.