fix.修复 PR 时 CI 爆炸的问题

GitHub 你罪大恶极!(划掉)

我是笨比(
This commit is contained in:
Liam Sho
2022-05-16 16:43:41 +08:00
parent ef8b8e03f3
commit 39ee8209d8
2 changed files with 17 additions and 1 deletions

View File

@@ -86,11 +86,15 @@ public partial class Build : NukeBuild
Information("5. 配置");
Information($"构建时间:{Parameters.BuildTime ?? "Null"}");
Information($"Commit Hash{Parameters.CommitHash ?? "Null"}");
Information($"Commit Hash Full{Parameters.CommitHashFull ?? "Null"}");
Information("6. CI");
Information($"在 GitHub Actions 中运行:{Parameters.IsGitHubActions}");
Information($"是 Pull Request{Parameters.IsPullRequest}");
Information($"是 Workflow Dispatch 触发:{Parameters.IsWorkflowDispatch}");
Information($"Actions 名称:{Parameters.GhActionName ?? "Null"}");
Information($"Actions 分支:{Parameters.GhBranch ?? "Null"}");
Information($"Actions PR{Parameters.GhPullRequestId ?? "Null"}");
Information($"Actions Tag{Parameters.GhTag ?? "Null"}");
Information("==========================");

View File

@@ -83,11 +83,13 @@ public partial class Build
// CI
public bool IsGitHubActions { get; }
public bool IsPullRequest { get; }
public bool IsWorkflowDispatch { get; }
public string GitHubPersonalAccessToken { get; } = null;
public Dictionary<string, string> WorkflowDispatchArguments { get; }
public ActionConfiguration GhActionName { get; } = null;
public string GhBranch { get; } = null;
public string GhPullRequestId { get; } = null;
public string GhTag { get; } = null;
public BuildParameters(Build b)
@@ -108,6 +110,7 @@ public partial class Build
MasterBranchRef = "refs/heads/master";
DevBranchRef = "refs/heads/dev";
ReleaseTagRefPrefix = "refs/tags/v";
// 路径
BuildOutput = RootDirectory / "x64";
@@ -158,6 +161,11 @@ public partial class Build
{
GhBranch = b.GitHubActions.Ref.Replace("refs/heads/", "");
}
else if (b.GitHubActions.Ref.StartsWith("refs/pull"))
{
IsPullRequest = true;
GhPullRequestId = b.GitHubActions.Ref.Replace("refs/pull/", "");
}
else
{
Assert.Fail($"不支持的 Ref{b.GitHubActions.Ref}");
@@ -186,13 +194,17 @@ public partial class Build
IsFork = true;
}
// 若是 DevBuildBranch 必须为 Dev又或者是手动触发
// 若是 DevBuildBranch 必须为 Dev或者是 PR又或者是手动触发
if (GhActionName == ActionConfiguration.DevBuild)
{
if (IsWorkflowDispatch)
{
Assert.True(GhBranch is not null, "DevBuild -> Workflow DispatchBranch 为 Null");
}
else if (IsPullRequest)
{
Assert.True(GhPullRequestId is not null, "DevBuild -> Pull RequestPull Request Id 为 Null");
}
else
{
Assert.True(GhBranch == DevBranch, "DevBuild -> Auto TriggeredBranch 不为 dev");