Skip to content

Commit 2c8f1af

Browse files
committed
Improved build system
1 parent 2d5600f commit 2c8f1af

File tree

2 files changed

+212
-204
lines changed

2 files changed

+212
-204
lines changed

build.cake

Lines changed: 7 additions & 204 deletions
Original file line numberDiff line numberDiff line change
@@ -1,208 +1,11 @@
1-
/* ****************************************
2-
Publishing workflow
3-
-------------------
4-
5-
- Update CHANGELOG.md
6-
- Run a normal build with Cake
7-
- Push to devel and FF merge to master
8-
- Switch to master
9-
- Run a Publish build with Cake
10-
- Switch back to devel branch
11-
**************************************** */
12-
13-
#addin "Cake.FileHelpers"
14-
#addin "Octokit"
15-
using Octokit;
16-
171
var target = Argument("target", "Default");
18-
var configuration = Argument("configuration", "Release");
19-
var isRunningOnUnix = IsRunningOnUnix();
20-
var isRunningOnWindows = IsRunningOnWindows();
21-
var isRunningOnAppVeyor = AppVeyor.IsRunningOnAppVeyor;
22-
var isPullRequest = AppVeyor.Environment.PullRequest.IsPullRequest;
23-
var buildNumber = AppVeyor.Environment.Build.Number;
24-
var releaseNotes = ParseReleaseNotes("./CHANGELOG.md");
25-
var version = releaseNotes.Version.ToString();
26-
var buildDir = Directory("./src/AngleSharp.Io/bin") + Directory(configuration);
27-
var buildResultDir = Directory("./bin") + Directory(version);
28-
var nugetRoot = buildResultDir + Directory("nuget");
29-
30-
// Initialization
31-
// ----------------------------------------
32-
33-
Setup(_ =>
2+
var projectName = "AngleSharp.Io";
3+
var solutionName = "AngleSharp.Io";
4+
var frameworks = new Dictionary<String, String>
345
{
35-
Information("Building version {0} of AngleSharp.Io.", version);
36-
Information("For the publish target the following environment variables need to be set:");
37-
Information(" NUGET_API_KEY, GITHUB_API_TOKEN");
38-
});
39-
40-
// Tasks
41-
// ----------------------------------------
42-
43-
Task("Clean")
44-
.Does(() =>
45-
{
46-
CleanDirectories(new DirectoryPath[] { buildDir, buildResultDir, nugetRoot });
47-
});
48-
49-
Task("Restore-Packages")
50-
.IsDependentOn("Clean")
51-
.Does(() =>
52-
{
53-
NuGetRestore("./src/AngleSharp.Io.sln", new NuGetRestoreSettings
54-
{
55-
ToolPath = "tools/nuget.exe",
56-
});
57-
});
58-
59-
Task("Build")
60-
.IsDependentOn("Restore-Packages")
61-
.Does(() =>
62-
{
63-
ReplaceRegexInFiles("./src/Directory.Build.props", "(?<=<Version>)(.+?)(?=</Version>)", version);
64-
DotNetCoreBuild("./src/AngleSharp.Io.sln", new DotNetCoreBuildSettings
65-
{
66-
Configuration = configuration,
67-
});
68-
});
69-
70-
Task("Run-Unit-Tests")
71-
.IsDependentOn("Build")
72-
.Does(() =>
73-
{
74-
var settings = new DotNetCoreTestSettings
75-
{
76-
Configuration = configuration,
77-
};
78-
79-
if (isRunningOnAppVeyor)
80-
{
81-
settings.TestAdapterPath = Directory(".");
82-
settings.Logger = "Appveyor";
83-
// TODO Finds a way to exclude tests not allowed to run on appveyor
84-
// Not used in current code
85-
//settings.Where = "cat != ExcludeFromAppVeyor";
86-
}
87-
88-
DotNetCoreTest("./src/AngleSharp.Io.Tests/", settings);
89-
});
90-
91-
Task("Copy-Files")
92-
.IsDependentOn("Build")
93-
.Does(() =>
94-
{
95-
var framework = "netstandard2.0";
96-
var target = nugetRoot + Directory("lib") + Directory(framework);
97-
98-
CreateDirectory(target);
99-
CopyFiles(new FilePath[]
100-
{
101-
buildDir + Directory(framework) + File("AngleSharp.Io.dll"),
102-
buildDir + Directory(framework) + File("AngleSharp.Io.xml"),
103-
}, target);
104-
105-
CopyFiles(new FilePath[] { "src/AngleSharp.Io.nuspec" }, nugetRoot);
106-
});
107-
108-
Task("Create-Package")
109-
.IsDependentOn("Copy-Files")
110-
.Does(() =>
111-
{
112-
var nugetExe = GetFiles("./tools/**/nuget.exe").FirstOrDefault()
113-
?? (isRunningOnAppVeyor ? GetFiles("C:\\Tools\\NuGet3\\nuget.exe").FirstOrDefault() : null)
114-
?? throw new InvalidOperationException("Could not find nuget.exe.");
115-
116-
var nuspec = nugetRoot + File("AngleSharp.Io.nuspec");
117-
118-
NuGetPack(nuspec, new NuGetPackSettings
119-
{
120-
Version = version,
121-
OutputDirectory = nugetRoot,
122-
Symbols = false,
123-
Properties = new Dictionary<String, String>
124-
{
125-
{ "Configuration", configuration },
126-
},
127-
});
128-
});
129-
130-
Task("Publish-Package")
131-
.IsDependentOn("Create-Package")
132-
.IsDependentOn("Run-Unit-Tests")
133-
.Does(() =>
134-
{
135-
var apiKey = EnvironmentVariable("NUGET_API_KEY");
136-
137-
if (String.IsNullOrEmpty(apiKey))
138-
{
139-
throw new InvalidOperationException("Could not resolve the NuGet API key.");
140-
}
141-
142-
foreach (var nupkg in GetFiles(nugetRoot.Path.FullPath + "/*.nupkg"))
143-
{
144-
NuGetPush(nupkg, new NuGetPushSettings
145-
{
146-
Source = "https://nuget.org/api/v2/package",
147-
ApiKey = apiKey,
148-
});
149-
}
150-
});
151-
152-
Task("Publish-Release")
153-
.IsDependentOn("Publish-Package")
154-
.IsDependentOn("Run-Unit-Tests")
155-
.Does(() =>
156-
{
157-
var githubToken = EnvironmentVariable("GITHUB_API_TOKEN");
158-
159-
if (String.IsNullOrEmpty(githubToken))
160-
{
161-
throw new InvalidOperationException("Could not resolve AngleSharp GitHub token.");
162-
}
163-
164-
var github = new GitHubClient(new ProductHeaderValue("AngleSharpCakeBuild"))
165-
{
166-
Credentials = new Credentials(githubToken),
167-
};
168-
169-
var newRelease = github.Repository.Release;
170-
newRelease.Create("AngleSharp", "AngleSharp.Io", new NewRelease("v" + version)
171-
{
172-
Name = version,
173-
Body = String.Join(Environment.NewLine, releaseNotes.Notes),
174-
Prerelease = false,
175-
TargetCommitish = "master",
176-
}).Wait();
177-
});
178-
179-
Task("Update-AppVeyor-Build-Number")
180-
.WithCriteria(() => isRunningOnAppVeyor)
181-
.Does(() =>
182-
{
183-
var num = AppVeyor.Environment.Build.Number;
184-
AppVeyor.UpdateBuildVersion($"{version}-{num}");
185-
});
186-
187-
// Targets
188-
// ----------------------------------------
189-
190-
Task("Package")
191-
.IsDependentOn("Run-Unit-Tests")
192-
.IsDependentOn("Create-Package");
193-
194-
Task("Default")
195-
.IsDependentOn("Package");
196-
197-
Task("Publish")
198-
.IsDependentOn("Publish-Package")
199-
.IsDependentOn("Publish-Release");
200-
201-
Task("AppVeyor")
202-
.IsDependentOn("Run-Unit-Tests")
203-
.IsDependentOn("Update-AppVeyor-Build-Number");
6+
{ "netstandard2.0", "netstandard2.0" },
7+
};
2048

205-
// Execution
206-
// ----------------------------------------
9+
#load tools/anglesharp.cake
20710

208-
RunTarget(target);
11+
RunTarget(target);

0 commit comments

Comments
 (0)