8000 Update build script and add appveyor.yml · XerProjects/Xer.Cqrs.EventStack@709ab04 · GitHub
[go: up one dir, main page]

Skip to content

Commit 709ab04

Browse files
committed
Update build script and add appveyor.yml
1 parent 4760456 commit 709ab04

File tree

2 files changed

+64
-147
lines changed

2 files changed

+64
-147
lines changed

appveyor.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
version: '{build}'
2+
pull_requests:
3+
do_not_increment_build_number: true
4+
image: Visual Studio 2017
5+
nuget:
6+
disable_publish_on_pr: true
7+
build_script:
8+
- ps: .\build.ps1
9+
test: off
10+
artifacts:
11+
- path: .\BuildArtifacts\*.nupkg
12+
name: NuGet
13+
skip_commits:
14+
message: /^\[nobuild\](.*)?/ # Skip build if commit message starts with [nobuild]
15+
deploy:
16+
- provider: NuGet
17+
server: https://www.myget.org/F/xerprojects-ci/api/v2/package
18+
api_key:
19+
secure: u04sQwcw2Dg6ymwifBf1PoYRwo6HrQOsEagB7IQYvwRPt+10tyFcrbuKq7Az34Oz
20+
skip_symbols: true
21+
on:
22+
branch: /(^dev$|^master$|^release[-/](.*)|^hotfix[-/](.*))/ # Branches: dev, master, release-*, release/*, hotfix-*, hotfix/*
23+
- provider: NuGet
24+
name: production
25+
skip_symbols: true
26+
api_key:
27+
secure: 1fEVy/0Jgny/LKUOQC75fofhRjEfpAaVV0Y8u3nH+oKdmrPFFFEF1swA+iS0W0rV
28+
on:
29+
branch: master
30+
appveyor_repo_tag: true # Only deploy to NuGet if a tag is found.

build.cake

Lines changed: 34 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -17,43 +17,31 @@ var configuration = Argument<string>("configuration", "Release");
1717

1818
var solutions = GetFiles("./**/*.sln");
1919
var projects = GetFiles("./**/*.csproj").Select(x => x.GetDirectory());
20-
string buildArtifactsDirectory = "./BuildArtifacts";
21-
22-
GitVersion gitVersion;
20+
BuildParameters buildParameters;
2321

2422
///////////////////////////////////////////////////////////////////////////////
2523
// SETUP / TEARDOWN
2624
///////////////////////////////////////////////////////////////////////////////
2725

2826
Setup(context =>
2927
{
30-
gitVersion = GitVersion(new GitVersionSettings {
31-
UpdateAssemblyInfo = true
32-
});
33-
34-
BuildParameters.Initialize(Context);
35-
28+
buildParameters = new BuildParameters(Context);
29+
3630
// Executed BEFORE the first task.
3731
Information("Xer.Cqrs.EventStack");
38-
Information("Parameters");
39-
Information("///////////////////////////////////////////////////////////////////////////////");
40-
Information("Branch: {0}", BuildParameters.Instance.BranchName);
41-
Information("Version semver: {0}", gitVersion.LegacySemVerPadded);
42-
Information("Version assembly: {0}", gitVersion.MajorMinorPatch);
43-
Information("Version informational: {0}", gitVersion.InformationalVersion);
44-
Information("Master branch: {0}", BuildParameters.Instance.IsMasterBranch);
45-
Information("Dev branch: {0}", BuildParameters.Instance.IsDevBranch);
46-
Information("Hotfix branch: {0}", BuildParameters.Instance.IsHotFixBranch);
47-
Information("Publish to myget: {0}", BuildParameters.Instance.ShouldPublishMyGet);
48-
Information("Publish to nuget: {0}", BuildParameters.Instance.ShouldPublishNuGet);
49-
Information("///////////////////////////////////////////////////////////////////////////////");
50-
51-
if (DirectoryExists(buildArtifactsDirectory))
32+
Information("===========================================================================================");
33+
Information("Git Version");
34+
Information("Semver: {0}", buildParameters.GitVersion.LegacySemVerPadded);
35+
Information("Major minor patch: {0}", buildParameters.GitVersion.MajorMinorPatch);
36+
Information("Assembly: {0}", buildParameters.GitVersion.AssemblySemVer);
37+
Information("Informational: {0}", buildParameters.GitVersion.InformationalVersion);
38+
if (DirectoryExists(buildParameters.BuildArtifactsDirectory))
5239
{
5340
// Cleanup build artifacts.
54-
Information($"Cleaning up {buildArtifactsDirectory} directory.");
55-
DeleteDirectory(buildArtifactsDirectory, new DeleteDirectorySettings { Recursive = true });
41+
Information($"Cleaning up {buildParameters.BuildArtifactsDirectory} directory.");
42+
DeleteDirectory(buildParameters.BuildArtifactsDirectory, new DeleteDirectorySettings { Recursive = true });
5643
}
44+
Information("===========================================================================================");
5745
});
5846

