Skip to content

Commit

Permalink
chore: Update Dotty project and package lists, other fixes (#2883)
Browse files Browse the repository at this point in the history
  • Loading branch information
tippmar-nr authored Nov 14, 2024
1 parent e853842 commit 9e77efa
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 15 deletions.
46 changes: 36 additions & 10 deletions .github/workflows/scripts/nugetSlackNotifications/CsprojHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,30 @@ public class CsprojHandler
{
public static async Task<List<string>> UpdatePackageReferences(string csprojPath, List<NugetVersionData> versionDatas)
{
Log.Information("Processing {CSProj}...", csprojPath);
var updateLog = new List<string>();
var csprojLines = await File.ReadAllLinesAsync(csprojPath);

var packages = Parse(csprojLines);
var packages = Parse(csprojPath, csprojLines);
if (packages.Count == 0)
{
Log.Warning("No packages found in csproj file " + csprojPath);
return updateLog;
}

var updatedCsProj = false;
foreach (var versionData in versionDatas)
{
var matchingPackages = packages.Where(p => p.Include == versionData.PackageName).ToList();
if (matchingPackages.Count == 0)
{
Log.Warning($"No matching packages found in csproj file for {versionData.PackageName}");
//Log.Warning($"No matching packages found in csproj file for {versionData.PackageName}");
continue;
}

foreach (var package in matchingPackages)
{
if(package.VersionAsVersion < versionData.NewVersionAsVersion && package.Pin)
if (package.VersionAsVersion < versionData.NewVersionAsVersion && package.Pin)
{
Log.Warning($"Not updating {package.Include} for {package.TargetFramework}, it is pinned to {package.Version}. Manual verification recommended.");
continue;
Expand All @@ -46,6 +48,7 @@ public static async Task<List<string>> UpdatePackageReferences(string csprojPath
var pattern = @"\d+(\.\d+){2,3}";
var result = Regex.Replace(csprojLines[package.LineNumber], pattern, versionData.NewVersion);
csprojLines[package.LineNumber] = result;
updatedCsProj = true;

updateLog.Add($"- Package [{versionData.PackageName}]({versionData.Url}) " +
$"for {package.TargetFramework} " +
Expand All @@ -55,38 +58,61 @@ public static async Task<List<string>> UpdatePackageReferences(string csprojPath
}
}

await File.WriteAllLinesAsync(csprojPath, csprojLines);
updateLog.Add("");
if (updatedCsProj)
{
await File.WriteAllLinesAsync(csprojPath, csprojLines);
updateLog.Add("");
}

return updateLog;
}

private static List<PackageReference> Parse(string[] csprojLines)
private static List<PackageReference> Parse(string csProjPath, string[] csprojLines)
{
var packages = new List<PackageReference>();
try
{
var unclosed = false;
var curLine = "";
for (int i = 0; i < csprojLines.Length; i++)
{
var line = csprojLines[i];
if (!line.Contains("PackageReference"))
curLine += csprojLines[i];
if (!unclosed && !curLine.Contains("PackageReference"))
{
curLine = "";
continue;
}

if (unclosed && curLine.Contains("</PackageReference>"))
{
unclosed = false;
}
else if (!curLine.EndsWith("/>"))
{
unclosed = true;
curLine += Environment.NewLine;
continue;
}
else
unclosed = false;

var serializer = new XmlSerializer(typeof(PackageReference));
using (var reader = new StringReader(line))
using (var reader = new StringReader(curLine))
{
var packageReference = (PackageReference)serializer.Deserialize(reader);
packageReference.LineNumber = i;
packages.Add(packageReference);
}

if (!unclosed)
curLine = "";
}

return packages;
}
catch (Exception e)
{
Log.Error(e, "XML issue");
Log.Error(e, $"XML issue while parsing {csProjPath}");
return packages;
}
}
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/scripts/nugetSlackNotifications/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ static async Task Main()
catch (Exception ex)
{
Log.Error(ex, $"Caught exception while checking {package.PackageName} for updates.");
await SendSlackNotification($"Dotty: caught exception while checking {package.PackageName} for updates: {ex}");
if (!_testMode)
await SendSlackNotification($"Dotty: caught exception while checking {package.PackageName} for updates: {ex}");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageReference Include="Octokit" Version="13.0.1" />
<PackageReference Include="Serilog" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Nuget.Protocol" Version="6.11.1" />
<PackageReference Include="Nuget.Protocol" Version="6.12.1" />
</ItemGroup>

<ItemGroup>
Expand All @@ -25,4 +25,8 @@
</None>
</ItemGroup>

<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
"ignoreMinor": false,
"ignoreReason": "frequent patch releases create too much noise"
},
{
"packageName": "awssdk.dynamodbv2"
},
{
"packageName": "confluent.kafka"
},
Expand All @@ -53,13 +56,31 @@
"ignoreMinor": false,
"ignoreReason": "frequent patch releases create too much noise"
},
{
"packageName": "enyimmemcachedcore"
},
{
"packageName": "log4net",
"ignorePatch": true,
"ignoreMinor": true,
"ignoreMajor": true,
"ignoreReason": "Breaking major update. See https://github.com/newrelic/newrelic-dotnet-agent/issues/2764"
},
{
"packageName": "microsoft.azure.functions.worker"
},
{
"packageName": "microsoft.azure.functions.worker.extensions.http"
},
{
"packageName": "microsoft.azure.functions.worker.extensions.http.aspnetcore"
},
{
"packageName": "microsoft.azure.functions.worker.extensions.storage.queues"
},
{
"packageName": "microsoft.azure.functions.worker.sdk"
},
{
"packageName": "microsoft.extensions.logging"
},
Expand All @@ -85,10 +106,13 @@
{
"packageName": "nest"
},
{
"packageName": "newrelic.agent.api"
},
{
"packageName": "nlog"
},
{
{
"packageName": "nservicebus"
},
{
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/scripts/nugetSlackNotifications/projectInfo.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
[
{
"projectFile": "tests/Agent/IntegrationTests/SharedApplications/Common/MFALatestPackages/MFALatestPackages.csproj"
},
{
"projectFile": "tests/Agent/IntegrationTests/Applications/AzureFunctionApplication/AzureFunctionApplication.csproj"
},
{
"projectFile": "tests/Agent/IntegrationTests/Applications/LambdaSelfExecutingAssembly/LambdaSelfExecutingAssembly.csproj"
},
{
"projectFile": "tests/Agent/IntegrationTests/ContainerApplications/AwsSdkTestApp/AwsSdkTestApp.csproj"
},
{
"projectFile": "tests/Agent/IntegrationTests/ContainerApplications/KafkaTestApp/KafkaTestApp.csproj"
},
{
"projectFile": "tests/Agent/IntegrationTests/ContainerApplications/MemcachedTestApp/MemcachedTestApp.csproj"
},
{
"projectFile": "tests/Agent/IntegrationTests/ContainerApplications/SmokeTestApp/SmokeTestApp.csproj"
}
]
2 changes: 1 addition & 1 deletion build/NugetValidator/NugetValidator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="NuGet.Protocol" Version="6.11.1" />
<PackageReference Include="NuGet.Protocol" Version="6.12.1" />
<PackageReference Include="YamlDotNet" Version="16.2.0" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion build/NugetVersionDeprecator/NugetVersionDeprecator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NuGet.Protocol" Version="6.11.1" />
<PackageReference Include="NuGet.Protocol" Version="6.12.1" />
<PackageReference Include="Octokit" Version="13.0.1" />
<PackageReference Include="RestSharp" Version="112.1.0" />
<PackageReference Include="RestSharp.Serializers.NewtonsoftJson" Version="112.1.0" />
Expand Down

0 comments on commit 9e77efa

Please sign in to comment.