Skip to content

Commit ddb38f0

Browse files
committed
修改参数,改为当 ApiKeySource 同时为参数且有值时上传包
1 parent 7eb0a69 commit ddb38f0

File tree

4 files changed

+67
-64
lines changed

4 files changed

+67
-64
lines changed

.github/workflows/build_nuget.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,17 @@ jobs:
126126
ls unity/nuget/downloaded_natives
127127
tree unity/nuget/downloaded_natives
128128
shell: pwsh
129-
- name: Run NuGet Task
129+
- name: Run NuGet Packaging and Publishing
130+
if: ${{ github.event.inputs.publish == 'true' }}
130131
run: |
131132
cd unity/nuget
132-
.\build.ps1 --NativeAssetsDirectory "$pwd\downloaded_natives" --ProjectsRoot "$pwd" --UploadPackage "${{ github.event.inputs.publish }}"
133+
.\build.ps1 --NativeAssetsDirectory "$pwd\downloaded_natives" --ProjectsRoot "$pwd" --Source "https://api.nuget.org/v3/index.json" --ApiKey "${{ secrets.NUGET_PUB_KEY }}"
134+
shell: pwsh
135+
- name: Run NuGet Packaging
136+
if: ${{ github.event.inputs.publish == 'false' }}
137+
run: |
138+
cd unity/nuget
139+
.\build.ps1 --NativeAssetsDirectory "$pwd\downloaded_natives" --ProjectsRoot "$pwd"
133140
shell: pwsh
134141
- name: Upload NuGet Packages
135142
uses: actions/upload-artifact@v4

unity/nuget/Directory.Build.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
<PuertsNativeAssetsLinuxTargetFrameworks>net8.0</PuertsNativeAssetsLinuxTargetFrameworks>
5252
<PuertsNativeAssetsWin32TargetFrameworks>net8.0</PuertsNativeAssetsWin32TargetFrameworks>
5353
<PuertsNativeAssetsmacOSTargetFramework>net8.0</PuertsNativeAssetsmacOSTargetFramework>
54-
<PuertsCurrentTargetmacOSPlatformVersion>14.0</PuertsCurrentTargetmacOSPlatformVersion>
5554
</PropertyGroup>
5655

5756
</Project>

