Skip to content

Commit

Permalink
Update Pulumi projects to net6.0
Browse files Browse the repository at this point in the history
.NET Core 3.1 is out of support on December 13th:
https://dotnet.microsoft.com/en-us/platform/support/policy/dotnet-core

We've already stopped testing on .NET Core 3.1, and program gen has been targeting only 6.0 for a while now as well.

This updates the core porjects to only 6.0 as well.

We'll still want to do pulumi/pulumi#11543 in
pu/pu to update sdkgen.
  • Loading branch information
Frassle committed Dec 22, 2022
1 parent 83ac275 commit fb505e6
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 57 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
- [auto] Adds SkipInstallDependencies option for Remote Workspaces
[#64](https://github.com/pulumi/pulumi-dotnet/pull/64)

- [sdk] Drop support for .NET Core 3.1.
[#10](https://github.com/pulumi/pulumi-dotnet/pull/10)

### Bug Fixes
36 changes: 18 additions & 18 deletions build/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ open CliWrap
open CliWrap.Buffered

/// Recursively tries to find the parent of a file starting from a directory
let rec findParent (directory: string) (fileToFind: string) =
let rec findParent (directory: string) (fileToFind: string) =
let path = if Directory.Exists(directory) then directory else Directory.GetParent(directory).FullName
let files = Directory.GetFiles(path)
if files.Any(fun file -> Path.GetFileName(file).ToLower() = fileToFind.ToLower())
then path
if files.Any(fun file -> Path.GetFileName(file).ToLower() = fileToFind.ToLower())
then path
else findParent (DirectoryInfo(path).Parent.FullName) fileToFind

let repositoryRoot = findParent __SOURCE_DIRECTORY__ "README.md";
Expand All @@ -28,13 +28,13 @@ let pulumiLanguageDotnet = Path.Combine(repositoryRoot, "pulumi-language-dotnet"

/// Runs `dotnet clean` command against the solution file,
/// then proceeds to delete the `bin` and `obj` directory of each project in the solution
let cleanSdk() =
let cleanSdk() =
let cmd = Cli.Wrap("dotnet").WithArguments("clean").WithWorkingDirectory(sdk)
let output = cmd.ExecuteAsync().GetAwaiter().GetResult()
if output.ExitCode <> 0 then
failwith "Clean failed"

let projects = [
let projects = [
pulumiSdk
pulumiSdkTests
pulumiAutomationSdk
Expand All @@ -47,7 +47,7 @@ let cleanSdk() =
Shell.deleteDir (Path.Combine(project, "obj"))

/// Runs `dotnet restore` against the solution file without using cache
let restoreSdk() =
let restoreSdk() =
printfn "Restoring Pulumi SDK packages"
if Shell.Exec("dotnet", "restore --no-cache", sdk) <> 0
then failwith "restore failed"
Expand All @@ -60,15 +60,15 @@ let integrationTestNames() =
let output = cmd.ExecuteBufferedAsync().GetAwaiter().GetResult()
if output.ExitCode <> 0 then
failwith $"Failed to list go tests from {integrationTests}"

output.StandardOutput.Split("\n")
|> Array.filter (fun line -> line.StartsWith "Test")

let listIntegrationTests() =
for testName in integrationTestNames() do
printfn $"{testName}"

let buildSdk() =
let buildSdk() =
cleanSdk()
restoreSdk()
printfn "Building Pulumi SDK"
Expand All @@ -89,7 +89,7 @@ let publishSdks() =
pulumiAutomationSdk
pulumiFSharp
]

match publishResults with
| Error errorMsg -> printfn $"{errorMsg}"
| Ok results ->
Expand All @@ -108,35 +108,35 @@ let publishSdks() =
results
|> List.where (fun result -> result.HasErrored())
|> List.map (fun result -> result.ProjectName())

failwith $"Some nuget packages were not published: {failedProjectsAtPublishing}"

let cleanLanguagePlugin() =
let cleanLanguagePlugin() =
let plugin = Path.Combine(pulumiLanguageDotnet, "pulumi-language-dotnet")
if File.Exists plugin then File.Delete plugin

let buildLanguagePlugin() =
let buildLanguagePlugin() =
cleanLanguagePlugin()
printfn "Building pulumi-language-dotnet Plugin"
if Shell.Exec("go", "build", pulumiLanguageDotnet) <> 0
then failwith "Building pulumi-language-dotnet failed"
let output = Path.Combine(pulumiLanguageDotnet, "pulumi-language-dotnet")
printfn $"Built binary {output}"

let testLanguagePlugin() =
let testLanguagePlugin() =
cleanLanguagePlugin()
printfn "Testing pulumi-language-dotnet Plugin"
if Shell.Exec("go", "test", Path.Combine(repositoryRoot, "pulumi-language-dotnet")) <> 0
then failwith "Testing pulumi-language-dotnet failed"

let testPulumiSdk() =
let testPulumiSdk() =
cleanSdk()
restoreSdk()
printfn "Testing Pulumi SDK"
if Shell.Exec("dotnet", "test --configuration Release", pulumiSdkTests) <> 0
then failwith "tests failed"

let testPulumiAutomationSdk() =
let testPulumiAutomationSdk() =
cleanSdk()
restoreSdk()
printfn "Testing Pulumi Automation SDK"
Expand All @@ -151,15 +151,15 @@ let syncProtoFiles() = GitSync.repository {
sourcePath = [ "proto"; "pulumi" ]
destinationPath = [ "proto"; "pulumi" ]
}

GitSync.folder {
sourcePath = [ "proto"; "google"; "protobuf" ]
destinationPath = [ "proto"; "google"; "protobuf" ]
}
]
}

let runSpecificIntegrationTest(testName: string) =
let runSpecificIntegrationTest(testName: string) =
buildLanguagePlugin()
cleanSdk()
if Shell.Exec("go", $"test -run=^{testName}$", Path.Combine(repositoryRoot, "integration_tests")) <> 0
Expand All @@ -174,7 +174,7 @@ let runAllIntegrationTests() =
then failwith $"Integration test '{testName}' failed"

[<EntryPoint>]
let main(args: string[]) : int =
let main(args: string[]) : int =
match args with
| [| "clean-sdk" |] -> cleanSdk()
| [| "build-sdk" |] -> buildSdk()
Expand Down
1 change: 1 addition & 0 deletions sdk/Pulumi.Automation/Commands/LocalPulumiCmd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public EventLogFile(string command)
public void Dispose()
{
var dir = Path.GetDirectoryName(this.FilePath);
System.Diagnostics.Debug.Assert(dir != null, "FilePath had no directory name");
try
{
Directory.Delete(dir, recursive: true);
Expand Down
2 changes: 1 addition & 1 deletion sdk/Pulumi.Automation/Pulumi.Automation.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Pulumi</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public override StackSettingsConfigValue Read(ref Utf8JsonReader reader, Type ty
// check if plain string
if (element.ValueKind == JsonValueKind.String)
{
var value = element.GetString();
var value = element.GetString()!;
return new StackSettingsConfigValue(value, false);
}

Expand All @@ -33,8 +33,8 @@ public override StackSettingsConfigValue Read(ref Utf8JsonReader reader, Type ty
{
throw new JsonException($"Unable to deserialize [{typeToConvert.FullName}] as a secure string. Expecting a string secret.");
}
return new StackSettingsConfigValue(secureValue.GetString(), true);

return new StackSettingsConfigValue(secureValue.GetString()!, true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class StringToEnumJsonConverter<TEnum, TConverter> : JsonConverter<TEnu

public override TEnum Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return _converter.Convert(reader.GetString());
return _converter.Convert(reader.GetString()!);
}

public override void Write(Utf8JsonWriter writer, TEnum value, JsonSerializerOptions options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public override object Read(ref Utf8JsonReader reader, Type typeToConvert, JsonS
return datetime;
}

return reader.GetString();
return reader.GetString()!;
}

if (reader.TokenType == JsonTokenType.StartArray)
{
return JsonSerializer.Deserialize<object[]>(ref reader, options);
return JsonSerializer.Deserialize<object[]>(ref reader, options)!;
}

if (reader.TokenType == JsonTokenType.StartObject)
Expand All @@ -61,7 +61,7 @@ public override object Read(ref Utf8JsonReader reader, Type typeToConvert, JsonS
throw new JsonException("Unable to retrieve property name.");

reader.Read();
dictionary[propertyName] = JsonSerializer.Deserialize<object>(ref reader, options);
dictionary[propertyName] = JsonSerializer.Deserialize<object>(ref reader, options)!;

reader.Read();
}
Expand Down
4 changes: 2 additions & 2 deletions sdk/Pulumi.Automation/Serialization/LocalSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public LocalSerializer()
}

public T DeserializeJson<T>(string content)
=> JsonSerializer.Deserialize<T>(content, this._jsonOptions);
=> JsonSerializer.Deserialize<T>(content, this._jsonOptions)!;

public T DeserializeYaml<T>(string content)
where T : class
Expand All @@ -45,7 +45,7 @@ public static JsonSerializerOptions BuildJsonSerializerOptions()
var options = new JsonSerializerOptions
{
AllowTrailingCommas = true,
IgnoreNullValues = true,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
};

Expand Down
4 changes: 2 additions & 2 deletions sdk/Pulumi.Automation/WorkspaceStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ void OnPreviewEvent(EngineEvent @event)
return ImmutableList<UpdateSummary>.Empty;

var jsonOptions = LocalSerializer.BuildJsonSerializerOptions();
var list = JsonSerializer.Deserialize<List<UpdateSummary>>(result.StandardOutput, jsonOptions);
var list = JsonSerializer.Deserialize<List<UpdateSummary>>(result.StandardOutput, jsonOptions)!;
return list.ToImmutableList();
}

Expand Down Expand Up @@ -705,7 +705,7 @@ private class InlineLanguageHost : IAsyncDisposable
try
{
var serverFeatures = this._host.Services.GetRequiredService<IServer>().Features;
var addresses = serverFeatures.Get<IServerAddressesFeature>().Addresses.ToList();
var addresses = serverFeatures.Get<IServerAddressesFeature>()!.Addresses.ToList();
Debug.Assert(addresses.Count == 1, "Server should only be listening on one address");
var uri = new Uri(addresses[0]);
this._portTcs.TrySetResult(uri.Port);
Expand Down
2 changes: 1 addition & 1 deletion sdk/Pulumi.FSharp/Pulumi.FSharp.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Pulumi</Authors>
<Company>Pulumi Corp.</Company>
Expand Down
31 changes: 7 additions & 24 deletions sdk/Pulumi/Core/Output.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
Expand Down Expand Up @@ -185,8 +184,8 @@ internal static Output<ImmutableArray<T>> Concat<T>(Output<ImmutableArray<T>> va
=> Tuple(values1, values2).Apply(tuple => tuple.Item1.AddRange(tuple.Item2));

/// <summary>
/// Uses <see cref="System.Text.Json.JsonSerializer.SerializeAsync{T}"/> to serialize the given <see
/// cref="Output{T}"/> value into a JSON string.
/// Uses <see cref="System.Text.Json.JsonSerializer.SerializeAsync{T}(System.IO.Stream, T, JsonSerializerOptions?, System.Threading.CancellationToken)"/>
/// to serialize the given <see cref="Output{T}"/> value into a JSON string.
/// </summary>
public static Output<string> JsonSerialize<T>(Output<T> value, System.Text.Json.JsonSerializerOptions? options = null)
{
Expand All @@ -206,26 +205,9 @@ async Task<OutputData<string>> GetData()
// This needs to handle nested potentially secret and unknown Output values, we do this by
// hooking options to handle any seen Output<T> values.

// TODO: This can be simplified in net6.0 to just new System.Text.Json.JsonSerializerOptions(options);
var internalOptions = new System.Text.Json.JsonSerializerOptions();
internalOptions.AllowTrailingCommas = options?.AllowTrailingCommas ?? internalOptions.AllowTrailingCommas;
if (options != null)
{
foreach(var converter in options.Converters)
{
internalOptions.Converters.Add(converter);
}
}
internalOptions.DefaultBufferSize = options?.DefaultBufferSize ?? internalOptions.DefaultBufferSize;
internalOptions.DictionaryKeyPolicy = options?.DictionaryKeyPolicy ?? internalOptions.DictionaryKeyPolicy;
internalOptions.Encoder = options?.Encoder ?? internalOptions.Encoder;
internalOptions.IgnoreNullValues = options?.IgnoreNullValues ?? internalOptions.IgnoreNullValues;
internalOptions.IgnoreReadOnlyProperties = options?.IgnoreReadOnlyProperties ?? internalOptions.IgnoreReadOnlyProperties;
internalOptions.MaxDepth = options?.MaxDepth ?? internalOptions.MaxDepth;
internalOptions.PropertyNameCaseInsensitive = options?.PropertyNameCaseInsensitive ?? internalOptions.PropertyNameCaseInsensitive;
internalOptions.PropertyNamingPolicy = options?.PropertyNamingPolicy ?? internalOptions.PropertyNamingPolicy;
internalOptions.ReadCommentHandling = options?.ReadCommentHandling ?? internalOptions.ReadCommentHandling;
internalOptions.WriteIndented = options?.WriteIndented ?? internalOptions.WriteIndented;
var internalOptions = options == null ?
new System.Text.Json.JsonSerializerOptions() :
new System.Text.Json.JsonSerializerOptions(options);

// Add the magic converter to allow us to do nested outputs
var outputConverter = new OutputJsonConverter();
Expand Down Expand Up @@ -285,7 +267,8 @@ public sealed class Output<T> : IOutput

if (Deployment.TryGetInternalInstance(out var instance))
{
instance.Runner.RegisterTask(TypeNameHelper.GetTypeDisplayName(GetType(), false), dataTask);
var description = GetType().ToString();
instance.Runner.RegisterTask(description, dataTask);
}
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/Pulumi/Deployment/Deployment_Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private static ImmutableHashSet<string> ParseConfigSecretKeys()
var envObject = JsonDocument.Parse(envConfigSecretKeys);
foreach (var element in envObject.RootElement.EnumerateArray())
{
parsedConfigSecretKeys.Add(element.GetString());
parsedConfigSecretKeys.Add(element.ToString());
}
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/Pulumi/Pulumi.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Pulumi</Authors>
Expand Down

0 comments on commit fb505e6

Please sign in to comment.