-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.cake
135 lines (108 loc) · 3.87 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
#tool "nuget:https://api.nuget.org/v3/index.json?package=KuduSync.NET&version=1.4.0"
#tool "nuget:https://api.nuget.org/v3/index.json?package=Wyam&version=1.4.1"
#addin "nuget:https://api.nuget.org/v3/index.json?package=Cake.Wyam&version=1.4.1"
#addin "nuget:https://api.nuget.org/v3/index.json?package=Cake.Git&version=0.18.0"
#addin "nuget:https://api.nuget.org/v3/index.json?package=Cake.Kudu&version=0.8.0"
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
// Define variables
var isRunningOnAppVeyor = AppVeyor.IsRunningOnAppVeyor;
var isPullRequest = AppVeyor.Environment.PullRequest.IsPullRequest;
var accessToken = EnvironmentVariable("git_access_token");
var deployRemote = EnvironmentVariable("git_deploy_remote");
var currentBranch = isRunningOnAppVeyor ? BuildSystem.AppVeyor.Environment.Repository.Branch : GitBranchCurrent("./").FriendlyName;
var deployBranch = "master";
// Define directories.
var releaseDir = Directory("./release");
var outputPath = MakeAbsolute(Directory("./output"));
var rootPublishFolder = MakeAbsolute(Directory("publish"));
//////////////////////////////////////////////////////////////////////
// SETUP
//////////////////////////////////////////////////////////////////////
Setup(ctx =>
{
// Executed BEFORE the first task.
Information("Building branch {0} ({1})...", currentBranch, deployBranch);
});
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
EnsureDirectoryExists(releaseDir);
});
Task("Build")
.IsDependentOn("Clean")
.Does(() =>
{
Wyam(new WyamSettings
{
Recipe = "Docs",
Theme = "Samson",
UpdatePackages = true
});
});
Task("Preview")
.Does(() =>
{
Wyam(new WyamSettings
{
Recipe = "Docs",
Theme = "Samson",
UpdatePackages = true,
Preview = true
});
});
Task("Copy-Repo-Files")
.IsDependentOn("Build")
.Does(() =>
{
CopyFiles(
new FilePath[] {
//"CNAME", add when domain in place
"LICENSE",
"README.md",
"appveyor.yml"
},
"./output"
);
});
Task("Deploy")
.WithCriteria(isRunningOnAppVeyor)
.WithCriteria(!isPullRequest)
.WithCriteria(!string.IsNullOrEmpty(accessToken))
.WithCriteria(currentBranch == "develop")
.WithCriteria(!string.IsNullOrEmpty(deployRemote))
.WithCriteria(!string.IsNullOrEmpty(deployBranch))
.IsDependentOn("Copy-Repo-Files")
.Does(() =>
{
EnsureDirectoryExists(rootPublishFolder);
var sourceCommit = GitLogTip("./");
var publishFolder = rootPublishFolder.Combine(DateTime.Now.ToString("yyyyMMdd_HHmmss"));
Information("Getting publish branch {0}...", deployBranch);
GitClone(deployRemote, publishFolder, new GitCloneSettings{ BranchName = deployBranch });
Information("Sync output files...");
Kudu.Sync(outputPath, publishFolder, new KuduSyncSettings {
PathsToIgnore = new []{ ".git", ".gitignore" }
});
Information("Stage all changes...");
GitAddAll(publishFolder);
Information("Commit all changes...");
GitCommit(
publishFolder,
sourceCommit.Committer.Name,
sourceCommit.Committer.Email,
string.Format("AppVeyor Publish: {0}\r\n{1}", sourceCommit.Sha, sourceCommit.Message)
);
Information("Pushing all changes...");
GitPush(publishFolder, accessToken, "x-oauth-basic", deployBranch);
});
Task("Default")
.IsDependentOn("Build");
Task("AppVeyor")
.IsDependentOn("Deploy");
RunTarget(target);