unity/nuget/README.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,36 +63,36 @@ var jsEnv = new ScriptEnv(
6363
<PuertsCurrentTargetmacOSPlatformVersion>14.0</PuertsCurrentTargetmacOSPlatformVersion>
6464
```
6565

66-
## 环境变量
66+
## 构建发布
6767

68-
```powershell
69-
$env:NUGET_SOURCE="https://example.com/v3/index.json"
70-
$env:NUGET_PUB_KEY="key"
71-
```
72-
73-
`NUGET_SOURCE` 打包发布的目标源 - 在指定 `UploadPackage` 后必须设置
74-
75-
`NUGET_PUB_KEY` 目标源的密钥 - 在指定 `UploadPackage` 后必须设置
76-
77-
## 构建
78-
79-
在Windows下构建
68+
在Windows下构建、发布
8069

8170
```powershell
82-
.\build.ps1 --NativeAssetsDirectory "xxx\puerts\unity\downloaded_natives" --ProjectsRoot "xxx\puerts\unity\nuget" --UploadPackage $true
71+
# 构建
72+
.\build.ps1 --NativeAssetsDirectory "xxx\puerts\unity\downloaded_natives" --ProjectsRoot "xxx\puerts\unity\nuget"
73+
# 构建并发布
74+
.\build.ps1 --NativeAssetsDirectory "xxx\puerts\unity\downloaded_natives" --ProjectsRoot "xxx\puerts\unity\nuget" --NUGET_SOURCE "https://api.nuget.org/v3/index.json" --NUGET_PUB_KEY "your-nuget-api-key"
75+
8376
```
8477

85-
在Linux/macOS下构建
78+
在Linux/macOS下构建、发布
8679

8780
```shell
88-
.\build.sh --NativeAssetsDirectory "xxx\puerts\unity\downloaded_natives" --ProjectsRoot "xxx\puerts\unity\nuget" --UploadPackage "true"
81+
# 构建
82+
./build.sh --NativeAssetsDirectory "xxx/puerts/unity/downloaded_natives" --ProjectsRoot "xxx/puerts/unity/nuget"
83+
# 构建并发布
84+
/build.sh --NativeAssetsDirectory "xxx/puerts/unity/downloaded_natives" --ProjectsRoot "xxx/puerts/unity/nuget" --NUGET_SOURCE "https://api.nuget.org/v3/index.json" --NUGET_PUB_KEY "your-nuget-api-key"
8985
```
9086

9187
### 构建参数
9288

9389
* `NativeAssetsDirectory` 原生文件目录,放置构建完成的 `native` 项目产物
9490
* `ProjectsRoot` nuget项目目录
95-
* `UploadPackage` 是否在构建完包之后上传到指定的 `NUGET_SOURCE`
91+
92+
### 发布参数
93+
94+
* `NUGET_SOURCE` 打包发布的目标源
95+
* `NUGET_PUB_KEY` 目标源的密钥 注意密钥安全
9696

9797
### 定义构建
9898

unity/nuget/build/Program.cs

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
* Puerts is licensed under the BSD 3-Clause License, except for the third-party components listed in the file 'LICENSE' which may be subject to their corresponding license terms.
55
* This file is subject to the terms and conditions defined in file 'LICENSE', which is part of this source code package.
66
*/
7+
8+
using System;
9+
using System.IO;
10+
using System.Linq;
711
using Cake.Common;
812
using Cake.Common.IO;
913
using Cake.Common.Tools.DotNet;
@@ -12,9 +16,8 @@
1216
using Cake.Core.Diagnostics;
1317
using Cake.Core.IO;
1418
using Cake.Frosting;
15-
using System;
16-
using System.IO;
17-
using System.Linq;
19+
20+
namespace Build;
1821

1922
public static class Program
2023
{
@@ -40,19 +43,18 @@ public class BuildContext : FrostingContext
4043
public IDirectory ProjectsRoot => this.HasArgument("ProjectsRoot")
4144
? FileSystem.GetDirectory(new DirectoryPath(Arguments.GetArgument("ProjectsRoot")))
4245
: throw new CakeException($"Argument '{nameof(ProjectsRoot)}' is required.");
43-
public bool IsUploadPackageEnabled => this.HasArgument("UploadPackage")
44-
&& Arguments.GetArgument("UploadPackage").Equals("true", StringComparison.OrdinalIgnoreCase);
45-
public string NUGET_SOURCE => this.HasEnvironmentVariable("NUGET_SOURCE")
46-
? Environment.GetEnvironmentVariable("NUGET_SOURCE")
47-
: throw new CakeException("NUGET_SOURCE is not defined in environment variables");
48-
public string NUGET_PUB_KEY
46+
public bool IsUploadPackageEnabled => this.HasArgument("Source") && this.HasArgument("ApiKey");
47+
public string Source => this.HasArgument("Source")
48+
? Arguments.GetArgument("Source")
49+
: throw new CakeException($"Argument '{nameof(Source)}' is required.");
50+
public string ApiKey
4951
{
5052
get
5153
{
52-
Log.Warning("Accessing Secret: {0}", nameof(NUGET_PUB_KEY));
53-
return this.HasEnvironmentVariable("NUGET_PUB_KEY")
54-
? Environment.GetEnvironmentVariable("NUGET_PUB_KEY")
55-
: throw new CakeException("NUGET_PUB_KEY is not defined in environment variables");
54+
Log.Warning("Accessing Secret: {0}", nameof(ApiKey));
55+
return this.HasArgument("ApiKey")
56+
? Arguments.GetArgument("ApiKey")
57+
: throw new CakeException($"Argument '{nameof(ApiKey)}' is required.");
5658
}
5759
}
5860
public BuildContext(ICakeContext context)
@@ -216,8 +218,8 @@ public override void Run(BuildContext context)
216218
new FilePath(nugetPackageFile),
217219
new Cake.Common.Tools.DotNet.NuGet.Push.DotNetNuGetPushSettings()
218220
{
219-
Source = context.NUGET_SOURCE,
220-
ApiKey = context.NUGET_PUB_KEY
221+
Source = context.Source,
222+
ApiKey = context.ApiKey
221223
});
222224
}
223225
}
@@ -234,14 +236,9 @@ public override void Run(BuildContext context)
234236
{
235237
context.Log.Information("Build and packaging completed successfully.");
236238
context.Log.Information("Native assets have been collected and NuGet packages have been created.");
237-
if (context.IsUploadPackageEnabled)
238-
{
239-
context.Log.Information("NuGet packages have been uploaded to the specified source.");
240-
}
241-
else
242-
{
243-
context.Log.Information("Package upload is disabled. No packages were uploaded.");
244-
}
239+
context.Log.Information(context.IsUploadPackageEnabled
240+
? "NuGet packages have been uploaded to the specified source."
241+
: "Package upload is disabled. No packages were uploaded.");
245242
}
246243
}
247244

@@ -265,27 +262,27 @@ public static class WellKnownProjects
265262
/// This also needs to be defined in their csproj file.
266263
/// </remarks>
267264
public static readonly ProjectAndRidWithNativeName[] NativeAssetsProjects =
268-
[
269-
new ProjectAndRidWithNativeName { Name = "Puerts.Core.NativeAssets.Win32", DotNetRid ="win-x64", DotNetNativeName = "Core" },
270-
new ProjectAndRidWithNativeName { Name = "Puerts.Core.NativeAssets.Linux", DotNetRid = "linux-x64", DotNetNativeName = "Core" },
271-
new ProjectAndRidWithNativeName { Name = "Puerts.Core.NativeAssets.macOS", DotNetRid = "osx", DotNetNativeName = "Core" },
272-
273-
new ProjectAndRidWithNativeName { Name = "Puerts.Lua.NativeAssets.Win32", DotNetRid = "win-x64", DotNetNativeName = "Lua" },
274-
new ProjectAndRidWithNativeName { Name = "Puerts.Lua.NativeAssets.Linux", DotNetRid = "linux-x64", DotNetNativeName = "Lua" },
275-
new ProjectAndRidWithNativeName { Name = "Puerts.Lua.NativeAssets.macOS", DotNetRid = "osx", DotNetNativeName = "Lua" },
276-
277-
new ProjectAndRidWithNativeName { Name = "Puerts.NodeJS.NativeAssets.Win32", DotNetRid = "win-x64", DotNetNativeName = "NodeJS" },
278-
new ProjectAndRidWithNativeName { Name = "Puerts.NodeJS.NativeAssets.Linux", DotNetRid = "linux-x64", DotNetNativeName = "NodeJS" },
279-
new ProjectAndRidWithNativeName { Name = "Puerts.NodeJS.NativeAssets.macOS", DotNetRid = "osx", DotNetNativeName = "NodeJS" },
280-
281-
new ProjectAndRidWithNativeName { Name = "Puerts.QuickJS.NativeAssets.Win32", DotNetRid = "win-x64", DotNetNativeName = "QuickJS" },
282-
new ProjectAndRidWithNativeName { Name = "Puerts.QuickJS.NativeAssets.Linux", DotNetRid = "linux-x64", DotNetNativeName = "QuickJS" },
283-
new ProjectAndRidWithNativeName { Name = "Puerts.QuickJS.NativeAssets.macOS", DotNetRid = "osx", DotNetNativeName = "QuickJS" },
284-
285-
new ProjectAndRidWithNativeName { Name = "Puerts.V8.NativeAssets.Win32", DotNetRid = "win-x64", DotNetNativeName = "V8" },
286-
new ProjectAndRidWithNativeName { Name = "Puerts.V8.NativeAssets.Linux", DotNetRid = "linux-x64", DotNetNativeName = "V8" },
287-
new ProjectAndRidWithNativeName { Name = "Puerts.V8.NativeAssets.macOS", DotNetRid = "osx", DotNetNativeName = "V8" },
288-
];
265+
[
266+
new() { Name = "Puerts.Core.NativeAssets.Win32", DotNetRid ="win-x64", DotNetNativeName = "Core" },
267+
new() { Name = "Puerts.Core.NativeAssets.Linux", DotNetRid = "linux-x64", DotNetNativeName = "Core" },
268+
new() { Name = "Puerts.Core.NativeAssets.macOS", DotNetRid = "osx", DotNetNativeName = "Core" },
269+
270+
new() { Name = "Puerts.Lua.NativeAssets.Win32", DotNetRid = "win-x64", DotNetNativeName = "Lua" },
271+
new() { Name = "Puerts.Lua.NativeAssets.Linux", DotNetRid = "linux-x64", DotNetNativeName = "Lua" },
272+
new() { Name = "Puerts.Lua.NativeAssets.macOS", DotNetRid = "osx", DotNetNativeName = "Lua" },
273+
274+
new() { Name = "Puerts.NodeJS.NativeAssets.Win32", DotNetRid = "win-x64", DotNetNativeName = "NodeJS" },
275+
new() { Name = "Puerts.NodeJS.NativeAssets.Linux", DotNetRid = "linux-x64", DotNetNativeName = "NodeJS" },
276+
new() { Name = "Puerts.NodeJS.NativeAssets.macOS", DotNetRid = "osx", DotNetNativeName = "NodeJS" },
277+
278+
new() { Name = "Puerts.QuickJS.NativeAssets.Win32", DotNetRid = "win-x64", DotNetNativeName = "QuickJS" },
279+
new() { Name = "Puerts.QuickJS.NativeAssets.Linux", DotNetRid = "linux-x64", DotNetNativeName = "QuickJS" },
280+
new() { Name = "Puerts.QuickJS.NativeAssets.macOS", DotNetRid = "osx", DotNetNativeName = "QuickJS" },
281+
282+
new() { Name = "Puerts.V8.NativeAssets.Win32", DotNetRid = "win-x64", DotNetNativeName = "V8" },
283+
new() { Name = "Puerts.V8.NativeAssets.Linux", DotNetRid = "linux-x64", DotNetNativeName = "V8" },
284+
new() { Name = "Puerts.V8.NativeAssets.macOS", DotNetRid = "osx", DotNetNativeName = "V8" },
285+
];
289286
}
290287

291288
public class ProjectAndRidWithNativeName

0 commit comments

Comments
 (0)