This repository has been archived by the owner on May 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
158 lines (137 loc) · 4.69 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
#tool dotnet:?package=GitVersion.Tool&version=5.12.0
#addin nuget:?package=System.Net.Http&version=4.3.4
var configuration = Argument("configuration", "Release");
var target = Argument("target", "Default");
var artifacts = "./BuildArtifacts/";
var solutionPath = File("./src/MediatR-vs.sln");
var version = "0.0.0";
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(ctx =>
{
if(!BuildSystem.IsLocalBuild) {
// get version and update dll info
var gitVersion = GitVersion(new GitVersionSettings {
UpdateAssemblyInfo = true
});
// update vsix info
var vsixs = GetFiles("./src/**/*.vsixmanifest");
foreach (var vsix in vsixs)
{
Verbose($"Updating version of {vsix.FullPath}");
XmlPoke(
vsix,
"/x:PackageManifest/x:Metadata/x:Identity/@Version",
$"{gitVersion.MajorMinorPatch}.{gitVersion.PreReleaseNumber}", // TODO: differentiate between CI-builds and Releases
new XmlPokeSettings
{
Namespaces = new Dictionary<string, string>
{
{ "x", "http://schemas.microsoft.com/developer/vsx-schema/2011" }
}
}
);
}
// TODO: source.extension.cs is generated from the vsixmanifest - if we modify the vsixmanifest, we should ensure
// that source.extension.cs is updated, too.
version = gitVersion.SemVer;
Information($"Building version {gitVersion.SemVer}.");
}
else
{
Information("Local build.");
var vsix = GetFiles("./src/**/*.vsixmanifest").First();
version = XmlPeek(
vsix,
"/x:PackageManifest/x:Metadata/x:Identity/@Version",
new XmlPeekSettings
{
Namespaces = new Dictionary<string, string>
{
{ "x", "http://schemas.microsoft.com/developer/vsx-schema/2011" }
}
});
}
});
Teardown(ctx =>
{
// Executed AFTER the last task.
Information("Finished running tasks.");
});
///////////////////////////////////////////////////////////////////////////////
// TASKS
///////////////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
CleanDirectories("./src/**/bin/");
CleanDirectories("./src/**/obj/");
CleanDirectory(artifacts);
});
Task("Restore")
.Does(() =>
{
NuGetRestore(solutionPath);
});
Task("Build")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.Does(() =>
{
MSBuild(solutionPath, settings =>
settings.SetPlatformTarget(PlatformTarget.MSIL)
.SetMSBuildPlatform(MSBuildPlatform.x86)
.UseToolVersion(MSBuildToolVersion.VS2022)
.SetVerbosity(Verbosity.Quiet)
.WithTarget("Build")
.SetConfiguration(configuration));
var files = GetFiles("./src/**/*.vsix");
foreach (var file in files)
{
var target = artifacts + File($"{file.GetFilenameWithoutExtension().ToString()}-v{version}.vsix");
CopyFile(file, target);
}
});
Task("PublishToOpenGallery")
.IsDependentOn("Build")
.WithCriteria(() => !BuildSystem.IsLocalBuild)
.Does(() =>
{
var baseUrl = "https://www.vsixgallery.com/api/upload";
var vsixs = GetFiles(artifacts + File("**/*.vsix"));
var repo = System.Net.WebUtility.UrlEncode($"https://github.com/nils-org/MediatR-vs/");
var issues = System.Net.WebUtility.UrlEncode($"https://github.com/nils-org/MediatR-vs/issues/");
var client = new System.Net.Http.HttpClient();
foreach (var vsix in vsixs)
{
var url = $"{baseUrl}?repo={repo}&issuetracker={issues}";
var fileName = vsix.GetFilename().ToString();
var content = new System.Net.Http.MultipartFormDataContent();
var fileContent = new System.Net.Http.ByteArrayContent(
System.IO.File.ReadAllBytes(
MakeAbsolute(vsix).FullPath));
fileContent.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("multipart/form-data");
content.Add(fileContent, "file", fileName);
var request = new System.Net.Http.HttpRequestMessage(
System.Net.Http.HttpMethod.Post,
url)
{
Content = content
};
var response = client.Send(request);
if(response.IsSuccessStatusCode)
{
Information($"Uploaded {fileName}");
}
else
{
Warning($"Error uploading vsix. Status:{response.StatusCode} - {response.ReasonPhrase}");
Verbose(response.Content.ReadAsStringAsync().GetAwaiter().GetResult());
}
}
});
Task("Default")
.IsDependentOn("Build")
.IsDependentOn("PublishToOpenGallery");
RunTarget(target);