From 1f81445ac7b7b8910de82bc4d626d484a00271fc Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Mon, 18 Dec 2023 19:11:41 -0600 Subject: [PATCH] Multi-target net48 and net7.0, streamline Docker image --- .github/workflows/build.yml | 12 +++- .github/workflows/release.yml | 12 +++- KSPMMCfgParser/KSPMMCfgParser.csproj | 12 ++-- KSPMMCfgValidator/Dockerfile | 17 ++++- KSPMMCfgValidator/KSPMMCfgValidator.csproj | 66 +++++++++++------- .../Properties/Resources.Designer.cs | 69 ------------------- .../SingleAssemblyResourceManager.cs | 37 +++++++--- Tests/Tests.csproj | 34 ++++----- action.yml | 3 +- 9 files changed, 127 insertions(+), 135 deletions(-) delete mode 100644 KSPMMCfgValidator/Properties/Resources.Designer.cs diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2666bad..c56e46f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,11 +23,17 @@ jobs: with: path: ~/.nuget/packages key: nuget-packref-modules-${{ hashFiles('**/*.csproj') }} + - name: Setup .NET Core + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '7' - name: Restore, build, and test - run: msbuild -r -p:configuration=Debug + run: | + msbuild -r -p:configuration=Debug -p:TargetFramework=net48 + dotnet build -f net7.0 - name: Smoke test the validator outside the build dir run: | - cp _build/KSPMMCfgValidator/Debug/bin/net461/KSPMMCfgValidator.exe . + cp _build/KSPMMCfgValidator/Debug/bin/net48/Repack/KSPMMCfgValidator.exe . chmod a+x KSPMMCfgValidator.exe mono ./KSPMMCfgValidator.exe @@ -42,6 +48,6 @@ jobs: uses: actions/upload-artifact@v2 with: name: KSPMMCfgValidator.exe - path: _build/KSPMMCfgValidator/Debug/bin/net461/KSPMMCfgValidator.exe + path: _build/KSPMMCfgValidator/Debug/bin/net48/Repack/KSPMMCfgValidator.exe retention-days: 7 if: github.event_name == 'pull_request' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6c2f343..3c36291 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,11 +15,17 @@ jobs: run: apt-get update && apt-get install -y wget jq - name: Checkout uses: actions/checkout@v3 + - name: Setup .NET Core + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '7' - name: Restore, build, and test - run: msbuild -r -p:configuration=Release + run: | + msbuild -r -p:configuration=Debug -p:TargetFramework=net48 + dotnet build -f net7.0 - name: Smoke test the validator outside the build dir run: | - cp _build/KSPMMCfgValidator/Release/bin/net461/KSPMMCfgValidator.exe . + cp _build/KSPMMCfgValidator/Release/bin/net48/Repack/KSPMMCfgValidator.exe . chmod a+x KSPMMCfgValidator.exe mono ./KSPMMCfgValidator.exe @@ -46,7 +52,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.release_data.outputs.upload_url }} - asset_path: _build/KSPMMCfgValidator/Release/bin/net461/KSPMMCfgValidator.exe + asset_path: _build/KSPMMCfgValidator/Release/bin/net48/Repack/KSPMMCfgValidator.exe asset_name: KSPMMCfgValidator.exe asset_content_type: application/vnd.microsoft.portable-executable diff --git a/KSPMMCfgParser/KSPMMCfgParser.csproj b/KSPMMCfgParser/KSPMMCfgParser.csproj index 6c6cbe8..0748c34 100644 --- a/KSPMMCfgParser/KSPMMCfgParser.csproj +++ b/KSPMMCfgParser/KSPMMCfgParser.csproj @@ -16,9 +16,7 @@ false 8.0 enable - net461 - .NETFramework - v4.6.1 + net48;net7.0 true true false @@ -42,12 +40,14 @@ https://github.com/KSP-CKAN/KSPMMCfgParser git - + - - + + + + diff --git a/KSPMMCfgValidator/Dockerfile b/KSPMMCfgValidator/Dockerfile index dd7d161..61f4bba 100644 --- a/KSPMMCfgValidator/Dockerfile +++ b/KSPMMCfgValidator/Dockerfile @@ -1,3 +1,18 @@ -FROM mono:latest +FROM ubuntu:latest + +# Don't prompt for time zone +ENV DEBIAN_FRONTEND=noninteractive + +# Set up Mono's APT repo +RUN apt-get update \ + && apt-get install -y --no-install-recommends ca-certificates gnupg \ + && gpg --homedir /tmp --no-default-keyring --keyring /usr/share/keyrings/mono-official-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF \ + && echo "deb [signed-by=/usr/share/keyrings/mono-official-archive-keyring.gpg] https://download.mono-project.com/repo/ubuntu stable-focal main" | tee /etc/apt/sources.list.d/mono-official-stable.list \ + && apt-get update + +# Install the necessary pieces of Mono +RUN apt-get install -y --no-install-recommends \ + mono-runtime ca-certificates-mono libmono-microsoft-csharp4.0-cil libmono-system-data4.0-cil libmono-system-runtime-serialization4.0-cil libmono-system-transactions4.0-cil libmono-system-net-http-webrequest4.0-cil + ADD KSPMMCfgValidator.exe /usr/local/bin/. ENTRYPOINT ["mono", "/usr/local/bin/KSPMMCfgValidator.exe"] diff --git a/KSPMMCfgValidator/KSPMMCfgValidator.csproj b/KSPMMCfgValidator/KSPMMCfgValidator.csproj index 2a53384..279aa23 100644 --- a/KSPMMCfgValidator/KSPMMCfgValidator.csproj +++ b/KSPMMCfgValidator/KSPMMCfgValidator.csproj @@ -17,42 +17,60 @@ false 8.0 enable - net461 - .NETFramework - v4.6.1 + net48;net7.0 true true false None $(BaseIntermediateOutputPath)$(AssemblyName).xml + NU1701 + PrepareResources;$(CompileDependsOn) - - - + + - + GeneratePathProperty="true" + PrivateAssets="All" /> + + TargetFramework=$(TargetFramework) + + ReferenceOutputAssembly="false"> + false + TargetFramework=$(TargetFramework) + + + MSBuild:Compile + $(IntermediateOutputPath)Resources.Designer.cs + $(IntermediateOutputPath)Resources.Designer.cs + $(Language) + $(RootNamespace).Properties + %(Filename) + + + + - - - - - - - - + + + + diff --git a/KSPMMCfgValidator/Properties/Resources.Designer.cs b/KSPMMCfgValidator/Properties/Resources.Designer.cs deleted file mode 100644 index 6580323..0000000 --- a/KSPMMCfgValidator/Properties/Resources.Designer.cs +++ /dev/null @@ -1,69 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. (I WISH!) -// -//------------------------------------------------------------------------------ - -namespace KSPMMCfgValidator.Properties { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() { } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) - { - resourceMan = new SingleAssemblyResourceManager("KSPMMCfgValidator.Properties.Resources", typeof(Resources).Assembly); - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - internal static string ErrorValidating { - get { - return ResourceManager.GetString("ErrorValidating", resourceCulture); - } - } - - } -} diff --git a/KSPMMCfgValidator/SingleAssemblyResourceManager.cs b/KSPMMCfgValidator/SingleAssemblyResourceManager.cs index c21b2a3..068c590 100644 --- a/KSPMMCfgValidator/SingleAssemblyResourceManager.cs +++ b/KSPMMCfgValidator/SingleAssemblyResourceManager.cs @@ -1,7 +1,6 @@ using System.IO; using System.Globalization; using System.Resources; -using System.Collections; using System.Reflection; using System.Collections.Generic; @@ -9,33 +8,49 @@ namespace KSPMMCfgValidator { // Thanks and credit to this guy: https://stackoverflow.com/q/1952638/2422988 - class SingleAssemblyResourceManager : ResourceManager + /// + /// Wrapper around ResourceManager that retrieves strings from the assembly + /// rather than external files + /// + public class SingleAssemblyResourceManager : ResourceManager { - public SingleAssemblyResourceManager(string basename, Assembly assembly) : base(basename, assembly) + /// + /// Initialize the resource manager + /// + /// To be passed to ResourceManager + /// To be passed to ResourceManager + public SingleAssemblyResourceManager(string basename, Assembly assembly) + : base(basename, assembly) { } - protected override ResourceSet InternalGetResourceSet(CultureInfo culture, + /// + /// Provides resources from the assembly to ResourceManager + /// + /// The language to get + /// Set to false to avoid loading if not already cached + /// Just gets passed to base class implementation + /// + protected override ResourceSet? InternalGetResourceSet(CultureInfo culture, bool createIfNotExists, bool tryParents) { - ResourceSet rs; - if (!myResourceSets.TryGetValue(culture, out rs)) + if (!myResourceSets.TryGetValue(culture, out ResourceSet? rs)) { // Lazy-load default language (without caring about duplicate assignment in race conditions, no harm done) - if (neutralResourcesCulture == null) + if (MainAssembly != null) { - neutralResourcesCulture = GetNeutralResourcesLanguage(this.MainAssembly); + neutralResourcesCulture ??= GetNeutralResourcesLanguage(MainAssembly); } // If we're asking for the default language, then ask for the // invariant (non-specific) resources. - if (neutralResourcesCulture.Equals(culture)) + if (neutralResourcesCulture?.Equals(culture) ?? true) { culture = CultureInfo.InvariantCulture; } string resourceFileName = GetResourceFileName(culture); - Stream store = this.MainAssembly.GetManifestResourceStream(resourceFileName); + Stream? store = MainAssembly?.GetManifestResourceStream(resourceFileName); // If we found the appropriate resources in the local assembly if (store != null) @@ -53,6 +68,6 @@ protected override ResourceSet InternalGetResourceSet(CultureInfo culture, } private CultureInfo? neutralResourcesCulture; - private Dictionary myResourceSets = new Dictionary(); + private readonly Dictionary myResourceSets = new Dictionary(); } } diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index b160a73..581a244 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -1,4 +1,4 @@ - + KSPMMCfgParser.Tests ..\_build\$(AssemblyName)\$(Configuration)\bin\ @@ -17,28 +17,30 @@ false 8.0 enable - net461 - .NETFramework - v4.6.1 + net48;net7.0 true - + - - - - - - - - - + + + + - + + + + + TargetFramework=$(TargetFramework) + diff --git a/action.yml b/action.yml index eb807a4..3eb07ae 100644 --- a/action.yml +++ b/action.yml @@ -1,7 +1,6 @@ name: Kerbal Space Program Module Manager Config File Validator description: Checks .cfg files for syntax errors -author: - - HebaruSan +author: HebaruSan runs: using: docker image: docker://kspckan/kspmmcfgvalidator