5947
Teardown(context =>
@@ -96,11 +84,7 @@ Task("Restore")
9684

9785
var settings = new DotNetCoreRestoreSettings
9886
{
99-
ArgumentCustomization = args => args
100-
.Append("/p:Version={0}", gitVersion.LegacySemVerPadded)
101-
.Append("/p:AssemblyVersion={0}", gitVersion.MajorMinorPatch)
102-
.Append("/p:FileVersion={0}", gitVersion.MajorMinorPatch)
103-
.Append("/p:AssemblyInformationalVersion={0}", gitVersion.InformationalVersion)
87+
ArgumentCustomization = args => buildParameters.AppendVersionArguments(args)
10488
};
10589

10690
// Restore all NuGet packages.
@@ -127,11 +111,7 @@ Task("Build")
127111
var settings = new DotNetCoreBuildSettings
128112
{
129113
Configuration = configuration,
130-
ArgumentCustomization = args => args
131-
.Append("/p:Version={0}", gitVersion.LegacySemVerPadded)
132-
.Append("/p:AssemblyVersion={0}", gitVersion.MajorMinorPatch)
133-
.Append("/p:FileVersion={0}", gitVersion.MajorMinorPatch)
134-
.Append("/p:AssemblyInformationalVersion={0}", gitVersion.InformationalVersion)
114+
ArgumentCustomization = args => buildParameters.AppendVersionArguments(args)
135115
};
136116

137117
// Build all solutions.
@@ -169,6 +149,7 @@ Task("Test")
169149
});
170150

171151
Task("Pack")
152+
.Description("Create NuGet packages.")
172153
.IsDependentOn("Test")
173154
.Does(() =>
174155
{
@@ -182,14 +163,10 @@ Task("Pack")
182163

183164
var settings = new DotNetCorePackSettings
184165
{
185-
OutputDirectory = buildArtifactsDirectory,
166+
OutputDirectory = buildParameters.BuildArtifactsDirectory,
186167
Configuration = configuration,
187168
NoBuild = true,
188-
ArgumentCustomization = (args) => args
189-
.Append("/p:Version={0}", gitVersion.LegacySemVerPadded)
190-
.Append("/p:AssemblyVersion={0}", gitVersion.MajorMinorPatch)
191-
.Append("/p:FileVersion={0}", gitVersion.MajorMinorPatch)
192-
.Append("/p:AssemblyInformationalVersion={0}", gitVersion.InformationalVersion)
169+
ArgumentCustomization = args => buildParameters.AppendVersionArguments(args)
193170
};
194171

195172
foreach (var project in projects)
@@ -198,66 +175,17 @@ Task("Pack")
198175
}
199176
});
200177

201-
Task("PublishMyGet")
202-
.WithCriteria(() => BuildParameters.Instance.ShouldPublishMyGet)
203-
.IsDependentOn("Pack")
204-
.Does(() =>
205-
{
206-
// Nupkgs in BuildArtifacts folder.
207-
var nupkgs = GetFiles(buildArtifactsDirectory + "/*.nupkg");
208-
209-
if (nupkgs.Count() == 0)
210-
{
211-
Information("No nupkgs found.");
212-
return;
213-
}
214-
215-
foreach (var nupkgFile in nupkgs)
216-
{
217-
Information("Pulishing to myget {0}", nupkgFile);
218-
219-
NuGetPush(nupkgFile, new NuGetPushSettings
220-
{
221-
Source = BuildParameters.Instance.MyGetFeed,
222-
ApiKey = BuildParameters.Instance.MyGetApiKey
223-
});
224-
}
225-
});
226-
227-
Task("PublishNuGet")
228-
.WithCriteria(() => BuildParameters.Instance.ShouldPublishNuGet)
229-
.IsDependentOn("Pack")
230-
.Does(() =>
231-
{
232-
// Nupkgs in BuildArtifacts folder.
233-
var nupkgs = GetFiles(buildArtifactsDirectory + "/*.nupkg");
234-
235-
if (nupkgs.Count() == 0)
236-
{
237-
Information("No nupkgs found.");
238-
return;
239-
}
240-
241-
foreach (var nupkgFile in nupkgs)
242-
{
243-
Information("Pulishing to nuget {0}", nupkgFile);
244-
NuGetPush(nupkgFile, new NuGetPushSettings
245-
{
246-
Source = BuildParameters.Instance.NuGetFeed,
247-
ApiKey = BuildParameters.Instance.NuGetApiKey
248-
});
249-
}
250-
});
251-
252-
253178
///////////////////////////////////////////////////////////////////////////////
254179
// TARGETS
255180
///////////////////////////////////////////////////////////////////////////////
256181

