From 0794ba0c05999922780d0220aa52d01368df80c9 Mon Sep 17 00:00:00 2001 From: kohanis Date: Mon, 18 Mar 2024 07:21:44 +0300 Subject: [PATCH] Adjusting workflows --- .config/dotnet-tools.json | 2 +- .github/workflows/build.yml | 53 +++++++++++++++++++-------- .github/workflows/publish_release.yml | 47 ++++++++++++------------ Harmony.sln | 1 + HarmonyTests/HarmonyTests.csproj | 6 +-- build.cake | 45 ++++++++++------------- global.json | 5 +++ 7 files changed, 90 insertions(+), 69 deletions(-) create mode 100644 global.json diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 31e896e9..da200cda 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -3,7 +3,7 @@ "isRoot": true, "tools": { "cake.tool": { - "version": "2.0.0", + "version": "4.0.0", "commands": [ "dotnet-cake" ] diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3b15f21d..f4e846d4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,34 +1,53 @@ name: Build -on: [push, pull_request] +on: + push: + branches: + - "**" + pull_request: + workflow_dispatch: + +env: + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 + DOTNET_CLI_TELEMETRY_OPTOUT: 1 + DOTNET_NOLOGO: 1 jobs: test: runs-on: windows-latest steps: - - uses: actions/checkout@v1 - - uses: actions/setup-dotnet@v1 + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup dotnet + uses: actions/setup-dotnet@v4 with: - dotnet-version: | - 3.1.x - 6.0.300 + dotnet-version: | + 3.x + 5.x + 6.x + 7.x + 8.x + - name: Log dotnet info run: dotnet --info + - name: Run test run: ./build.ps1 --target=Test + build: runs-on: windows-latest if: github.ref == 'refs/heads/master' needs: test steps: - - uses: actions/checkout@v1 - - - uses: actions/setup-dotnet@v1 + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup dotnet + uses: actions/setup-dotnet@v4 with: - dotnet-version: | - 3.1.x - 6.0.300 + dotnet-version: '8.x' - name: Make repo pushable env: @@ -49,9 +68,11 @@ jobs: - name: Get target file id: getfilename shell: bash - run: echo "::set-output name=file::$(ls ./Harmony/bin/Release/HarmonyX*.nupkg)" - - - uses: actions/upload-artifact@v1 + run: | + echo "file=$(ls ./Harmony/bin/Release/HarmonyX*.nupkg)" >> "$GITHUB_OUTPUT" + + - name: Upload HarmonyX nupkg + uses: actions/upload-artifact@v4 with: - path: ${{ steps.getfilename.outputs.file }} name: HarmonyX + path: ${{ steps.getfilename.outputs.file }} diff --git a/.github/workflows/publish_release.yml b/.github/workflows/publish_release.yml index e2decbf1..e7e62be3 100644 --- a/.github/workflows/publish_release.yml +++ b/.github/workflows/publish_release.yml @@ -5,46 +5,47 @@ on: tags: - 'v*' +env: + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 + DOTNET_CLI_TELEMETRY_OPTOUT: 1 + DOTNET_NOLOGO: 1 + +permissions: + contents: write + jobs: build: runs-on: windows-latest steps: - - uses: actions/checkout@v1 - - uses: actions/setup-dotnet@v1 - with: - dotnet-version: | - 3.1.x - 6.0.300 + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup dotnet + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '8.x' + - name: Get Version id: get_version shell: bash run: | tag=${GITHUB_REF##*/} echo Current branch: ${tag:1} - echo ::set-output name=version_num::${tag:1} + echo "version_num=${tag:1}" >> "$GITHUB_OUTPUT" + - name: Run build script run: ./build.ps1 --target=Build shell: powershell + - name: Create Release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: softprops/action-gh-release@v2 with: - tag_name: ${{ github.ref }} - release_name: Release ${{ github.ref }} + name: Release ${{ github.ref }} body: "" draft: false prerelease: false - - name: Upload Release Asset - id: upload-release-asset - uses: actions/upload-release-asset@v1.0.1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./Harmony/bin/Release/HarmonyX.${{ steps.get_version.outputs.version_num }}.nupkg - asset_name: HarmonyX.${{ steps.get_version.outputs.version_num }}.nupkg - asset_content_type: application/zip + token: ${{ secrets.GITHUB_TOKEN }} + files: | + ./Harmony/bin/Release/HarmonyX.${{ steps.get_version.outputs.version_num }}.nupkg diff --git a/Harmony.sln b/Harmony.sln index 39258b9b..56087deb 100644 --- a/Harmony.sln +++ b/Harmony.sln @@ -11,6 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution LICENSE = LICENSE Directory.Build.props = Directory.Build.props README.md = README.md + build.cake = build.cake EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Harmony", "Harmony\Harmony.csproj", "{69AEE16A-B6E7-4642-8081-3928B32455DF}" diff --git a/HarmonyTests/HarmonyTests.csproj b/HarmonyTests/HarmonyTests.csproj index 03457ec0..c9c8065a 100644 --- a/HarmonyTests/HarmonyTests.csproj +++ b/HarmonyTests/HarmonyTests.csproj @@ -32,9 +32,9 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/build.cake b/build.cake index 2d95cbc0..2df313b9 100644 --- a/build.cake +++ b/build.cake @@ -1,9 +1,8 @@ -#addin nuget:?package=Cake.FileHelpers&version=4.0.0 -#tool "nuget:?package=NUnit.ConsoleRunner&version=3.12.0" -#addin "nuget:?package=Cake.Incubator&version=6.0.0" +#addin nuget:?package=Cake.FileHelpers&version=7.0.0 var target = Argument("target", "Build"); var nugetKey = Argument("nugetKey", ""); +var useTmpLocalNuget = Argument("useTmpLocalNuget", false); string RunGit(string command, string separator = "") { @@ -22,50 +21,44 @@ Task("Cleanup") CleanDirectories(GetDirectories("./**/obj/")); }); -Task("PullDependencies") - .Does(() => -{ - Information("Restoring NuGet packages"); - DotNetRestore("."); -}); - Task("Build") .IsDependentOn("Cleanup") - .IsDependentOn("PullDependencies") .Does(() => { var buildSettings = new DotNetBuildSettings { - Configuration = "Release", - MSBuildSettings = new DotNetCoreMSBuildSettings() + MSBuildSettings = new DotNetMSBuildSettings() }; buildSettings.MSBuildSettings.Targets.Add("build"); buildSettings.MSBuildSettings.Targets.Add("pack"); - DotNetBuild(".", buildSettings); + buildSettings.Configuration = "Release"; + DotNetBuild("./Harmony/Harmony.csproj", buildSettings); }); Task("Test") .IsDependentOn("Build") .Does(() => { - var testTargets = new [] { "net35", "net452", "net48", "netcoreapp3.1", "net5.0", "net6.0", "net7.0", "net8.0" }; - foreach (var target in testTargets) - { - Information($"Testing {target}"); - DotNetCoreTest("./HarmonyTests/HarmonyTests.csproj", new DotNetCoreTestSettings { - Configuration = "Release", - Framework = target, - Verbosity = DotNetCoreVerbosity.Normal - }); - } + var targets = FindRegexMatchGroupInFile("./HarmonyTests/HarmonyTests.csproj", @"(.*)<\/TargetFrameworks>", 1, System.Text.RegularExpressions.RegexOptions.IgnoreCase).Captures[0].Value.Split(';'); + + foreach (var target in targets) + { + Information($"Testing {target}"); + DotNetTest("./HarmonyTests/HarmonyTests.csproj", new DotNetTestSettings { + Configuration = "Release", + Framework = target, + Verbosity = DotNetVerbosity.Normal + }); + } }); Task("Publish") .IsDependentOn("Build") .Does(() => { - var version = FindRegexMatchGroupInFile("./Harmony/Harmony.csproj", @"(.*)<\/Version>", 1, System.Text.RegularExpressions.RegexOptions.IgnoreCase); - var versionTagPresent = !string.IsNullOrWhiteSpace(RunGit($"ls-remote --tags origin v{version}")); + var version = FindRegexMatchGroupInFile("./Directory.Build.props", @"(.*)<\/HarmonyXVersion>", 1, System.Text.RegularExpressions.RegexOptions.IgnoreCase).Captures[0].Value; + version += FindRegexMatchGroupInFile("./Directory.Build.props", @"(.*)<\/HarmonyXVersionSuffix>", 1, System.Text.RegularExpressions.RegexOptions.IgnoreCase).Captures[0].Value; + var versionTagPresent = !string.IsNullOrWhiteSpace(RunGit($"ls-remote --tags origin v{version}")); if(versionTagPresent) { Information("New version exists, no need to push."); diff --git a/global.json b/global.json new file mode 100644 index 00000000..5631d787 --- /dev/null +++ b/global.json @@ -0,0 +1,5 @@ +{ + "sdk": { + "allowPrerelease": false + } +} \ No newline at end of file