Skip to content

Commit f9e9d35

Browse files
committed
(GH-2028) added GitHubActions build support
1 parent 2e5e97e commit f9e9d35

File tree

6 files changed

+23
-2
lines changed

6 files changed

+23
-2
lines changed

build.cake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Setup<BuildParameters>(context =>
7171
if (parameters.IsRunningOnAppVeyor) Information("Building on AppVeyor");
7272
if (parameters.IsRunningOnTravis) Information("Building on Travis");
7373
if (parameters.IsRunningOnAzurePipeline) Information("Building on AzurePipeline");
74+
if (parameters.IsRunningOnGitHubActions) Information("Building on GitHubActions");
7475

7576
Information("Building version {0} of GitVersion ({1}, {2})",
7677
parameters.Version.SemVersion,

build/utils/docker.cake

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ DockerContainerRunSettings GetDockerRunSettings(BuildParameters parameters)
127127
$"BUILD_SOURCEBRANCH={Context.EnvironmentVariable("BUILD_SOURCEBRANCH")}"
128128
};
129129
}
130+
if (parameters.IsRunningOnGitHubActions) {
131+
settings.Env = new[]
132+
{
133+
"GITHUB_ACTIONS=true",
134+
$"GITHUB_REF={Context.EnvironmentVariable("GITHUB_REF")}"
135+
};
136+
}
130137

131138
return settings;
132139
}
@@ -170,7 +177,7 @@ string[] GetDockerTags(DockerImage dockerImage, BuildParameters parameters) {
170177
static string GetDockerCliPlatform(this ICakeContext context)
171178
{
172179
var buildSystem = context.BuildSystem();
173-
var ciSupportsDockerBuild = buildSystem.IsRunningOnAzurePipelines || buildSystem.IsRunningOnAzurePipelinesHosted;
180+
var ciSupportsDockerBuild = buildSystem.IsRunningOnAzurePipelines || buildSystem.IsRunningOnAzurePipelinesHosted || buildSystem.IsRunningOnGitHubActions;
174181

175182
if (ciSupportsDockerBuild && context.Environment.Platform.Family != PlatformFamily.OSX || buildSystem.IsLocalBuild)
176183
{

build/utils/parameters.cake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class BuildParameters
3636
public bool IsRunningOnAppVeyor { get; private set; }
3737
public bool IsRunningOnTravis { get; private set; }
3838
public bool IsRunningOnAzurePipeline { get; private set; }
39+
public bool IsRunningOnGitHubActions { get; private set; }
3940

4041
public bool IsReleasingCI { get; private set; }
4142

@@ -94,8 +95,9 @@ public class BuildParameters
9495
IsRunningOnAppVeyor = buildSystem.IsRunningOnAppVeyor,
9596
IsRunningOnTravis = buildSystem.IsRunningOnTravisCI,
9697
IsRunningOnAzurePipeline = buildSystem.IsRunningOnAzurePipelines || buildSystem.IsRunningOnAzurePipelinesHosted,
98+
IsRunningOnGitHubActions = buildSystem.IsRunningOnGitHubActions,
9799

98-
IsReleasingCI = buildSystem.IsRunningOnAzurePipelines || buildSystem.IsRunningOnAzurePipelinesHosted,
100+
IsReleasingCI = buildSystem.IsRunningOnAzurePipelines || buildSystem.IsRunningOnAzurePipelinesHosted || buildSystem.IsRunningOnGitHubActions,
99101

100102
IsDockerForWindows = dockerCliPlatform == "windows",
101103
IsDockerForLinux = dockerCliPlatform == "linux",

build/utils/utils.cake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public static bool IsOnMainRepo(this ICakeContext context)
2525
{
2626
repositoryName = buildSystem.TFBuild.Environment.Repository.RepoName;
2727
}
28+
else if (buildSystem.IsRunningOnGitHubActions)
29+
{
30+
repositoryName = buildSystem.GitHubActions.Environment.Workflow.Repository;
31+
}
2832

2933
context.Information("Repository Name: {0}" , repositoryName);
3034

@@ -47,6 +51,10 @@ public static bool IsOnMainBranch(this ICakeContext context)
4751
{
4852
repositoryBranch = buildSystem.TFBuild.Environment.Repository.SourceBranchName;
4953
}
54+
else if (buildSystem.IsRunningOnGitHubActions)
55+
{
56+
repositoryBranch = buildSystem.GitHubActions.Environment.Workflow.Ref.Replace("refs/heads/", "");
57+
}
5058

5159
context.Information("Repository Branch: {0}" , repositoryBranch);
5260

src/GitVersionCore/BuildServers/GitHubActions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,7 @@ public override string GetCurrentBranch(bool usingDynamicRepos)
6161

6262
return base.GetCurrentBranch(usingDynamicRepos);
6363
}
64+
65+
public override bool PreventFetch() => false;
6466
}
6567
}

src/GitVersionExe.Tests/GitVersionHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ params KeyValuePair<string, string>[] environments
5050
{ TravisCi.EnvironmentVariableName, null },
5151
{ Jenkins.EnvironmentVariableName, null },
5252
{ AzurePipelines.EnvironmentVariableName, null },
53+
{ GitHubActions.EnvironmentVariableName, null },
5354
};
5455

5556
foreach (var environment in environments)

0 commit comments

Comments
 (0)