Skip to content

Commit 62a0df8

Browse files
committed
(build) use git cmd instead of cake.git for push
cleaning up the credentials, keeping only token were needed
1 parent 08b777c commit 62a0df8

File tree

9 files changed

+28
-25
lines changed

9 files changed

+28
-25
lines changed

build/.run/Publish Docs.run.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<component name="ProjectRunConfigurationManager">
22
<configuration default="false" name="Publish Docs" type="DotNetProject" factoryName=".NET Project" folderName="Docs">
33
<option name="EXE_PATH" value="$PROJECT_DIR$/../run/docs.exe" />
4-
<option name="PROGRAM_PARAMETERS" value="--target=PublishDocs" />
4+
<option name="PROGRAM_PARAMETERS" value="--target=PublishDocs --force" />
55
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/.." />
66
<option name="PASS_PARENT_ENVS" value="1" />
77
<option name="USE_EXTERNAL_CONSOLE" value="0" />

build/common/Utilities/Constants.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace Common.Utilities
22
{
33
public class Constants
44
{
5-
public const string RepoOwner = "gittools";
5+
public const string RepoOwner = "GitTools";
66
public const string Repository = "GitVersion";
77

88
public const string Version50 = "5.0";

build/common/Utilities/ContextExtensions.cs

+16-6
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,27 @@ namespace Common.Utilities
1212
{
1313
public static class ContextExtensions
1414
{
15-
private static IEnumerable<string> ExecuteCommand(this ICakeContext context, FilePath exe, string? args)
15+
private static IEnumerable<string> ExecuteCommand(this ICakeContext context, FilePath exe, string? args, DirectoryPath? workDir = null)
1616
{
1717
var processSettings = new ProcessSettings { Arguments = args, RedirectStandardOutput = true };
18+
if (workDir is not null)
19+
{
20+
processSettings.WorkingDirectory = workDir;
21+
}
1822
context.StartProcess(exe, processSettings, out var redirectedOutput);
1923
return redirectedOutput.ToList();
2024
}
2125

22-
private static IEnumerable<string> ExecGitCmd(this ICakeContext context, string? cmd)
26+
private static IEnumerable<string> ExecGitCmd(this ICakeContext context, string? cmd, DirectoryPath? workDir = null)
2327
{
2428
var gitExe = context.Tools.Resolve(context.IsRunningOnWindows() ? "git.exe" : "git");
25-
return context.ExecuteCommand(gitExe, cmd);
29+
return context.ExecuteCommand(gitExe, cmd, workDir);
30+
}
31+
32+
public static void GitPushBranch(this ICakeContext context, DirectoryPath repositoryDirectoryPath, string username, string token, string branchName)
33+
{
34+
var pushUrl = $"https://{username}:{token}@github.com/{Constants.RepoOwner}/{Constants.Repository}";
35+
context.ExecGitCmd($"push {pushUrl} {branchName}", workDir: repositoryDirectoryPath);
2636
}
2737

2838
public static bool IsOriginalRepo(this ICakeContext context)
@@ -49,7 +59,7 @@ public static bool IsOriginalRepo(this ICakeContext context)
4959
public static bool IsMainBranch(this ICakeContext context)
5060
{
5161
var buildSystem = context.BuildSystem();
52-
string repositoryBranch = ExecGitCmd(context, "rev-parse --abbrev-ref HEAD").Single();
62+
string repositoryBranch = context.ExecGitCmd("rev-parse --abbrev-ref HEAD").Single();
5363
if (buildSystem.IsRunningOnAppVeyor)
5464
{
5565
repositoryBranch = buildSystem.AppVeyor.Environment.Repository.Branch;
@@ -70,8 +80,8 @@ public static bool IsMainBranch(this ICakeContext context)
7080

7181
public static bool IsTagged(this ICakeContext context)
7282
{
73-
var sha = ExecGitCmd(context, "rev-parse --verify HEAD").Single();
74-
var isTagged = ExecGitCmd(context, "tag --points-at " + sha).Any();
83+
var sha = context.ExecGitCmd("rev-parse --verify HEAD").Single();
84+
var isTagged = context.ExecGitCmd("tag --points-at " + sha).Any();
7585

7686
return isTagged;
7787
}

build/common/Utilities/Models.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ public record CodeCovCredentials(string Token);
99

1010
public record GitHubCredentials(string Token, string? UserName = null);
1111

12-
public record NugetCredentials(string ApiKey, string ApiUrl);
12+
public record NugetCredentials(string ApiKey);
1313

14-
public record ChocolateyCredentials(string ApiKey, string ApiUrl);
14+
public record ChocolateyCredentials(string ApiKey);
1515

1616
public record BuildVersion(GitVersion GitVersion, string? Version, string? Milestone, string? SemVersion, string? NugetVersion)
1717
{

build/docs/BuildContext.cs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ public class BuildContext : BuildContextBase
99
{
1010
public bool ForcePublish { get; set; }
1111
public Credentials? Credentials { get; set; }
12-
1312
public WyamSettings? WyamSettings { get; set; }
1413

1514
public BuildContext(ICakeContext context) : base(context)

build/docs/Tasks/PublishDocs.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ private static void PublishToGitHub(BuildContext context, DirectoryPath publishF
122122
}
123123

124124
context.Information("Pushing all changes...");
125-
context.GitPush(publishFolder, username, token, publishBranchName);
125+
126+
context.GitPushBranch(publishFolder, username, token, publishBranchName);
126127
}
127128
}
128129
}

build/docs/docs.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
<RootNamespace>Docs</RootNamespace>
55
</PropertyGroup>
66
<ItemGroup>
7-
<ProjectReference Include="..\common\common.csproj"/>
7+
<ProjectReference Include="..\common\common.csproj" />
88
</ItemGroup>
99
<ItemGroup>
10-
<PackageReference Include="Cake.Git" Version="1.1.0"/>
11-
<PackageReference Include="Cake.Wyam" Version="2.2.12"/>
10+
<PackageReference Include="Cake.Git" Version="1.1.0" />
11+
<PackageReference Include="Cake.Wyam" Version="2.2.12" />
1212
</ItemGroup>
1313
</Project>

build/publish/Tasks/PublishNuget.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,8 @@ private static void PublishToNugetRepo(BuildContext context, string apiKey, stri
6969
}
7070
}
7171
// TODO check package is already published
72-
private static bool IsPackagePublished(BuildContext context, string? packageName, string? nugetVersion)
72+
private static bool IsPackagePublished(BuildContext context, string? packageName, string? nugetVersion, string apiUrl)
7373
{
74-
var apiUrl = context.Credentials?.Nuget?.ApiUrl;
7574
var publishedPackages = context.NuGetList($"packageId:{packageName} version:{nugetVersion}", new NuGetListSettings
7675
{
7776
Source = new[]

build/publish/Utilities/Credentials.cs

+2-8
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,8 @@ public class Credentials
1313
public static Credentials GetCredentials(ICakeContext context) => new()
1414
{
1515
GitHub = new GitHubCredentials(context.EnvironmentVariable("GITHUB_TOKEN")),
16-
17-
Nuget = new NugetCredentials(
18-
context.EnvironmentVariable("NUGET_API_KEY"),
19-
context.EnvironmentVariable("NUGET_API_URL")),
20-
21-
Chocolatey = new ChocolateyCredentials(
22-
context.EnvironmentVariable("CHOCOLATEY_API_KEY"),
23-
context.EnvironmentVariable("CHOCOLATEY_API_URL")),
16+
Nuget = new NugetCredentials(context.EnvironmentVariable("NUGET_API_KEY")),
17+
Chocolatey = new ChocolateyCredentials(context.EnvironmentVariable("CHOCOLATEY_API_KEY")),
2418
};
2519
}
2620
}

0 commit comments

Comments
 (0)