forked from FacilityApi/FacilityJavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.cake
More file actions
172 lines (148 loc) · 5.81 KB
/
build.cake
File metadata and controls
172 lines (148 loc) · 5.81 KB
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
#addin nuget:?package=Cake.Git&version=0.17.0
#addin nuget:?package=Cake.XmlDocMarkdown&version=1.4.0
using System.Text.RegularExpressions;
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var versionSuffix = Argument("versionSuffix", "");
var solutionFileName = "FacilityJavaScript.sln";
var docsAssemblies = new[] { "Facility.CodeGen.JavaScript" };
var docsAssemblyDirectory = $"src/fsdgenjs/bin/{configuration}";
var docsSourceUri = "https://github.com/FacilityApi/FacilityJavaScript/tree/master/src";
var codeGenExe = $"src/fsdgenjs/bin/{configuration}/fsdgenjs.exe";
var nugetSource = "https://api.nuget.org/v3/index.json";
var nugetApiKey = EnvironmentVariable("NUGET_API_KEY");
var docsRepoUri = "https://github.com/FacilityApi/FacilityApi.github.io.git";
var docsRepoBranch = "master";
var buildBotUserName = "FacilityApiBot";
var buildBotEmail = "facilityapi@gmail.com";
var buildBotPassword = EnvironmentVariable("BUILD_BOT_PASSWORD");
var trigger = EnvironmentVariable("APPVEYOR_REPO_TAG_NAME");;
var buildBranch = EnvironmentVariable("APPVEYOR_REPO_BRANCH");
void CodeGen(bool verify)
{
ExecuteCodeGen("example/ExampleApi.fsd example/js/ --indent 2 --express", verify);
ExecuteCodeGen("example/ExampleApi.fsd example/ts/src/ --typescript --express", verify);
}
Task("Clean")
.Does(() =>
{
CleanDirectories("src/**/bin");
CleanDirectories("src/**/obj");
CleanDirectories("tests/**/bin");
CleanDirectories("tests/**/obj");
CleanDirectories("release");
});
Task("Build")
.Does(() =>
{
DotNetCoreRestore(solutionFileName);
DotNetCoreBuild(solutionFileName, new DotNetCoreBuildSettings { Configuration = configuration, ArgumentCustomization = args => args.Append("--verbosity normal") });
});
Task("Rebuild")
.IsDependentOn("Clean")
.IsDependentOn("Build");
Task("CodeGen")
.IsDependentOn("Build")
.Does(() => CodeGen(verify: false));
Task("VerifyCodeGen")
.IsDependentOn("Build")
.Does(() => CodeGen(verify: true));
Task("Test")
.IsDependentOn("VerifyCodeGen")
.Does(() =>
{
foreach (var projectPath in GetFiles("tests/**/*.csproj").Select(x => x.FullPath))
DotNetCoreTest(projectPath, new DotNetCoreTestSettings { Configuration = configuration });
});
Task("Package")
.IsDependentOn("Rebuild")
.IsDependentOn("Test")
.Does(() =>
{
if (string.IsNullOrEmpty(versionSuffix) && !string.IsNullOrEmpty(trigger))
versionSuffix = Regex.Match(trigger, @"^nuget-v[^\.]+\.[^\.]+\.[^\.]+-(.+)").Groups[1].ToString();
foreach (var projectPath in GetFiles("src/**/*.csproj").Select(x => x.FullPath))
DotNetCorePack(projectPath, new DotNetCorePackSettings { Configuration = configuration, OutputDirectory = "release", VersionSuffix = versionSuffix });
});
Task("UpdateDocs")
.IsDependentOn("Build")
.Does(() =>
{
bool shouldCommit = !string.IsNullOrEmpty(buildBotPassword);
var docsDirectory = Directory($"release/{docsRepoBranch}");
if (shouldCommit)
GitClone(docsRepoUri, docsDirectory, new GitCloneSettings { BranchName = docsRepoBranch });
var outputPath = $"release/{docsRepoBranch}/reference";
var isPreview = buildBranch != "master" || trigger == null || !Regex.IsMatch(trigger, @"^(nuget-v[0-9]+\.[0-9]+\.[0-9]+|update-docs)$");
if (isPreview)
outputPath += $"/preview/{buildBranch}";
Information($"Updating documentation at {outputPath}.");
foreach (var docsAssembly in docsAssemblies)
{
XmlDocMarkdownGenerate($"{docsAssemblyDirectory}/{docsAssembly}.dll", $"{outputPath}/",
new XmlDocMarkdownSettings { SourceCodePath = $"{docsSourceUri}/{docsAssembly}", NewLine = "\n", ShouldClean = true });
}
if (!shouldCommit)
{
Information("Set BUILD_BOT_PASSWORD to publish documentation changes.");
}
else if (GitHasUncommitedChanges(docsDirectory))
{
Information("Committing all documentation changes.");
GitAddAll(docsDirectory);
GitCommit(docsDirectory, buildBotUserName, buildBotEmail,
"Automatic documentation update." + (isPreview ? $" (preview {buildBranch})" : ""));
Information("Pushing updated documentation to GitHub.");
GitPush(docsDirectory, buildBotUserName, buildBotPassword, docsRepoBranch);
}
else
{
Information("No documentation changes detected.");
}
});
Task("Publish")
.IsDependentOn("Package")
.IsDependentOn("UpdateDocs")
.Does(() =>
{
var nupkgPaths = GetFiles("release/*.nupkg").Select(x => x.FullPath).ToList();
string version = null;
foreach (var nupkgPath in nupkgPaths)
{
string nupkgVersion = Regex.Match(nupkgPath, @"\.([^\.]+\.[^\.]+\.[^\.]+)\.nupkg$").Groups[1].ToString();
if (version == null)
version = nupkgVersion;
else if (version != nupkgVersion)
throw new InvalidOperationException($"Mismatched package versions '{version}' and '{nupkgVersion}'.");
}
if (!string.IsNullOrEmpty(nugetApiKey) && trigger != null && Regex.IsMatch(trigger, "^nuget-v[0-9]"))
{
if (trigger != $"nuget-v{version}")
throw new InvalidOperationException($"Trigger '{trigger}' doesn't match package version '{version}'.");
var pushSettings = new NuGetPushSettings { ApiKey = nugetApiKey, Source = nugetSource };
foreach (var nupkgPath in nupkgPaths)
NuGetPush(nupkgPath, pushSettings);
}
else
{
Information("To publish NuGet packages, push this git tag: nuget-v" + version);
}
});
Task("Default")
.IsDependentOn("Test");
void ExecuteCodeGen(string args, bool verify)
{
Information(args);
string exePath = codeGenExe;
if (IsRunningOnUnix())
{
args = exePath + " " + args;
exePath = "mono";
}
int exitCode = StartProcess(exePath, args + " --newline lf" + (verify ? " --verify" : ""));
if (exitCode == 1 && verify)
throw new InvalidOperationException("Generated code doesn't match; use --target=CodeGen to regenerate.");
else if (exitCode != 0)
throw new InvalidOperationException($"Code generation failed with exit code {exitCode}.");
}
RunTarget(target);