From f12a6b93e30237367f188c879c3d1d2b32c3ae1c Mon Sep 17 00:00:00 2001
From: guotianliang <1265346495@qq.com>
Date: Thu, 12 May 2022 14:50:52 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9E=84=E5=BB=BA=E5=8F=8A?=
=?UTF-8?q?=E5=8F=91=E5=B8=83Nuget=E5=8C=85=E8=84=9A=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
build/build-release.ps1 | 18 ++++++
common.props | 1 -
nupkg/common.ps1 | 126 ++++++++++++++++++++++++++++++++++++++++
nupkg/pack.ps1 | 43 ++++++++++++++
nupkg/push_packages.ps1 | 44 ++++++++++++++
5 files changed, 231 insertions(+), 1 deletion(-)
create mode 100644 build/build-release.ps1
create mode 100644 nupkg/common.ps1
create mode 100644 nupkg/pack.ps1
create mode 100644 nupkg/push_packages.ps1
diff --git a/build/build-release.ps1 b/build/build-release.ps1
new file mode 100644
index 0000000..b8d6b73
--- /dev/null
+++ b/build/build-release.ps1
@@ -0,0 +1,18 @@
+$rootFolder = (Get-Item -Path "./" -Verbose).FullName
+
+$solutionPaths = @(
+ "../"
+ )
+
+foreach ($solutionPath in $solutionPaths) {
+ $solutionAbsPath = (Join-Path $rootFolder $solutionPath)
+ Set-Location $solutionAbsPath
+ dotnet build --configuration Release
+ if (-Not $?) {
+ Write-Host ("Build failed for the solution: " + $solutionPath)
+ Set-Location $rootFolder
+ exit $LASTEXITCODE
+ }
+}
+
+Set-Location $rootFolder
\ No newline at end of file
diff --git a/common.props b/common.props
index 5402705..8a042e2 100644
--- a/common.props
+++ b/common.props
@@ -4,6 +4,5 @@
5.1.4
$(NoWarn);CS1591;
git
- true
\ No newline at end of file
diff --git a/nupkg/common.ps1 b/nupkg/common.ps1
new file mode 100644
index 0000000..d116eea
--- /dev/null
+++ b/nupkg/common.ps1
@@ -0,0 +1,126 @@
+# Nuget包文件夹
+$packFolder = (Get-Item -Path "./" -Verbose).FullName
+# 根文件夹
+$rootFolder = Join-Path $packFolder "../"
+
+function Write-Info
+{
+ param(
+ [Parameter(Mandatory = $true)]
+ [string]
+ $text
+ )
+
+ Write-Host $text -ForegroundColor Black -BackgroundColor Green
+
+ try
+ {
+ $host.UI.RawUI.WindowTitle = $text
+ }
+ catch
+ {
+ #Changing window title is not suppoerted!
+ }
+}
+
+function Write-Error
+{
+ param(
+ [Parameter(Mandatory = $true)]
+ [string]
+ $text
+ )
+
+ Write-Host $text -ForegroundColor Red -BackgroundColor Black
+}
+
+function Seperator
+{
+ Write-Host ("_" * 100) -ForegroundColor gray
+}
+
+function Get-Current-Version {
+ $commonPropsFilePath = resolve-path "../common.props"
+ $commonPropsXmlCurrent = [xml](Get-Content $commonPropsFilePath )
+ $currentVersion = $commonPropsXmlCurrent.Project.PropertyGroup.Version.Trim()
+ return $currentVersion
+}
+
+function Get-Current-Branch {
+ return git branch --show-current
+}
+
+function Read-File {
+ param(
+ [Parameter(Mandatory = $true)]
+ [string]
+ $filePath
+ )
+
+ $pathExists = Test-Path -Path $filePath -PathType Leaf
+ if ($pathExists)
+ {
+ return Get-Content $filePath
+ }
+ else{
+ Write-Error "$filePath path does not exist!"
+ }
+}
+
+# 解决方案列表
+$solutions = (
+ # Sanhe.Abp.Framework
+ "./"
+)
+
+# 项目列表
+$projects = (
+ # modules/common
+ "modules/common/Sanhe.Abp.EntityFrameworkCore",
+ "modules/common/Sanhe.Abp.ExceptionHandling",
+ "modules/common/Sanhe.Abp.ExceptionHandling.Emailing",
+ "modules/common/Sanhe.Abp.Features.LimitValidation",
+ "modules/common/Sanhe.Abp.Features.LimitValidation.Redis",
+ "modules/common/Sanhe.Abp.Features.LimitValidation.Redis.Client",
+ "modules/common/Sanhe.Abp.Hangfire.Dashboard",
+ "modules/common/Sanhe.Abp.Hangfire.Storage.PostgreSql",
+ "modules/common/Sanhe.Abp.IdGenerator",
+ "modules/common/Sanhe.Abp.Localization.Dynamic",
+ "modules/common/Sanhe.Abp.Notifications",
+ "modules/common/Sanhe.Abp.PinyinConverter",
+ "modules/common/Sanhe.Abp.PinyinConverter.ToolGoodWords",
+ "modules/common/Sanhe.Abp.RealTime",
+ "modules/common/Sanhe.Abp.Wrapper",
+
+ # modules/elasticsearch
+ "modules/elasticsearch/Sanhe.Abp.Elasticsearch",
+
+ # modules/identity
+ "modules/identity/Sanhe.Abp.Identity.Application",
+ "modules/identity/Sanhe.Abp.Identity.Application.Contracts",
+ "modules/identity/Sanhe.Abp.Identity.Domain",
+ "modules/identity/Sanhe.Abp.Identity.Domain.Shared",
+ "modules/identity/Sanhe.Abp.Identity.EntityFrameworkCore",
+ "modules/identity/Sanhe.Abp.Identity.HttpApi",
+ "modules/identity/Sanhe.Abp.Identity.HttpApi.Client",
+
+ # modules/localization-management
+ "modules/localization-management/Sanhe.Abp.LocalizationManagement.Application",
+ "modules/localization-management/Sanhe.Abp.LocalizationManagement.Application.Contracts",
+ "modules/localization-management/Sanhe.Abp.LocalizationManagement.Domain",
+ "modules/localization-management/Sanhe.Abp.LocalizationManagement.Domain.Shared",
+ "modules/localization-management/Sanhe.Abp.LocalizationManagement.EntityFrameworkCore",
+ "modules/localization-management/Sanhe.Abp.LocalizationManagement.HttpApi",
+
+ # modules/menu-management
+ "modules/menu-management/Sanhe.Abp.MenuManagement.Application",
+ "modules/menu-management/Sanhe.Abp.MenuManagement.Application.Contracts",
+ "modules/menu-management/Sanhe.Abp.MenuManagement.Domain",
+ "modules/menu-management/Sanhe.Abp.MenuManagement.Domain.Identity",
+ "modules/menu-management/Sanhe.Abp.MenuManagement.Domain.Shared",
+ "modules/menu-management/Sanhe.Abp.MenuManagement.EntityFrameworkCore",
+ "modules/menu-management/Sanhe.Abp.MenuManagement.HttpApi",
+
+ # modules/mvc
+ "modules/mvc/Sanhe.Abp.AspNetCore.Mvc.Wrapper"
+)
diff --git a/nupkg/pack.ps1 b/nupkg/pack.ps1
new file mode 100644
index 0000000..3458d6e
--- /dev/null
+++ b/nupkg/pack.ps1
@@ -0,0 +1,43 @@
+. ".\common.ps1"
+
+# 重新构建所有解决方案
+foreach($solution in $solutions) {
+ $solutionFolder = Join-Path $rootFolder $solution
+ Set-Location $solutionFolder
+ & dotnet restore
+}
+
+# 删除旧的Nuget包
+del *.nupkg
+
+# 创建新的Nuget包
+$i = 0
+$projectsCount = $projects.length
+Write-Info "Running dotnet pack on $projectsCount projects..."
+
+foreach($project in $projects) {
+ $i += 1
+ $projectFolder = Join-Path $rootFolder $project
+ $projectName = ($project -split '/')[-1]
+
+ # 创建Nuget包
+ Write-Info "[$i / $projectsCount] - Packing project: $projectName"
+ Set-Location $projectFolder
+ dotnet clean
+ dotnet pack -c Release
+
+ if (-Not $?) {
+ Write-Error "Packaging failed for the project: $projectName"
+ exit $LASTEXITCODE
+ }
+
+ # 移动Nuget包
+ $projectName = $project.Substring($project.LastIndexOf("/") + 1)
+ $projectPackPath = Join-Path $projectFolder ("/bin/Release/" + $projectName + ".*.nupkg")
+ Move-Item -Force $projectPackPath $packFolder
+
+ Seperator
+}
+
+# 退回Nuget包文件夹
+Set-Location $packFolder
\ No newline at end of file
diff --git a/nupkg/push_packages.ps1 b/nupkg/push_packages.ps1
new file mode 100644
index 0000000..a6532f3
--- /dev/null
+++ b/nupkg/push_packages.ps1
@@ -0,0 +1,44 @@
+. ".\common.ps1"
+
+$apiKey = $args[0]
+
+# 获取版本
+[xml]$commonPropsXml = Get-Content (Join-Path $rootFolder "common.props")
+$version = $commonPropsXml.Project.PropertyGroup.Version
+
+# 发布所有Nuget包
+$i = 0
+$errorCount = 0
+$totalProjectsCount = $projects.length
+$nugetUrl = "http://nuget.sanhexinxi.com:80/v3/index.json"
+Set-Location $packFolder
+
+foreach($project in $projects) {
+ $i += 1
+ $projectFolder = Join-Path $rootFolder $project
+ $projectName = ($project -split '/')[-1]
+ $nugetPackageName = $projectName + "." + $version + ".nupkg"
+ $nugetPackageExists = Test-Path $nugetPackageName -PathType leaf
+
+ Write-Info "[$i / $totalProjectsCount] - Pushing: $nugetPackageName"
+
+ if ($nugetPackageExists)
+ {
+ dotnet nuget push $nugetPackageName --skip-duplicate -s $nugetUrl --api-key "$apiKey"
+ #Write-Host ("Deleting package from local: " + $nugetPackageName)
+ #Remove-Item $nugetPackageName -Force
+ }
+ else
+ {
+ Write-Host ("********** ERROR PACKAGE NOT FOUND: " + $nugetPackageName) -ForegroundColor red
+ $errorCount += 1
+ #Exit
+ }
+
+ Write-Host "--------------------------------------------------------------`r`n"
+}
+
+if ($errorCount > 0)
+{
+ Write-Host ("******* $errorCount error(s) occured *******") -ForegroundColor red
+}