From d1a245dca2304c0a2e27430b55ec4ecd19f9d869 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 21 Aug 2024 16:06:52 -0400 Subject: [PATCH 1/5] Migrated to nuke with github actions Migrated to nuke with github actions --- .github/workflows/Build.yml | 47 ++++++++ .nuke/build.schema.json | 110 ++++++++++++++++++ .nuke/parameters.json | 4 + .../Eraware_Dnn_Spa_Ef_Di_Stencil.csproj | 1 + Eraware_Dnn_Templates.sln | 4 + .../Eraware_Dnn_Templates.csproj | 1 + build.cmd | 7 ++ build.ps1 | 74 ++++++++++++ build.sh | 67 +++++++++++ build/.editorconfig | 11 ++ build/Build.cs | 75 ++++++++++++ build/Configuration.cs | 16 +++ build/Directory.Build.props | 8 ++ build/Directory.Build.targets | 8 ++ build/_build.csproj | 18 +++ build/_build.csproj.DotSettings | 27 +++++ 16 files changed, 478 insertions(+) create mode 100644 .github/workflows/Build.yml create mode 100644 .nuke/build.schema.json create mode 100644 .nuke/parameters.json create mode 100755 build.cmd create mode 100644 build.ps1 create mode 100755 build.sh create mode 100644 build/.editorconfig create mode 100644 build/Build.cs create mode 100644 build/Configuration.cs create mode 100644 build/Directory.Build.props create mode 100644 build/Directory.Build.targets create mode 100644 build/_build.csproj create mode 100644 build/_build.csproj.DotSettings diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml new file mode 100644 index 00000000..78bcc271 --- /dev/null +++ b/.github/workflows/Build.yml @@ -0,0 +1,47 @@ +# ------------------------------------------------------------------------------ +# +# +# This code was generated. +# +# - To turn off auto-generation set: +# +# [GitHubActions (AutoGenerate = false)] +# +# - To trigger manual generation invoke: +# +# nuke --generate-configuration GitHubActions_Build --host GitHubActions +# +# +# ------------------------------------------------------------------------------ + +name: Build + +on: + push: + branches: + - master + - develop + - 'release/*' + pull_request: + branches: + - master + - main + - develop + - development + - 'release/*' + +jobs: + ubuntu-latest: + name: ubuntu-latest + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: 'Run: Compile' + run: ./build.cmd Compile + - name: 'Publish: artifacts' + uses: actions/upload-artifact@v3 + with: + name: artifacts + path: artifacts diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json new file mode 100644 index 00000000..db869b0f --- /dev/null +++ b/.nuke/build.schema.json @@ -0,0 +1,110 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/build", + "title": "Build Schema", + "definitions": { + "build": { + "type": "object", + "properties": { + "Configuration": { + "type": "string", + "description": "Configuration to build - Default is 'Debug' (local) or 'Release' (server)", + "enum": [ + "Debug", + "Release" + ] + }, + "Continue": { + "type": "boolean", + "description": "Indicates to continue a previously failed build attempt" + }, + "Help": { + "type": "boolean", + "description": "Shows the help text for this build assembly" + }, + "Host": { + "type": "string", + "description": "Host for execution. Default is 'automatic'", + "enum": [ + "AppVeyor", + "AzurePipelines", + "Bamboo", + "Bitbucket", + "Bitrise", + "GitHubActions", + "GitLab", + "Jenkins", + "Rider", + "SpaceAutomation", + "TeamCity", + "Terminal", + "TravisCI", + "VisualStudio", + "VSCode" + ] + }, + "NoLogo": { + "type": "boolean", + "description": "Disables displaying the NUKE logo" + }, + "Partition": { + "type": "string", + "description": "Partition to use on CI" + }, + "Plan": { + "type": "boolean", + "description": "Shows the execution plan (HTML)" + }, + "Profile": { + "type": "array", + "description": "Defines the profiles to load", + "items": { + "type": "string" + } + }, + "Root": { + "type": "string", + "description": "Root directory during build execution" + }, + "Skip": { + "type": "array", + "description": "List of targets to be skipped. Empty list skips all dependencies", + "items": { + "type": "string", + "enum": [ + "Clean", + "Compile", + "Restore" + ] + } + }, + "Solution": { + "type": "string", + "description": "Path to a solution file that is automatically loaded" + }, + "Target": { + "type": "array", + "description": "List of targets to be invoked. Default is '{default_target}'", + "items": { + "type": "string", + "enum": [ + "Clean", + "Compile", + "Restore" + ] + } + }, + "Verbosity": { + "type": "string", + "description": "Logging verbosity during build execution. Default is 'Normal'", + "enum": [ + "Minimal", + "Normal", + "Quiet", + "Verbose" + ] + } + } + } + } +} diff --git a/.nuke/parameters.json b/.nuke/parameters.json new file mode 100644 index 00000000..1a426d95 --- /dev/null +++ b/.nuke/parameters.json @@ -0,0 +1,4 @@ +{ + "$schema": "./build.schema.json", + "Solution": "Eraware_Dnn_Templates.sln" +} diff --git a/Eraware_Dnn_Spa_Ef_Di_Stencil/Eraware_Dnn_Spa_Ef_Di_Stencil.csproj b/Eraware_Dnn_Spa_Ef_Di_Stencil/Eraware_Dnn_Spa_Ef_Di_Stencil.csproj index 182cec18..dc38fb9f 100644 --- a/Eraware_Dnn_Spa_Ef_Di_Stencil/Eraware_Dnn_Spa_Ef_Di_Stencil.csproj +++ b/Eraware_Dnn_Spa_Ef_Di_Stencil/Eraware_Dnn_Spa_Ef_Di_Stencil.csproj @@ -3,6 +3,7 @@ 16.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + win diff --git a/Eraware_Dnn_Templates.sln b/Eraware_Dnn_Templates.sln index 32bdb3a9..16e27330 100644 --- a/Eraware_Dnn_Templates.sln +++ b/Eraware_Dnn_Templates.sln @@ -12,12 +12,16 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionIt LICENSE = LICENSE EndProjectSection EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "_build", "build\_build.csproj", "{DEC1FDF7-0D64-4992-BB69-0E15EA6E8088}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DEC1FDF7-0D64-4992-BB69-0E15EA6E8088}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DEC1FDF7-0D64-4992-BB69-0E15EA6E8088}.Release|Any CPU.ActiveCfg = Release|Any CPU {1AABA73D-8159-4BD7-BD86-F711E9BF8106}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1AABA73D-8159-4BD7-BD86-F711E9BF8106}.Debug|Any CPU.Build.0 = Debug|Any CPU {1AABA73D-8159-4BD7-BD86-F711E9BF8106}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/Eraware_Dnn_Templates/Eraware_Dnn_Templates.csproj b/Eraware_Dnn_Templates/Eraware_Dnn_Templates.csproj index 3a3e965f..b6958c41 100644 --- a/Eraware_Dnn_Templates/Eraware_Dnn_Templates.csproj +++ b/Eraware_Dnn_Templates/Eraware_Dnn_Templates.csproj @@ -3,6 +3,7 @@ 16.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + win true diff --git a/build.cmd b/build.cmd new file mode 100755 index 00000000..b08cc590 --- /dev/null +++ b/build.cmd @@ -0,0 +1,7 @@ +:; set -eo pipefail +:; SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) +:; ${SCRIPT_DIR}/build.sh "$@" +:; exit $? + +@ECHO OFF +powershell -ExecutionPolicy ByPass -NoProfile -File "%~dp0build.ps1" %* diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 00000000..4634dc03 --- /dev/null +++ b/build.ps1 @@ -0,0 +1,74 @@ +[CmdletBinding()] +Param( + [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] + [string[]]$BuildArguments +) + +Write-Output "PowerShell $($PSVersionTable.PSEdition) version $($PSVersionTable.PSVersion)" + +Set-StrictMode -Version 2.0; $ErrorActionPreference = "Stop"; $ConfirmPreference = "None"; trap { Write-Error $_ -ErrorAction Continue; exit 1 } +$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent + +########################################################################### +# CONFIGURATION +########################################################################### + +$BuildProjectFile = "$PSScriptRoot\build\_build.csproj" +$TempDirectory = "$PSScriptRoot\\.nuke\temp" + +$DotNetGlobalFile = "$PSScriptRoot\\global.json" +$DotNetInstallUrl = "https://dot.net/v1/dotnet-install.ps1" +$DotNetChannel = "STS" + +$env:DOTNET_CLI_TELEMETRY_OPTOUT = 1 +$env:DOTNET_NOLOGO = 1 + +########################################################################### +# EXECUTION +########################################################################### + +function ExecSafe([scriptblock] $cmd) { + & $cmd + if ($LASTEXITCODE) { exit $LASTEXITCODE } +} + +# If dotnet CLI is installed globally and it matches requested version, use for execution +if ($null -ne (Get-Command "dotnet" -ErrorAction SilentlyContinue) -and ` + $(dotnet --version) -and $LASTEXITCODE -eq 0) { + $env:DOTNET_EXE = (Get-Command "dotnet").Path +} +else { + # Download install script + $DotNetInstallFile = "$TempDirectory\dotnet-install.ps1" + New-Item -ItemType Directory -Path $TempDirectory -Force | Out-Null + [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 + (New-Object System.Net.WebClient).DownloadFile($DotNetInstallUrl, $DotNetInstallFile) + + # If global.json exists, load expected version + if (Test-Path $DotNetGlobalFile) { + $DotNetGlobal = $(Get-Content $DotNetGlobalFile | Out-String | ConvertFrom-Json) + if ($DotNetGlobal.PSObject.Properties["sdk"] -and $DotNetGlobal.sdk.PSObject.Properties["version"]) { + $DotNetVersion = $DotNetGlobal.sdk.version + } + } + + # Install by channel or version + $DotNetDirectory = "$TempDirectory\dotnet-win" + if (!(Test-Path variable:DotNetVersion)) { + ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Channel $DotNetChannel -NoPath } + } else { + ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath } + } + $env:DOTNET_EXE = "$DotNetDirectory\dotnet.exe" + $env:PATH = "$DotNetDirectory;$env:PATH" +} + +Write-Output "Microsoft (R) .NET SDK version $(& $env:DOTNET_EXE --version)" + +if (Test-Path env:NUKE_ENTERPRISE_TOKEN) { + & $env:DOTNET_EXE nuget remove source "nuke-enterprise" > $null + & $env:DOTNET_EXE nuget add source "https://f.feedz.io/nuke/enterprise/nuget" --name "nuke-enterprise" --username "PAT" --password $env:NUKE_ENTERPRISE_TOKEN > $null +} + +ExecSafe { & $env:DOTNET_EXE build $BuildProjectFile /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet } +ExecSafe { & $env:DOTNET_EXE run --project $BuildProjectFile --no-build -- $BuildArguments } diff --git a/build.sh b/build.sh new file mode 100755 index 00000000..fdff0c62 --- /dev/null +++ b/build.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash + +bash --version 2>&1 | head -n 1 + +set -eo pipefail +SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) + +########################################################################### +# CONFIGURATION +########################################################################### + +BUILD_PROJECT_FILE="$SCRIPT_DIR/build/_build.csproj" +TEMP_DIRECTORY="$SCRIPT_DIR//.nuke/temp" + +DOTNET_GLOBAL_FILE="$SCRIPT_DIR//global.json" +DOTNET_INSTALL_URL="https://dot.net/v1/dotnet-install.sh" +DOTNET_CHANNEL="STS" + +export DOTNET_CLI_TELEMETRY_OPTOUT=1 +export DOTNET_NOLOGO=1 + +########################################################################### +# EXECUTION +########################################################################### + +function FirstJsonValue { + perl -nle 'print $1 if m{"'"$1"'": "([^"]+)",?}' <<< "${@:2}" +} + +# If dotnet CLI is installed globally and it matches requested version, use for execution +if [ -x "$(command -v dotnet)" ] && dotnet --version &>/dev/null; then + export DOTNET_EXE="$(command -v dotnet)" +else + # Download install script + DOTNET_INSTALL_FILE="$TEMP_DIRECTORY/dotnet-install.sh" + mkdir -p "$TEMP_DIRECTORY" + curl -Lsfo "$DOTNET_INSTALL_FILE" "$DOTNET_INSTALL_URL" + chmod +x "$DOTNET_INSTALL_FILE" + + # If global.json exists, load expected version + if [[ -f "$DOTNET_GLOBAL_FILE" ]]; then + DOTNET_VERSION=$(FirstJsonValue "version" "$(cat "$DOTNET_GLOBAL_FILE")") + if [[ "$DOTNET_VERSION" == "" ]]; then + unset DOTNET_VERSION + fi + fi + + # Install by channel or version + DOTNET_DIRECTORY="$TEMP_DIRECTORY/dotnet-unix" + if [[ -z ${DOTNET_VERSION+x} ]]; then + "$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --channel "$DOTNET_CHANNEL" --no-path + else + "$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --version "$DOTNET_VERSION" --no-path + fi + export DOTNET_EXE="$DOTNET_DIRECTORY/dotnet" + export PATH="$DOTNET_DIRECTORY:$PATH" +fi + +echo "Microsoft (R) .NET SDK version $("$DOTNET_EXE" --version)" + +if [[ ! -z ${NUKE_ENTERPRISE_TOKEN+x} && "$NUKE_ENTERPRISE_TOKEN" != "" ]]; then + "$DOTNET_EXE" nuget remove source "nuke-enterprise" &>/dev/null || true + "$DOTNET_EXE" nuget add source "https://f.feedz.io/nuke/enterprise/nuget" --name "nuke-enterprise" --username "PAT" --password "$NUKE_ENTERPRISE_TOKEN" --store-password-in-clear-text &>/dev/null || true +fi + +"$DOTNET_EXE" build "$BUILD_PROJECT_FILE" /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet +"$DOTNET_EXE" run --project "$BUILD_PROJECT_FILE" --no-build -- "$@" diff --git a/build/.editorconfig b/build/.editorconfig new file mode 100644 index 00000000..31e43dcd --- /dev/null +++ b/build/.editorconfig @@ -0,0 +1,11 @@ +[*.cs] +dotnet_style_qualification_for_field = false:warning +dotnet_style_qualification_for_property = false:warning +dotnet_style_qualification_for_method = false:warning +dotnet_style_qualification_for_event = false:warning +dotnet_style_require_accessibility_modifiers = never:warning + +csharp_style_expression_bodied_methods = true:silent +csharp_style_expression_bodied_properties = true:warning +csharp_style_expression_bodied_indexers = true:warning +csharp_style_expression_bodied_accessors = true:warning diff --git a/build/Build.cs b/build/Build.cs new file mode 100644 index 00000000..296d1fff --- /dev/null +++ b/build/Build.cs @@ -0,0 +1,75 @@ +using System; +using System.Linq; +using Nuke.Common; +using Nuke.Common.CI; +using Nuke.Common.CI.GitHubActions; +using Nuke.Common.Execution; +using Nuke.Common.IO; +using Nuke.Common.ProjectModel; +using Nuke.Common.Tooling; +using Nuke.Common.Tools.DotNet; +using Nuke.Common.Tools.MSBuild; +using Nuke.Common.Utilities.Collections; +using Octokit; +using static Nuke.Common.EnvironmentInfo; +using static Nuke.Common.IO.FileSystemTasks; +using static Nuke.Common.IO.PathConstruction; +using static Nuke.Common.Tools.DotNet.DotNetTasks; +using static Nuke.Common.Tools.MSBuild.MSBuildTasks; + +[GitHubActions( + "Build", + GitHubActionsImage.UbuntuLatest, + OnPullRequestBranches = new[] { "master", "main", "develop", "development", "release/*" }, + OnPushBranches = new[] { "master", "develop", "release/*" }, + InvokedTargets = new[] { nameof(Compile) }, + FetchDepth = 0, + CacheKeyFiles = new string[0] + )] +class Build : NukeBuild +{ + /// Support plugins are available for: + /// - JetBrains ReSharper https://nuke.build/resharper + /// - JetBrains Rider https://nuke.build/rider + /// - Microsoft VisualStudio https://nuke.build/visualstudio + /// - Microsoft VSCode https://nuke.build/vscode + + public static int Main () => Execute(x => x.Compile); + + [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] + readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release; + + [Solution] readonly Solution Solution; + + AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts"; + + Target Clean => _ => _ + .Before(Restore) + .Executes(() => + { + ArtifactsDirectory.CreateOrCleanDirectory(); + }); + + Target Restore => _ => _ + .Executes(() => + { + var projects = Solution.GetAllProjects("*"); + + foreach (var project in projects.Where(p => p.Name != "_build")) + { + DotNetRestore(s => s + .SetProjectFile(project)); + } + }); + + Target Compile => _ => _ + .DependsOn(Restore) + .Produces(ArtifactsDirectory / "*.vsix") + .Executes(() => + { + MSBuild(s => s + .SetTargetPath(Solution) + .SetConfiguration(Configuration)); + }); + +} diff --git a/build/Configuration.cs b/build/Configuration.cs new file mode 100644 index 00000000..9c08b1ae --- /dev/null +++ b/build/Configuration.cs @@ -0,0 +1,16 @@ +using System; +using System.ComponentModel; +using System.Linq; +using Nuke.Common.Tooling; + +[TypeConverter(typeof(TypeConverter))] +public class Configuration : Enumeration +{ + public static Configuration Debug = new Configuration { Value = nameof(Debug) }; + public static Configuration Release = new Configuration { Value = nameof(Release) }; + + public static implicit operator string(Configuration configuration) + { + return configuration.Value; + } +} diff --git a/build/Directory.Build.props b/build/Directory.Build.props new file mode 100644 index 00000000..e147d635 --- /dev/null +++ b/build/Directory.Build.props @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/build/Directory.Build.targets b/build/Directory.Build.targets new file mode 100644 index 00000000..25326095 --- /dev/null +++ b/build/Directory.Build.targets @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/build/_build.csproj b/build/_build.csproj new file mode 100644 index 00000000..b1965fae --- /dev/null +++ b/build/_build.csproj @@ -0,0 +1,18 @@ + + + + Exe + net8.0 + + CS0649;CS0169;CA1050;CA1822;CA2211;IDE1006 + .. + .. + 1 + false + + + + + + + diff --git a/build/_build.csproj.DotSettings b/build/_build.csproj.DotSettings new file mode 100644 index 00000000..a778f33d --- /dev/null +++ b/build/_build.csproj.DotSettings @@ -0,0 +1,27 @@ + + DO_NOT_SHOW + DO_NOT_SHOW + DO_NOT_SHOW + DO_NOT_SHOW + DO_NOT_SHOW + Implicit + Implicit + ExpressionBody + 0 + NEXT_LINE + True + False + 120 + IF_OWNER_IS_SINGLE_LINE + WRAP_IF_LONG + False + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + True + True + True + True + True + True + True + True From 095703cf7c018aeb70b27634d204ceb366beffba Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 21 Aug 2024 16:16:41 -0400 Subject: [PATCH 2/5] Switched to a windows runner --- .github/workflows/Build.yml | 6 +++--- build/Build.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index 78bcc271..947b38a1 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -31,9 +31,9 @@ on: - 'release/*' jobs: - ubuntu-latest: - name: ubuntu-latest - runs-on: ubuntu-latest + windows-latest: + name: windows-latest + runs-on: windows-latest steps: - uses: actions/checkout@v3 with: diff --git a/build/Build.cs b/build/Build.cs index 296d1fff..a0fef59d 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -19,7 +19,7 @@ [GitHubActions( "Build", - GitHubActionsImage.UbuntuLatest, + GitHubActionsImage.WindowsLatest, OnPullRequestBranches = new[] { "master", "main", "develop", "development", "release/*" }, OnPushBranches = new[] { "master", "develop", "release/*" }, InvokedTargets = new[] { nameof(Compile) }, From 7ce76c549c1fbdbf24d39b3683b510ad52198ea6 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 21 Aug 2024 16:27:54 -0400 Subject: [PATCH 3/5] Moved buidl result to artifacts directory --- .github/workflows/Build.yml | 4 ++-- .nuke/build.schema.json | 2 ++ build/Build.cs | 12 ++++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index 947b38a1..dc3d6ac3 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -38,8 +38,8 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 - - name: 'Run: Compile' - run: ./build.cmd Compile + - name: 'Run: CI' + run: ./build.cmd CI - name: 'Publish: artifacts' uses: actions/upload-artifact@v3 with: diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json index db869b0f..3ca5c22f 100644 --- a/.nuke/build.schema.json +++ b/.nuke/build.schema.json @@ -72,6 +72,7 @@ "items": { "type": "string", "enum": [ + "CI", "Clean", "Compile", "Restore" @@ -88,6 +89,7 @@ "items": { "type": "string", "enum": [ + "CI", "Clean", "Compile", "Restore" diff --git a/build/Build.cs b/build/Build.cs index a0fef59d..7b85226f 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -22,7 +22,7 @@ GitHubActionsImage.WindowsLatest, OnPullRequestBranches = new[] { "master", "main", "develop", "development", "release/*" }, OnPushBranches = new[] { "master", "develop", "release/*" }, - InvokedTargets = new[] { nameof(Compile) }, + InvokedTargets = new[] { nameof(CI) }, FetchDepth = 0, CacheKeyFiles = new string[0] )] @@ -42,6 +42,7 @@ class Build : NukeBuild [Solution] readonly Solution Solution; AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts"; + AbsolutePath TemplateProjectDirectory => RootDirectory / "Eraware_Dnn_Templates"; Target Clean => _ => _ .Before(Restore) @@ -64,7 +65,6 @@ class Build : NukeBuild Target Compile => _ => _ .DependsOn(Restore) - .Produces(ArtifactsDirectory / "*.vsix") .Executes(() => { MSBuild(s => s @@ -72,4 +72,12 @@ class Build : NukeBuild .SetConfiguration(Configuration)); }); + Target CI => _ => _ + .DependsOn(Compile) + .Produces(ArtifactsDirectory / "*.vsix") + .Executes(() => + { + var vsix = TemplateProjectDirectory / "bin" / Configuration / "Eraware_Dnn_Templates.vsix"; + CopyFileToDirectory(vsix, ArtifactsDirectory, FileExistsPolicy.Overwrite); + }); } From 13f97eb32a58d20648924cbb1d059d3012a85757 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 21 Aug 2024 20:04:34 -0400 Subject: [PATCH 4/5] Added release steps --- .github/workflows/Build.yml | 2 + .nuke/build.schema.json | 8 +- Eraware_Dnn_Templates.sln | 4 +- .../source.extension.vsixmanifest | 82 +++++++++---------- build/Build.cs | 75 ++++++++++++++++- build/_build.csproj | 4 + 6 files changed, 129 insertions(+), 46 deletions(-) diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index dc3d6ac3..c926e00d 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -40,6 +40,8 @@ jobs: fetch-depth: 0 - name: 'Run: CI' run: ./build.cmd CI + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: 'Publish: artifacts' uses: actions/upload-artifact@v3 with: diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json index 3ca5c22f..5a3dc5b1 100644 --- a/.nuke/build.schema.json +++ b/.nuke/build.schema.json @@ -75,7 +75,9 @@ "CI", "Clean", "Compile", - "Restore" + "Release", + "Restore", + "SetVsixVersion" ] } }, @@ -92,7 +94,9 @@ "CI", "Clean", "Compile", - "Restore" + "Release", + "Restore", + "SetVsixVersion" ] } }, diff --git a/Eraware_Dnn_Templates.sln b/Eraware_Dnn_Templates.sln index 16e27330..18fd9845 100644 --- a/Eraware_Dnn_Templates.sln +++ b/Eraware_Dnn_Templates.sln @@ -20,8 +20,6 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {DEC1FDF7-0D64-4992-BB69-0E15EA6E8088}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DEC1FDF7-0D64-4992-BB69-0E15EA6E8088}.Release|Any CPU.ActiveCfg = Release|Any CPU {1AABA73D-8159-4BD7-BD86-F711E9BF8106}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1AABA73D-8159-4BD7-BD86-F711E9BF8106}.Debug|Any CPU.Build.0 = Debug|Any CPU {1AABA73D-8159-4BD7-BD86-F711E9BF8106}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -30,6 +28,8 @@ Global {6C652B7C-F011-419E-B90D-F75AB49A8F4B}.Debug|Any CPU.Build.0 = Debug|Any CPU {6C652B7C-F011-419E-B90D-F75AB49A8F4B}.Release|Any CPU.ActiveCfg = Release|Any CPU {6C652B7C-F011-419E-B90D-F75AB49A8F4B}.Release|Any CPU.Build.0 = Release|Any CPU + {DEC1FDF7-0D64-4992-BB69-0E15EA6E8088}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DEC1FDF7-0D64-4992-BB69-0E15EA6E8088}.Release|Any CPU.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Eraware_Dnn_Templates/source.extension.vsixmanifest b/Eraware_Dnn_Templates/source.extension.vsixmanifest index 19f0f9a1..e604dffb 100644 --- a/Eraware_Dnn_Templates/source.extension.vsixmanifest +++ b/Eraware_Dnn_Templates/source.extension.vsixmanifest @@ -1,42 +1,42 @@ - + - - - Eraware_Dnn_Templates - A WebAPI/WebComponents module template for DNN extensions. - LICENSE - https://github.com/valadas/Eraware_Dnn_Templates#readme - Eraware.ico - dnn - - - - x86 - - - x86 - - - x86 - - - amd64 - - - amd64 - - - amd64 - - - - - - - - - - - - - + + + Eraware_Dnn_Templates + A WebAPI/WebComponents module template for DNN extensions. + LICENSE + https://github.com/valadas/Eraware_Dnn_Templates#readme + Eraware.ico + dnn + + + + x86 + + + x86 + + + x86 + + + amd64 + + + amd64 + + + amd64 + + + + + + + + + + + + + \ No newline at end of file diff --git a/build/Build.cs b/build/Build.cs index 7b85226f..d91f4b0b 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -1,13 +1,18 @@ using System; +using System.IO; using System.Linq; +using System.Xml; using Nuke.Common; using Nuke.Common.CI; using Nuke.Common.CI.GitHubActions; using Nuke.Common.Execution; +using Nuke.Common.Git; using Nuke.Common.IO; using Nuke.Common.ProjectModel; using Nuke.Common.Tooling; using Nuke.Common.Tools.DotNet; +using Nuke.Common.Tools.GitHub; +using Nuke.Common.Tools.GitVersion; using Nuke.Common.Tools.MSBuild; using Nuke.Common.Utilities.Collections; using Octokit; @@ -15,11 +20,13 @@ using static Nuke.Common.IO.FileSystemTasks; using static Nuke.Common.IO.PathConstruction; using static Nuke.Common.Tools.DotNet.DotNetTasks; +using static Nuke.Common.Tools.GitHub.GitHubTasks; using static Nuke.Common.Tools.MSBuild.MSBuildTasks; [GitHubActions( "Build", GitHubActionsImage.WindowsLatest, + EnableGitHubToken = true, OnPullRequestBranches = new[] { "master", "main", "develop", "development", "release/*" }, OnPushBranches = new[] { "master", "develop", "release/*" }, InvokedTargets = new[] { nameof(CI) }, @@ -40,6 +47,11 @@ class Build : NukeBuild readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release; [Solution] readonly Solution Solution; + [GitRepository] readonly GitRepository GitRepository; + [GitVersion(UpdateAssemblyInfo = false)] readonly GitVersion GitVersion; + + static GitHubActions GitHubActions => GitHubActions.Instance; + static readonly string PackageContentType = "application/octet-stream"; AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts"; AbsolutePath TemplateProjectDirectory => RootDirectory / "Eraware_Dnn_Templates"; @@ -63,21 +75,82 @@ class Build : NukeBuild } }); + Target SetVsixVersion => _ => _ + .DependsOn(Restore) + .Executes(() => + { + var manifestFile = TemplateProjectDirectory / "source.extension.vsixmanifest"; + var manifest = new XmlDocument(); + manifest.Load(manifestFile); + var metadataNode = manifest.DocumentElement.ChildNodes.Cast().First(n => n.Name == "Metadata") as XmlElement; + var identityNode = metadataNode.ChildNodes.Cast().First(n => n.Name == "Identity") as XmlElement; + var versionAttribute = identityNode.Attributes["Version"]; + versionAttribute.Value = GitVersion.MajorMinorPatch; + manifest.Save(manifestFile); + }); + Target Compile => _ => _ .DependsOn(Restore) + .DependsOn(SetVsixVersion) .Executes(() => { MSBuild(s => s .SetTargetPath(Solution) - .SetConfiguration(Configuration)); + .SetConfiguration(Configuration) + .SetAssemblyVersion(GitVersion.AssemblySemVer) + .SetFileVersion(GitVersion.MajorMinorPatch) + .SetPackageVersion(GitVersion.MajorMinorPatch)); }); Target CI => _ => _ + .Description("Handles everything needed for CI") .DependsOn(Compile) .Produces(ArtifactsDirectory / "*.vsix") + .Triggers(Release) .Executes(() => { var vsix = TemplateProjectDirectory / "bin" / Configuration / "Eraware_Dnn_Templates.vsix"; CopyFileToDirectory(vsix, ArtifactsDirectory, FileExistsPolicy.Overwrite); }); + + Target Release => _ => _ + .OnlyWhenStatic(() => GitRepository.IsOnReleaseBranch() || GitRepository.IsOnMainOrMasterBranch()) + .Requires(() => Configuration.Equals(Configuration.Release)) + .Executes(async () => + { + var credentials = new Credentials(GitHubActions.Token); + GitHubTasks.GitHubClient = new GitHubClient(new ProductHeaderValue("Eraware.Dnn.Templates")) + { + Credentials = credentials, + }; + var (owner, name) = (GitRepository.GetGitHubOwner(), GitRepository.GetGitHubName()); + + var newRelease = new NewRelease(GitVersion.FullSemVer) + { + Draft = true, + Name = $"v{GitVersion.FullSemVer}", + GenerateReleaseNotes = true, + TargetCommitish = GitVersion.Sha, + Prerelease = GitRepository.IsOnReleaseBranch(), + }; + + var createdRelease = await GitHubTasks + .GitHubClient + .Repository + .Release + .Create(owner, name, newRelease); + + ArtifactsDirectory.GlobFiles("*") + .ForEach(async file => + { + await using var artifactStream = File.OpenRead(file); + var fileName = Path.GetFileName(file); + var assetUpload = new ReleaseAssetUpload + { + FileName = fileName, + }; + }); + + }); + } diff --git a/build/_build.csproj b/build/_build.csproj index b1965fae..f4c817fa 100644 --- a/build/_build.csproj +++ b/build/_build.csproj @@ -15,4 +15,8 @@ + + + + From d187c304f0032ba4629cda383f22b9114d6daf32 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 21 Aug 2024 20:07:07 -0400 Subject: [PATCH 5/5] Removed azure pipelines config --- azure-pipelines.yml | 51 --------------------------------------------- 1 file changed, 51 deletions(-) delete mode 100644 azure-pipelines.yml diff --git a/azure-pipelines.yml b/azure-pipelines.yml deleted file mode 100644 index e3a31235..00000000 --- a/azure-pipelines.yml +++ /dev/null @@ -1,51 +0,0 @@ -# ASP.NET -# Build and test ASP.NET projects. -# Add steps that publish symbols, save build artifacts, deploy, and more: -# https://docs.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4 - -trigger: -- master -- develop -- release - -pool: - vmImage: 'windows-latest' - -variables: - solution: '**/*.sln' - buildPlatform: 'Any CPU' - buildConfiguration: 'Release' - -steps: -- task: NuGetToolInstaller@1 - -- task: NuGetCommand@2 - inputs: - restoreSolution: '$(solution)' - -- task: VSBuild@1 - inputs: - solution: '$(solution)' - msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"' - platform: '$(buildPlatform)' - configuration: '$(buildConfiguration)' - -- task: VSTest@2 - inputs: - platform: '$(buildPlatform)' - configuration: '$(buildConfiguration)' - -- task: CopyFiles@2 - inputs: - SourceFolder: 'Eraware_Dnn_Templates\bin\Release' - Contents: '*.vsix' - TargetFolder: '$(Build.ArtifactStagingDirectory)' - CleanTargetFolder: true - OverWrite: true - flattenFolders: true - -- task: PublishBuildArtifacts@1 - inputs: - PathtoPublish: '$(Build.ArtifactStagingDirectory)' - ArtifactName: 'drop' - publishLocation: Container \ No newline at end of file