Skip to content

Commit

Permalink
add test local release
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Aug 30, 2023
1 parent 0238a4e commit e706b1d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
6 changes: 4 additions & 2 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
"Compile",
"CreateInstaller",
"PublishGitHubRelease",
"RestoreAndBuild"
"RestoreAndBuild",
"TestPublishGithubRelease"
]
}
},
Expand All @@ -89,7 +90,8 @@
"Compile",
"CreateInstaller",
"PublishGitHubRelease",
"RestoreAndBuild"
"RestoreAndBuild",
"TestPublishGithubRelease"
]
}
},
Expand Down
31 changes: 29 additions & 2 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class Build : NukeBuild
public const string BuildConfiguration = "Release";
public const string InstallerConfiguration = "Installer";
const string BinOutputFolder = "bin";

// define github token here

static readonly Lazy<string> MsBuildPath = new(() =>
{
if (IsServerBuild) return null;
Expand Down Expand Up @@ -120,6 +121,31 @@ class Build : NukeBuild
});
});

// target try test github release
Target TestPublishGithubRelease => _ => _
.Requires(() => GitRepository)
.Requires(() => GitVersion)
.TriggeredBy(RestoreAndBuild)
.OnlyWhenStatic(()=>IsLocalBuild || GitRepository.IsOnDevelopBranch())
.Executes(() =>
{
// get github token from environment variable with name: GITHUB_TOKEN
GitHubToken = Environment.GetEnvironmentVariable("GITHUB_TOKEN",EnvironmentVariableTarget.User);
if (GitHubToken == null || GitHubToken.Equals(string.Empty))
{
Log.Warning("Can't find github token, please set environment with variable name: GITHUB_TOKEN");
return;
}
GitHubTasks.GitHubClient = new GitHubClient(new ProductHeaderValue(Solution.Name))
{
Credentials = new Credentials(GitHubToken)
};
var gitHubName = GitRepository.GetGitHubName();
Log.Information("Detected Name: {Name}", gitHubName);
var gitHubOwner = GitRepository.GetGitHubOwner();
Log.Information("Detected Owner: {Owner}", gitHubOwner);
GetNewCommitMessages();
});
Target PublishGitHubRelease => _ => _
.Requires(() => GitHubToken)
.Requires(() => GitRepository)
Expand All @@ -129,7 +155,8 @@ class Build : NukeBuild
.TriggeredBy(CreateInstaller)
.Executes(() =>
{
// if local get the token from environment variable
GitHubToken = "";
GitHubTasks.GitHubClient = new GitHubClient(new ProductHeaderValue(Solution.Name))
{
Credentials = new Credentials(GitHubToken)
Expand Down

0 comments on commit e706b1d

Please sign in to comment.