This repository has been archived by the owner on Sep 25, 2023. It is now read-only.
forked from jjcollinge/traefik-on-service-fabric
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.cake
173 lines (145 loc) · 4.95 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#addin "nuget:?package=Newtonsoft.Json&version=9.0.1"
#addin "nuget:?package=Cake.Json&version=3.0.0"
#tool "nuget:?package=OctopusTools&version=4.24.4"
#tool "nuget:?package=GitVersion.CommandLine&Version=4.0.0"
#addin "nuget:?package=Cake.FileHelpers&version=3.1.0"
#addin "nuget:?package=Cake.Git&version=0.19.0"
var target = Argument("target", "Build");
var configuration = Argument("configuration", "Release");
var sfPackageRoot = "./src/Traefik/";
Task("Clean")
.WithCriteria(c => HasArgument("rebuild"))
.Does(() =>
{
//CleanDirectory($"./src/Example/bin/{configuration}");
});
Task("Build")
.IsDependentOn("Clean")
.Does(() =>
{
NuGetRestore($"./src/Traefik.sln");
MSBuild($"./src/Traefik.sln");
MSBuild($"{sfPackageRoot}Traefik.sfproj", new MSBuildSettings{
Configuration = configuration,
ToolVersion = MSBuildToolVersion.VS2019
}.WithTarget("Package"));
EnsureDirectoryExists( $"{sfPackageRoot}pkg/Release/PublishProfiles/");
CopyFiles($"{sfPackageRoot}PublishProfiles/*.xml", $"{sfPackageRoot}pkg/Release/PublishProfiles/");
EnsureDirectoryExists( $"{sfPackageRoot}pkg/Release/ApplicationParameters/");
CopyFiles($"{sfPackageRoot}ApplicationParameters/*.xml", $"{sfPackageRoot}pkg/Release/ApplicationParameters/");
});
GitVersion semVer = null;
Task("Apply Version")
.WithCriteria(EnvironmentVariable("GH_UNAME") != null && EnvironmentVariable("GH_PASSWORD") != null)
.Does(() =>
{
var result = GitVersion(new GitVersionSettings
{
UserName = EnvironmentVariable("GH_UNAME"),
Password = EnvironmentVariable("GH_PASSWORD")
});
semVer = result;
//FileWriteText("./version.properties", $"LAST_RELEASED_TAG={semVer.MajorMinorPatch}");
//update the package.json file at root for versioning.
var jObj = ParseJsonFromFile("./package.json");
jObj.Property("version").Value = semVer.MajorMinorPatch;
SerializeJsonToPrettyFile("./package.json", jObj);
Information(semVer.MajorMinorPatch);
});
Task("Package")
.IsDependentOn("Build")
.IsDependentOn("Apply Version")
.Does(() =>
{
EnsureDirectoryExists("./artifacts/ServiceFabric");
CopyDirectory($"{sfPackageRoot}pkg/Release", "./artifacts/ServiceFabric");
UpdateServiceManifest(File($"./artifacts/ServiceFabric/TraefikPkg/ServiceManifest.xml"));
UpdateAppManifest(File("./artifacts/ServiceFabric/ApplicationManifest.xml"));
OctoPack("ServiceFabric.Traefik", new OctopusPackSettings
{
Version = semVer.MajorMinorPatch,
BasePath = "./artifacts/ServiceFabric",
OutFolder = Directory("./artifacts/microservices"),
Format = OctopusPackFormat.Zip,
Overwrite = true
});
});
Task("Release")
.WithCriteria(EnvironmentVariable("GH_UNAME") != null
&& EnvironmentVariable("GH_PASSWORD") != null
&& EnvironmentVariable("OCTO_API_KEY") != null
&& EnvironmentVariable("NUGET_API") != null)
.IsDependentOn("Apply Version")
.IsDependentOn("Package")
.Does(() =>
{
foreach (var package in GetFiles("./artifacts/microservices/*." + semVer.MajorMinorPatch + "*.*"))
{
Information($"Publishing Package {package}");
OctoPush("https://octo.thuzi.com/",
EnvironmentVariable("OCTO_API_KEY"),
package,
new OctopusPushSettings
{
ReplaceExisting = true
});
}
OctoCreateRelease("ServiceFabric - Traefik", new CreateReleaseSettings
{
Server = "https://octo.thuzi.com/",
ApiKey = EnvironmentVariable("OCTO_API_KEY"),
ReleaseNumber = semVer.MajorMinorPatch,
DeploymentProgress = false,
DeployTo ="Events Platform - Staging",
WaitForDeployment = false,
});
Information($"\tTagging this build: "+semVer.MajorMinorPatch);
GitTag(".", semVer.MajorMinorPatch);
Information($"\tPushing the tag: "+semVer.MajorMinorPatch);
GitPushRef(".", EnvironmentVariable("GH_UNAME"), EnvironmentVariable("GH_PASSWORD"), "origin", semVer.MajorMinorPatch);
});
void UpdateServiceManifest(FilePath file)
{
XmlPoke(file, "/x:ServiceManifest/x:CodePackage[@Name=\"Code\"]/@Version",
semVer.MajorMinorPatch,
new XmlPokeSettings
{
Namespaces = new Dictionary<string, string>
{
{ "x", "http://schemas.microsoft.com/2011/01/fabric" }
}
});
XmlPoke(file, "/x:ServiceManifest/@Version",
semVer.MajorMinorPatch,
new XmlPokeSettings
{
Namespaces = new Dictionary<string, string>
{
{ "x", "http://schemas.microsoft.com/2011/01/fabric" }
}
});
}
void UpdateAppManifest(FilePath file)
{
XmlPoke(file,
"/x:ApplicationManifest/@ApplicationTypeVersion",
semVer.MajorMinorPatch,
new XmlPokeSettings
{
Namespaces = new Dictionary<string, string>
{
{ "x", "http://schemas.microsoft.com/2011/01/fabric" }
}
});
XmlPoke(file,
$"//x:ServiceManifestRef[@ServiceManifestName=\"TraefikPkg\"]/@ServiceManifestVersion",
semVer.MajorMinorPatch,
new XmlPokeSettings
{
Namespaces = new Dictionary<string, string>
{
{ "x", "http://schemas.microsoft.com/2011/01/fabric" }
}
});
}
RunTarget(target);