-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbuild.cake
177 lines (158 loc) · 6.5 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
174
175
176
177
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var configuration = Argument("configuration", "Release");
Information("Configuration is "+configuration);
var target = Argument("target", "Default");
Information("Target is "+target);
//////////////////////////////////////////////////////////////////////
// PREPARATION
//////////////////////////////////////////////////////////////////////
var workingPathName = "."; //EnvironmentVariable("BUILD_REPOSITORY_LOCALPATH") ?? ".";
var workingDir = MakeAbsolute(new DirectoryPath( workingPathName ));
var releaseNotes = ParseReleaseNotes( workingDir + "/ReleaseNotes.md");
var version = releaseNotes.Version.ToString(); //string.Format("{0}.{1}.{2}", releaseNotes.Version.Major, releaseNotes.Version.Minor, releaseNotes.Version.Patch);
Information("Version is "+version);
var srcDir = new DirectoryPath( workingDir.ToString() + "/src" );
var binDir = new DirectoryPath( workingDir.CombineWithFilePath("bin").FullPath );
var buildDir = new DirectoryPath( binDir.CombineWithFilePath("build").FullPath );
var buildPath = buildDir.FullPath;
var deployDir = new DirectoryPath( binDir.CombineWithFilePath("deploy").FullPath );
//var testDir = new DirectoryPath( binDir.CombineWithFilePath("test").FullPath );
//var testPath = testDir.FullPath;
//var reportDir = new DirectoryPath( binDir.CombineWithFilePath("report").FullPath );
//////////////////////////////////////////////////////////////////////
// PROPERTIES
//////////////////////////////////////////////////////////////////////
//var platform = new CakePlatform();
//public bool IsWindows { get { return platform.Family==PlatformFamily.Windows; } }
public bool IsLocalBuild { get { return BuildSystem.IsLocalBuild; } }
public bool IsDevelop { get { return BranchName.ToLower()=="develop"; } }
public bool IsMaster { get { return BranchName.ToLower()=="master"; } }
public string BranchName { get { return EnvironmentVariable("APPVEYOR_REPO_BRANCH"); } } // TFBuild.Environment.Repository.Branch; } }
public string CurrentVersion() {
var isAppVeyorBuild = AppVeyor.IsRunningOnAppVeyor;
if (isAppVeyorBuild) {
var buildno = EnvironmentVariable("APPVEYOR_BUILD_NUMBER") ?? "0";
var result = version + string.Format(".{0}", buildno);
//AppVeyor.UpdateBuildVersion(result);
return result;
}
return version + ".0";
}
var prologSolution = "src/Prolog.sln";
var prologProject = "src/Prolog/Prolog.csproj";
var coreAppsSolution = "src/Prolog.Core.Apps.sln";
var wpfAppsSolution = "src/Prolog.Wpf.Apps.sln";
ProcessArgumentBuilder CreateNugetArguments(ProcessArgumentBuilder args) {
var relNotes = string.Join("\n", releaseNotes.Notes)
.Replace(",", " and");
// .Replace(",", "[MSBuild]::Escape(',')");
Information("Release notes: \n"+relNotes);
return args
.Append("/p:Version="+version)
.Append("/p:PackageReleaseNotes=\""+relNotes+"\"");
}
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
if( !IsLocalBuild || !DirectoryExists(buildDir) || !DirectoryExists(deployDir) /*|| !DirectoryExists(testDir) || !DirectoryExists(reportDir)*/ )
{
CleanDirectory(buildDir);
CleanDirectory(deployDir);
//CleanDirectory(testDir);
//CleanDirectory(reportDir);
}
});
Task("VersionInfo")
.Does( () => {
var file = "src/VersionInfo.cs";
CreateAssemblyInfo(file, new AssemblyInfoSettings {
Product = "Prolog.NET",
Version = version,
FileVersion = version,
InformationalVersion = CurrentVersion(),
Trademark = "MS Public License",
Copyright = string.Format("Copyright (c) Richard G. Todd 2010 - {0}", DateTime.Now.Year)
});
});
Task("Restore-NuGet-Packages")
.Does( () => {
var settings = new DotNetRestoreSettings {
ArgumentCustomization = args => CreateNugetArguments(args),
};
DotNetRestore(wpfAppsSolution, settings);
DotNetRestore(coreAppsSolution, settings);
});
Task("Build")
.Does( () => {
var platform = new CakePlatform();
// var framework = IsWindows ? "net461" : "netcoreapp2.2";
var coreSettings = new DotNetBuildSettings
{
ArgumentCustomization = args => CreateNugetArguments(args),
//Framework = "netcoreapp2.0",
Configuration = configuration,
//OutputDirectory = buildPath,
NoRestore = true,
};
// if (!IsWindows) coreSettings.Framework = framework;
DotNetBuild(prologSolution, coreSettings);
var corePath = buildPath + "/core";
var corePublish = new DotNetBuildSettings
{
// Framework = framework,
//NoBuild = true,
NoRestore = true,
Configuration = configuration,
OutputDirectory = corePath
};
DotNetBuild(coreAppsSolution, corePublish);
/* Does not build if (IsWindows) {
var wpfPath = buildPath + "/wpf";
var wpfAppsSettings = new MSBuildSettings()
.WithProperty("OutputPath", wpfPath)
.WithProperty("Configuration", configuration);
MSBuild(wpfAppsSolution, wpfAppsSettings);
} */
});
Task("CreatePackages")
// .WithCriteria( IsWindows )
.Does( () => {
var settings = new DotNetPackSettings
{
ArgumentCustomization = args => CreateNugetArguments(args),
Configuration = configuration,
OutputDirectory = deployDir,
IncludeSymbols = true,
NoRestore = true,
NoBuild = true,
};
DotNetPack(prologProject, settings);
});
Task("PublishPackages")
.WithCriteria( !IsLocalBuild )
.Does( () => {
var apikey = EnvironmentVariable("NUGET_APIKEY");
var packages = GetFiles(deployDir+"/*.nupkg");
NuGetPush(packages, new NuGetPushSettings {
Source = "https://nuget.org",
ApiKey = apikey
});
});
//////////////////////////////////////////////////////////////////////
// TARGETS
//////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("Clean")
.IsDependentOn("VersionInfo")
.IsDependentOn("Restore-NuGet-Packages")
.IsDependentOn("Build")
.IsDependentOn("CreatePackages")
.IsDependentOn("PublishPackages");
Task("Deploy")
.IsDependentOn("PublishPackages");
RunTarget(target);