From 24d9477a0f41e9581f4c9ae49e5d593855ab73c0 Mon Sep 17 00:00:00 2001 From: Christopher Whitley Date: Sun, 19 May 2024 15:28:33 -0400 Subject: [PATCH] Drop CAKE build and move Build CI to github workflow --- .github/workflows/build-test-deploy.yml | 49 ---------------- .github/workflows/develop-build.yml | 75 +++++++++++++++++++++++++ .github/workflows/pull-request-test.yml | 32 +++++++++++ .github/workflows/release-build.yml | 70 +++++++++++++++++++++++ Directory.Build.props | 7 ++- MonoGame.Extended.sln | 13 ----- build/Build.csproj | 15 ----- build/BuildContext.cs | 41 -------------- build/BuildTask.cs | 29 ---------- build/DeployToGithubTask.cs | 25 --------- build/DeployToMyGetTask.cs | 25 --------- build/DeployToNuGetTask.cs | 27 --------- build/Directory.Build.props | 13 ----- build/PackageTask.cs | 40 ------------- build/Program.cs | 33 ----------- build/RestoreTask.cs | 18 ------ build/TestTask.cs | 22 -------- 17 files changed, 183 insertions(+), 351 deletions(-) delete mode 100644 .github/workflows/build-test-deploy.yml create mode 100644 .github/workflows/develop-build.yml create mode 100644 .github/workflows/pull-request-test.yml create mode 100644 .github/workflows/release-build.yml delete mode 100644 build/Build.csproj delete mode 100644 build/BuildContext.cs delete mode 100644 build/BuildTask.cs delete mode 100644 build/DeployToGithubTask.cs delete mode 100644 build/DeployToMyGetTask.cs delete mode 100644 build/DeployToNuGetTask.cs delete mode 100644 build/Directory.Build.props delete mode 100644 build/PackageTask.cs delete mode 100644 build/Program.cs delete mode 100644 build/RestoreTask.cs delete mode 100644 build/TestTask.cs diff --git a/.github/workflows/build-test-deploy.yml b/.github/workflows/build-test-deploy.yml deleted file mode 100644 index d6ccc9d1..00000000 --- a/.github/workflows/build-test-deploy.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: "Build test deploy" - -on: - push: - branches: [develop, test/feature] - tags: [v*] - pull_request: - branches: [develop] - pull_request_target: - branches: [develop] - -jobs: - build-test-pack-job: - name: "Build-Test-Pack" - runs-on: ubuntu-latest - steps: - - name: "Clone Repository" - uses: actions/checkout@v4 - - name: "CAKE (Build -> Test -> Package)" - run: dotnet run --project ./src/cs/Build/Build.csproj -- --target=Default - - name: "Upload Artifacts For Deploy" - if: github.event_name != 'pull_request' - uses: actions/upload-artifact@main - with: - name: MonoGame.Extended - path: artifacts/* - - deploy-job: - name: "Deploy Nugets" - runs-on: ubuntu-latest - permissions: - packages: write - contents: write - needs: [build-test-pack-job] - if: ${{ github.event_name == 'push' }} - steps: - - name: "Clone Repository" - uses: actions/checkout@v4 - - name: "Download Artifacts For Deploy" - uses: actions/download-artifact@main - with: - name: MonoGame.Extended - path: artifacts - - name: "Push Package" - run: dotnet run --project ./build/Build.csproj -- --target=Deploy - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - MYGET_ACCESS_TOKEN: ${{ secrets.MYGET_ACCESS_TOKEN }} - NUGET_ACCESS_TOKEN: ${{ secrets.NUGET_ACCESS_TOKEN }} diff --git a/.github/workflows/develop-build.yml b/.github/workflows/develop-build.yml new file mode 100644 index 00000000..c24f7189 --- /dev/null +++ b/.github/workflows/develop-build.yml @@ -0,0 +1,75 @@ +################################################################################ +### Build MonoGame.Extended (Develop) +### Clones the `develop` branch and performs a build, test, then pack of the +### Monogame.Extended source code. Once the build job is finished, the deploy +### job will upload the nupkg files created to the MonoGame.Extended GitHub +### and NuGet sources. +### +### - Only runs on a push to the `develop` branch +### - Sets the IS_PRERELASE and BUILD_NUMBER environment variables which are +### picked up in the Directory.Build.props file to set the version suffix +### so the packages are build as prerelease packages. +################################################################################ +name: "Build MonoGame.Extended (Develop)" + +on: + push: + branches: develop + +jobs: + build: + name: "Build MonoGame.Extended" + runs-on: ubuntu-latest + env: + IS_PRERELEASE: true + BUILD_NUMBER: ${{ github.run_id }} + + steps: + - name: Clone Repository + uses: actions/checkout@v4 + with: + ref: develop + + - name: Setup DotNet + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 6.0.x + + - name: Test MonoGame.Extended + run: dotnet test --nologo --verbosity minimial --configuration Release + + - name: Build MonoGame.Extended + run: dotnet build --nologo --verbosity minimal --configuration Release + + - name: Pack MonoGame.Extended + run: dotnet pack --nologo --verbosity minimal --configuration Release + + - name: Upload Artifacts + uses: actions/upload-artifact@v4 + with: + name: build-artifacts + path: ./.artifacts/source/package/release/*.nupkg + + + deploy-job: + name: "Deploy Nugets" + runs-on: ubuntu-latest + needs: [build] + permissions: + packages: write + contents: write + + steps: + - name: "Download Artifacts For Deploy" + uses: actions/download-artifact@v4 + with: + name: build-artifacts + path: ./.artifacts + + - name: "Push Packages" + run: | + PACKAGES=(".artifacts/*.nupkg") + for PACKAGE in "${PACKAGES[@]}"; do + dotnet nuget push "$PACKAGE" --source "github" --skip-duplicate --api-key "${{ env.GITHUB_TOKEN }}" + dotnet nuget push "$PACKAGE" --source "https://api.nuget.org/v3/index.json" --skip-duplicate --api-key "${{ secrets.NUGET_ACCESS_TOKEN }}" + done diff --git a/.github/workflows/pull-request-test.yml b/.github/workflows/pull-request-test.yml new file mode 100644 index 00000000..f376e412 --- /dev/null +++ b/.github/workflows/pull-request-test.yml @@ -0,0 +1,32 @@ +################################################################################ +### Pull Request Test +### Executes tests to ensure that the pull request being submitted is valid. +### - Only runs on pull requests made to the `develop` branch +### - Only runs if the pull request was opened or synchronized +################################################################################ +name: Pull Request Test + +on: + pull_request: + branches: + - develop + - main + types: + - opened + - synchronize + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Clone Repository + uses: actions/checkout@v4 + + - name: Setup DotNet + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 6.0.x + + - name: Test MonoGame.Extended + run: dotnet test --nologo --verbosity minimial --configuration Release diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml new file mode 100644 index 00000000..a40fb94c --- /dev/null +++ b/.github/workflows/release-build.yml @@ -0,0 +1,70 @@ +################################################################################ +### Build MonoGame.Extended (Release) +### Clones the `main` branch and performs a build, test, then pack of the +### Monogame.Extended source code. Once the build job is finished, the deploy +### job will upload the nupkg files created to the MonoGame.Extended NuGet +### source. +### +### - Only runs when there is a new version release tag created. +################################################################################ +name: "Build MonoGame.Extended (Release)" + +on: + push: + tags: + - 'v*' + +jobs: + build: + name: "Build MonoGame.Extended" + runs-on: ubuntu-latest + + steps: + - name: Clone Repository + uses: actions/checkout@v4 + with: + ref: main + + - name: Setup DotNet + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 6.0.x + + - name: Test MonoGame.Extended + run: dotnet test --nologo --verbosity minimial --configuration Release + + - name: Build MonoGame.Extended + run: dotnet build --nologo --verbosity minimal --configuration Release + + - name: Pack MonoGame.Extended + run: dotnet pack --nologo --verbosity minimal --configuration Release + + - name: Upload Artifacts + uses: actions/upload-artifact@v4 + with: + name: build-artifacts + path: ./.artifacts/source/package/release/*.nupkg + + + deploy-job: + name: "Deploy Nugets" + runs-on: ubuntu-latest + needs: [build] + permissions: + packages: write + contents: write + + steps: + - name: "Download Artifacts For Deploy" + uses: actions/download-artifact@v4 + with: + name: build-artifacts + path: ./.artifacts + + - name: "Push Packages" + run: | + PACKAGES=(".artifacts/*.nupkg") + for PACKAGE in "${PACKAGES[@]}"; do + dotnet nuget push "$PACKAGE" --source "github" --skip-duplicate --api-key "${{ env.GITHUB_TOKEN }}" + dotnet nuget push "$PACKAGE" --source "https://api.nuget.org/v3/index.json" --skip-duplicate --api-key "${{ secrets.NUGET_ACCESS_TOKEN }}" + done diff --git a/Directory.Build.props b/Directory.Build.props index 89f7ed14..7c615665 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -5,10 +5,15 @@ net6.0 $(MSBuildThisFileDirectory) + + + 3.9.0 + -prerelease + .$(BUILD_NUMBER) + $(MonoGameExtendedVersion)$(IsPrerelease)$(BuildNumber) - 3.9.0 craftworkgames and contributors https://github.com/craftworkgames/MonoGame.Extended https://github.com/craftworkgames/MonoGame.Extended diff --git a/MonoGame.Extended.sln b/MonoGame.Extended.sln index 8865469d..2cfd0944 100644 --- a/MonoGame.Extended.sln +++ b/MonoGame.Extended.sln @@ -44,10 +44,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoGame.Extended.Tiled.Tes EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoGame.Extended.Tweening.Tests", "tests\MonoGame.Extended.Tweening.Tests\MonoGame.Extended.Tweening.Tests.csproj", "{C2A9982B-7BF7-4243-9E05-CFD31752B6DC}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{D596CBD4-8DDE-46BD-AF76-59FC1F03BF64}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Build", "build\Build.csproj", "{0D198ABB-0BA6-4AC7-8F30-E49C70AF203A}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -208,14 +204,6 @@ Global {C2A9982B-7BF7-4243-9E05-CFD31752B6DC}.Release|Any CPU.Build.0 = Release|Any CPU {C2A9982B-7BF7-4243-9E05-CFD31752B6DC}.Release|x86.ActiveCfg = Release|Any CPU {C2A9982B-7BF7-4243-9E05-CFD31752B6DC}.Release|x86.Build.0 = Release|Any CPU - {0D198ABB-0BA6-4AC7-8F30-E49C70AF203A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0D198ABB-0BA6-4AC7-8F30-E49C70AF203A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0D198ABB-0BA6-4AC7-8F30-E49C70AF203A}.Debug|x86.ActiveCfg = Debug|Any CPU - {0D198ABB-0BA6-4AC7-8F30-E49C70AF203A}.Debug|x86.Build.0 = Debug|Any CPU - {0D198ABB-0BA6-4AC7-8F30-E49C70AF203A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0D198ABB-0BA6-4AC7-8F30-E49C70AF203A}.Release|Any CPU.Build.0 = Release|Any CPU - {0D198ABB-0BA6-4AC7-8F30-E49C70AF203A}.Release|x86.ActiveCfg = Release|Any CPU - {0D198ABB-0BA6-4AC7-8F30-E49C70AF203A}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -240,7 +228,6 @@ Global {E1339B07-EB0B-454F-9803-E923843DB5C4} = {61C82014-E3A9-4AB3-8705-FBBD5F799BA6} {BF0EC593-4BAB-424F-B7E9-BB13EC78A0E5} = {61C82014-E3A9-4AB3-8705-FBBD5F799BA6} {C2A9982B-7BF7-4243-9E05-CFD31752B6DC} = {61C82014-E3A9-4AB3-8705-FBBD5F799BA6} - {0D198ABB-0BA6-4AC7-8F30-E49C70AF203A} = {D596CBD4-8DDE-46BD-AF76-59FC1F03BF64} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {8ED5A62D-25EC-4331-9F99-BDD1E10C02A0} diff --git a/build/Build.csproj b/build/Build.csproj deleted file mode 100644 index 27845d59..00000000 --- a/build/Build.csproj +++ /dev/null @@ -1,15 +0,0 @@ - - - - Exe - net8.0 - enable - $(MSBuildProjectDirectory) - - - - - - - diff --git a/build/BuildContext.cs b/build/BuildContext.cs deleted file mode 100644 index 077fa638..00000000 --- a/build/BuildContext.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System.Linq; -using Cake.Common; -using Cake.Common.Build; -using Cake.Common.Xml; -using Cake.Core; -using Cake.Frosting; - -namespace BuildScripts; - -public sealed class BuildContext : FrostingContext -{ - public string ArtifactsDirectory { get; } - public string Version { get; } - public string SolutionPath { get; } - public string? RepositoryOwner { get; } - public string? RepositoryUrl { get; } - public bool IsTag { get; } - public bool IsRunningOnGitHubActions { get; } - public string? GitHubToken { get; } - public string? MyGetAccessToken { get; } - public string? NuGetAccessToken { get; } - - public BuildContext(ICakeContext context) : base(context) - { - ArtifactsDirectory = context.Argument(nameof(ArtifactsDirectory), ".artifacts"); - Version = context.XmlPeek("Directory.Build.props", "/Project/PropertyGroup/Version"); - SolutionPath = "./MonoGame.Extended.sln"; - IsRunningOnGitHubActions = context.BuildSystem().IsRunningOnGitHubActions; - - if (IsRunningOnGitHubActions) - { - Version += "." + context.EnvironmentVariable("GITHUB_RUN_NUMBER"); - RepositoryOwner = context.EnvironmentVariable("GITHUB_REPOSITORY_OWNER"); - RepositoryUrl = $"https://github.com/{context.EnvironmentVariable("GITHUB_REPOSITORY")}"; - IsTag = context.EnvironmentVariable("GITHUB_REF_TYPE") == "tag"; - GitHubToken = context.EnvironmentVariable("GITHUB_TOKEN"); - MyGetAccessToken = context.EnvironmentVariable("MYGET_ACCESS_TOKEN"); - NuGetAccessToken = context.EnvironmentVariable("NUGET_ACCESS_TOKEN"); - } - } -} diff --git a/build/BuildTask.cs b/build/BuildTask.cs deleted file mode 100644 index 218c2095..00000000 --- a/build/BuildTask.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Cake.Common.Tools.DotNet; -using Cake.Common.Tools.DotNet.Build; -using Cake.Common.Tools.DotNet.MSBuild; -using Cake.Frosting; - -namespace BuildScripts; - -[TaskName(nameof(BuildTask))] -public sealed class BuildTask : FrostingTask -{ - public override void Run(BuildContext context) - { - DotNetMSBuildSettings msBuildSettings = new DotNetMSBuildSettings(); - msBuildSettings.WithProperty("Version", context.Version); - msBuildSettings.WithProperty("NoWarn", "CS1591"); - - - DotNetBuildSettings buildSettings = new DotNetBuildSettings() - { - MSBuildSettings = msBuildSettings, - Configuration = "Release", - Verbosity = DotNetVerbosity.Minimal, - NoRestore = true, - NoLogo = true - }; - - context.DotNetBuild(context.SolutionPath, buildSettings); - } -} diff --git a/build/DeployToGithubTask.cs b/build/DeployToGithubTask.cs deleted file mode 100644 index 62981e79..00000000 --- a/build/DeployToGithubTask.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Cake.Common.Tools.DotNet; -using Cake.Common.Tools.DotNet.NuGet.Push; -using Cake.Frosting; - -namespace BuildScripts; - -[TaskName(nameof(DeployToGitHubTask))] -public sealed class DeployToGitHubTask : FrostingTask -{ - public override bool ShouldRun(BuildContext context) - { - return context.IsRunningOnGitHubActions; - } - - public override void Run(BuildContext context) - { - DotNetNuGetPushSettings pushSettings = new DotNetNuGetPushSettings() - { - Source = $"https://nuget.pkg.github.com/{context.RepositoryOwner}/index.json", - ApiKey = context.GitHubToken - }; - - context.DotNetNuGetPush("artifacts/*.nupkg", pushSettings); - } -} diff --git a/build/DeployToMyGetTask.cs b/build/DeployToMyGetTask.cs deleted file mode 100644 index c83fe07c..00000000 --- a/build/DeployToMyGetTask.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Cake.Common.Tools.DotNet; -using Cake.Common.Tools.DotNet.NuGet.Push; -using Cake.Frosting; - -namespace BuildScripts; - -[TaskName(nameof(DeployToMyGetTask))] -public sealed class DeployToMyGetTask : FrostingTask -{ - public override bool ShouldRun(BuildContext context) - { - return context.IsRunningOnGitHubActions; - } - - public override void Run(BuildContext context) - { - DotNetNuGetPushSettings pushSettings = new DotNetNuGetPushSettings() - { - Source = $"https://www.myget.org/F/lithiumtoast/api/v3/index.json", - ApiKey = context.MyGetAccessToken - }; - - context.DotNetNuGetPush("artifacts/*.nupkg", pushSettings); - } -} diff --git a/build/DeployToNuGetTask.cs b/build/DeployToNuGetTask.cs deleted file mode 100644 index 84675021..00000000 --- a/build/DeployToNuGetTask.cs +++ /dev/null @@ -1,27 +0,0 @@ -using Cake.Common.Tools.DotNet; -using Cake.Common.Tools.DotNet.NuGet.Push; -using Cake.Frosting; - -namespace BuildScripts; - -[TaskName(nameof(DeployToNuGetTask))] -public sealed class DeployToNuGetTask : FrostingTask -{ - public override bool ShouldRun(BuildContext context) - { - return context.IsRunningOnGitHubActions && - context.IsTag && - context.RepositoryOwner == "craftworksgames"; - } - - public override void Run(BuildContext context) - { - DotNetNuGetPushSettings pushSettings = new DotNetNuGetPushSettings() - { - Source = $"https://api.nuget.org/v3/index.json", - ApiKey = context.NuGetAccessToken - }; - - context.DotNetNuGetPush("artifacts/*.nupkg", pushSettings); - } -} diff --git a/build/Directory.Build.props b/build/Directory.Build.props deleted file mode 100644 index 9eea1e0b..00000000 --- a/build/Directory.Build.props +++ /dev/null @@ -1,13 +0,0 @@ - - - - - build - false - false - - - - - - diff --git a/build/PackageTask.cs b/build/PackageTask.cs deleted file mode 100644 index b1c56ab4..00000000 --- a/build/PackageTask.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Cake.Common.Build; -using Cake.Common.IO; -using Cake.Common.Tools.DotNet; -using Cake.Common.Tools.DotNet.MSBuild; -using Cake.Common.Tools.DotNet.Pack; -using Cake.Core.IO; -using Cake.Frosting; - -namespace BuildScripts; - -[TaskName(nameof(PackageTask))] -public sealed class PackageTask : FrostingTask -{ - public override void Run(BuildContext context) - { - context.CleanDirectories(context.ArtifactsDirectory); - context.CreateDirectory(context.ArtifactsDirectory); - - DotNetMSBuildSettings msBuildSettings = new DotNetMSBuildSettings(); - msBuildSettings.WithProperty("Version", context.Version); - - // Ignore warnings about adding duplicate items added to package - msBuildSettings.WithProperty("NoWarn", "NU5118"); - - DotNetPackSettings packSettings = new DotNetPackSettings() - { - MSBuildSettings = msBuildSettings, - Configuration = "Release", - Verbosity = DotNetVerbosity.Minimal, - NoLogo = true, - OutputDirectory = context.ArtifactsDirectory, - }; - - FilePathCollection files = context.GetFiles("./src/cs/MonoGame.Extended*/**/*.csproj"); - foreach(FilePath file in files) - { - context.DotNetPack(file.FullPath, packSettings); - } - } -} diff --git a/build/Program.cs b/build/Program.cs deleted file mode 100644 index 1603494a..00000000 --- a/build/Program.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Threading.Tasks; -using Cake.Common.Build; -using Cake.Common.IO; -using Cake.Common.Tools.ReportUnit; -using Cake.Core; -using Cake.Core.IO; -using Cake.Frosting; - -namespace BuildScripts; - -public static class Program -{ - public static int Main(string[] args) - { - return new CakeHost() - .UseContext() - .UseWorkingDirectory("../") - .Run(args); - } -} - -[TaskName("Default")] -[IsDependentOn(typeof(RestoreTask))] -[IsDependentOn(typeof(BuildTask))] -[IsDependentOn(typeof(TestTask))] -[IsDependentOn(typeof(PackageTask))] -public sealed class DefaultTask : FrostingTask {} - - -[TaskName("Deploy")] -[IsDependentOn(typeof(DeployToGitHubTask))] -[IsDependentOn(typeof(DeployToNuGetTask))] -public sealed class DeployTask : FrostingTask {} diff --git a/build/RestoreTask.cs b/build/RestoreTask.cs deleted file mode 100644 index 91c5222c..00000000 --- a/build/RestoreTask.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Cake.Common.Tools.DotNet; -using Cake.Common.Tools.DotNet.Restore; -using Cake.Frosting; - -namespace BuildScripts; - -public sealed class RestoreTask : FrostingTask -{ - public override void Run(BuildContext context) - { - DotNetRestoreSettings restoreSettings = new DotNetRestoreSettings() - { - Verbosity = DotNetVerbosity.Quiet - }; - - context.DotNetRestore(context.SolutionPath, restoreSettings); - } -} diff --git a/build/TestTask.cs b/build/TestTask.cs deleted file mode 100644 index 93af6839..00000000 --- a/build/TestTask.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Cake.Common.Tools.DotNet; -using Cake.Common.Tools.DotNet.Test; -using Cake.Frosting; - -namespace BuildScripts; - -[TaskName(nameof(TestTask))] -public class TestTask : FrostingTask -{ - public override void Run(BuildContext context) - { - DotNetTestSettings testSettings = new DotNetTestSettings() - { - Configuration = "Release", - Verbosity = DotNetVerbosity.Normal, - NoLogo = true, - NoBuild = true - }; - - context.DotNetTest(context.SolutionPath, testSettings); - } -}