-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.cake
107 lines (88 loc) · 2.9 KB
/
build.cake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#tool dotnet:?package=GitVersion.Tool&version=5.6.8
#addin nuget:?package=Cake.Docker&version=1.0.0
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var imageName = Argument("imageName", "dependabot-cake");
// test
var testRepositoryName = Argument("test-RepositoryName", "nils-a/Cake.7zip");
var testRepositoryBranch = Argument("test-RepositoryBranch", "develop");
var testFolders = Arguments<string>("test-folder", null).Where(x => x != null).ToList();
var testIgnore = Arguments<string>("test-ignore", null).Where(x => x != null).ToList();
var testNoDryRun = HasArgument("test-no-dryrun");
///////////////////////////////////////////////////////////////////////////////
// TASKS
///////////////////////////////////////////////////////////////////////////////
var imageFullTag = "";
Task("Calculate-Image-Tag")
.Does(() =>
{
var version = GitVersion();
imageFullTag = $"{imageName}:{version.SemVer}";
Information($"calculated tag for image: {imageFullTag}");
});
Task("Build-Image")
.IsDependentOn("Calculate-Image-Tag")
.Does(() =>
{
DockerBuild(new DockerImageBuildSettings
{
Tag = new[] {imageFullTag},
}, "src");
});
Task("Run-Test")
.IsDependentOn("Calculate-Image-Tag")
.IsDependentOn("Build-Image")
.Does(() =>
{
Information($"running test on RepositoryName:{testRepositoryName} branch:{testRepositoryBranch}");
if(testFolders.Count > 0)
{
Information($"searching in folders: {string.Join(", ", (IEnumerable<string>)testFolders)}");
}
if(testIgnore.Count > 0)
{
Information($"ignoring packages: {string.Join(", ", (IEnumerable<string>)testIgnore)}");
}
if(testNoDryRun)
{
Warning("NO-DRY-RUN is set. Real PRs will be created.");
}
var branches = string.Join("\n", testRepositoryBranch);
var envArgs = new List<string>
{
$"GITHUB_REPOSITORY={testRepositoryName}",
$"INPUT_TARGET_BRANCH={branches}",
"INPUT_TOKEN",
};
if (testFolders.Count > 0)
{
envArgs.Add($"INPUT_DIRECTORY={string.Join("\n", (IEnumerable<string>)testFolders)}");
}
if (!testNoDryRun)
{
envArgs.Add("DRY_RUN=1");
}
if(testIgnore.Count > 0)
{
envArgs.Add($"INPUT_IGNORE={string.Join("\n", (IEnumerable<string>)testIgnore)}");
}
if(string.IsNullOrEmpty(EnvironmentVariable("INPUT_TOKEN")))
{
throw new ArgumentException("'INPUT_TOKEN' not set. Please set INPUT_TOKEN to your GitHub pat");
}
DockerRunWithoutResult(new DockerContainerRunSettings
{
Env = envArgs.ToArray(),
Rm = true,
},
imageFullTag,
"");
});
Task("Default")
.Does(() => {
Information($"test no dry-run is: {testNoDryRun}");
Warning("Currently there is no default. Chose a better target!");
});
RunTarget(target);