257182
Task("Default")
258183
.Description("This is the default task which will be ran if no specific target is passed in.")
259-
.IsDependentOn("PublishNuGet")
260-
.IsDependentOn("PublishMyGet");
184+
.IsDependentOn("Pack")
185+
.IsDependentOn("Test")
186+
.IsDependentOn("Build")
187+
.IsDependentOn("Restore")
188+
.IsDependentOn("Clean");
261189

262190
///////////////////////////////////////////////////////////////////////////////
263191
// EXECUTION
@@ -266,64 +194,23 @@ Task("Default")
266194
RunTarget(target);
267195

268196
public class BuildParameters
269-
{
270-
private static BuildParameters _buildParameters;
271-
272-
public static BuildParameters Instance => _buildParameters;
273-
197+
{
274198
private ICakeContext _context;
199+
private GitVersion _gitVersion;
275200

276-
private BuildParameters(ICakeContext context)
201+
public BuildParameters(ICakeContext context)
277202
{
278203
_context = context;
204+
_gitVersion = context.GitVersion();
279205
}
280206

281-
public static void Initialize(ICakeContext context)
282-
{
283-
if(_buildParameters != null)
284-
{
285-
return;
286-
}
287-
288-
_buildParameters = new BuildParameters(context);
289-
}
290-
291-
public bool IsAppVeyorBuild => _context.BuildSystem().AppVeyor.IsRunningOnAppVeyor;
292-
293-
public bool IsLocalBuild => _context.BuildSystem().IsLocalBuild;
294-
295-
public bool IsPullRequest => _context.BuildSystem().AppVeyor.Environment.PullRequest.IsPullRequest;
296-
297-
public string BranchName
298-
{
299-
get
300-
{
301-
return IsLocalBuild
302-
? _context.GitBranchCurrent(".").FriendlyName
303-
: _context.BuildSystem().AppVeyor.Environment.Repository.Branch;
304-
}
305-
}
306-
307-
public string MyGetFeed => _context.EnvironmentVariable("MYGET_SOURCE");
308-
309-
public string MyGetApiKey => _context.EnvironmentVariable("MYGET_API_KEY");
310-
311-
public string NuGetFeed => _context.EnvironmentVariable("NUGET_SOURCE");
312-
313-
public string NuGetApiKey => _context.EnvironmentVariable("NUGET_API_KEY");
314-
315-
public bool IsMasterBranch => StringComparer.OrdinalIgnoreCase.Equals("master", BranchName);
316-
317-
public bool IsDevBranch => StringComparer.OrdinalIgnoreCase.Equals("dev", BranchName);
318-
319-
public bool IsReleaseBranch => A0A8 BranchName.StartsWith("release", StringComparison.OrdinalIgnoreCase);
320-
321-
public bool IsHotFixBranch => BranchName.StartsWith("hotfix", StringComparison.OrdinalIgnoreCase);
207+
public GitVersion GitVersion => _gitVersion;
322208

323-
public bool ShouldPublishMyGet => !string.IsNullOrWhiteSpace(MyGetApiKey) && !string.IsNullOrWhiteSpace(MyGetFeed);
209+
public string BuildArtifactsDirectory => "./BuildArtifacts";
324210

325-
public bool ShouldPublishNuGet => !string.IsNullOrWhiteSpace(NuGetApiKey)
326-
&& !string.IsNullOrWhiteSpace(NuGetFeed)
327-
&& (IsMasterBranch || IsHotFixBranch)
328-
&& !IsPullRequest;
211+
public ProcessArgumentBuilder AppendVersionArguments(ProcessArgumentBuilder args) => args
212+
.Append("/p:Version={0}", GitVersion.LegacySemVerPadded)
213+
.Append("/p:AssemblyVersion={0}", GitVersion.MajorMinorPatch)
214+
.Append("/p:FileVersion={0}", GitVersion.MajorMinorPatch)
215+
.Append("/p:AssemblyInformationalVersion={0}", GitVersion.InformationalVersion);
329216
}

0 commit comments

Comments
 (0)
0