Move GITHUB_PASSWORD env var check out of VersionRepoUpdater.
This commit is contained in:
parent
d0a1e239dc
commit
e28450e5a3
3 changed files with 24 additions and 22 deletions
|
@ -554,25 +554,15 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
[Target(nameof(PrepareTargets.Init))]
|
[Target(nameof(PrepareTargets.Init))]
|
||||||
public static BuildTargetResult UpdateVersionsRepo(BuildTargetContext c)
|
public static BuildTargetResult UpdateVersionsRepo(BuildTargetContext c)
|
||||||
{
|
{
|
||||||
string nupkgFilePath = EnsureVariable("NUPKG_FILE_PATH");
|
string githubAuthToken = EnvVars.EnsureVariable("GITHUB_PASSWORD");
|
||||||
string versionsRepoPath = EnsureVariable("VERSIONS_REPO_PATH");
|
string nupkgFilePath = EnvVars.EnsureVariable("NUPKG_FILE_PATH");
|
||||||
|
string versionsRepoPath = EnvVars.EnsureVariable("VERSIONS_REPO_PATH");
|
||||||
|
|
||||||
VersionRepoUpdater repoUpdater = new VersionRepoUpdater();
|
VersionRepoUpdater repoUpdater = new VersionRepoUpdater(githubAuthToken);
|
||||||
repoUpdater.UpdatePublishedVersions(nupkgFilePath, versionsRepoPath).Wait();
|
repoUpdater.UpdatePublishedVersions(nupkgFilePath, versionsRepoPath).Wait();
|
||||||
|
|
||||||
return c.Success();
|
return c.Success();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string EnsureVariable(string variableName)
|
|
||||||
{
|
|
||||||
string value = Environment.GetEnvironmentVariable(variableName);
|
|
||||||
if (string.IsNullOrEmpty(value))
|
|
||||||
{
|
|
||||||
throw new BuildFailureException($"'{variableName}' environment variable was not found.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using Microsoft.DotNet.Cli.Build.Framework;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Cli.Build
|
namespace Microsoft.DotNet.Cli.Build
|
||||||
{
|
{
|
||||||
|
@ -28,5 +29,16 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string EnsureVariable(string variableName)
|
||||||
|
{
|
||||||
|
string value = Environment.GetEnvironmentVariable(variableName);
|
||||||
|
if (string.IsNullOrEmpty(value))
|
||||||
|
{
|
||||||
|
throw new BuildFailureException($"'{variableName}' environment variable was not found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,29 +14,29 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
{
|
{
|
||||||
private static Regex s_nugetFileRegex = new Regex("^(.*?)\\.(([0-9]+\\.)?[0-9]+\\.[0-9]+(-([A-z0-9-]+))?)\\.nupkg$");
|
private static Regex s_nugetFileRegex = new Regex("^(.*?)\\.(([0-9]+\\.)?[0-9]+\\.[0-9]+(-([A-z0-9-]+))?)\\.nupkg$");
|
||||||
|
|
||||||
|
private string _gitHubAuthToken;
|
||||||
private string _gitHubUser;
|
private string _gitHubUser;
|
||||||
private string _gitHubEmail;
|
private string _gitHubEmail;
|
||||||
private string _gitHubAuthToken;
|
|
||||||
private string _versionsRepoOwner;
|
private string _versionsRepoOwner;
|
||||||
private string _versionsRepo;
|
private string _versionsRepo;
|
||||||
|
|
||||||
public VersionRepoUpdater(
|
public VersionRepoUpdater(
|
||||||
|
string gitHubAuthToken,
|
||||||
string gitHubUser = null,
|
string gitHubUser = null,
|
||||||
string gitHubEmail = null,
|
string gitHubEmail = null,
|
||||||
string gitHubAuthToken = null,
|
|
||||||
string versionRepoOwner = null,
|
string versionRepoOwner = null,
|
||||||
string versionsRepo = null)
|
string versionsRepo = null)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(gitHubAuthToken))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(gitHubAuthToken));
|
||||||
|
}
|
||||||
|
|
||||||
|
_gitHubAuthToken = gitHubAuthToken;
|
||||||
_gitHubUser = gitHubUser ?? "dotnet-bot";
|
_gitHubUser = gitHubUser ?? "dotnet-bot";
|
||||||
_gitHubEmail = gitHubEmail ?? "dotnet-bot@microsoft.com";
|
_gitHubEmail = gitHubEmail ?? "dotnet-bot@microsoft.com";
|
||||||
_versionsRepoOwner = versionRepoOwner ?? "dotnet";
|
_versionsRepoOwner = versionRepoOwner ?? "dotnet";
|
||||||
_versionsRepo = versionsRepo ?? "versions";
|
_versionsRepo = versionsRepo ?? "versions";
|
||||||
|
|
||||||
_gitHubAuthToken = gitHubAuthToken ?? Environment.GetEnvironmentVariable("GITHUB_PASSWORD");
|
|
||||||
if (string.IsNullOrEmpty(_gitHubAuthToken))
|
|
||||||
{
|
|
||||||
throw new ArgumentException("A GitHub auth token is required and wasn't provided. Set 'GITHUB_PASSWORD' environment variable.", nameof(gitHubAuthToken));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpdatePublishedVersions(string nupkgFilePath, string versionsRepoPath)
|
public async Task UpdatePublishedVersions(string nupkgFilePath, string versionsRepoPath)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue