Skip to content

Commit

Permalink
Add gulp master task (dotnet#1542)
Browse files Browse the repository at this point in the history
  • Loading branch information
qinezh authored Apr 18, 2017
1 parent c977589 commit 26b3303
Show file tree
Hide file tree
Showing 10 changed files with 654 additions and 130 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,9 @@ src/docfx/Template/*.zip
src/docfx.website.themes/default/styles/docfx.vendor.css
src/docfx.website.themes/default/styles/docfx.vendor.js
src/docfx.website.themes/default/fonts/

###############
# deploy #
###############
tools/Deployment/.vscode/
tools/Deployment/out/
25 changes: 22 additions & 3 deletions tools/Deployment/config_gulp.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
{
"docfx": {
"home": "../../../docfx/",
"home": "../../",
"repoUrl": "git@github.com-ci:dotnet/docfx.git",
"docfxSeedHome": "../../../docfx-seed/",
"e2eTestsHome": "../../test/docfx.E2E.Tests/",
"targetFolder": "../../target/",
"artifactsFolder": "../../artifacts/",
"exe": "../../target/Release/docfx/docfx.exe"
"exe": "../../target/Release/docfx/docfx.exe",
"releaseNotePath": "../../RELEASENOTE.md",
"releaseFolder": "../../target/Release/docfx",
"assetZipPath": "../../Documentation/_site/tutorial/artifacts/docfx.zip",
"siteFolder": "../../Documentation/_site"
},
"myget": {
"exe": "C:/nuget.exe",
Expand All @@ -15,5 +20,19 @@
},
"firefox": {
"version": "46.0.1"
},
"choco": {
"homeDir": "../../src/nuspec/chocolatey/docfx/",
"nuspec": "../../src/nuspec/chocolatey/docfx/docfx.nuspec",
"chocoScript": "../../src/nuspec/chocolatey/docfx/tools/chocolateyinstall.ps1"
},
"git": {
"name": "DocFX CI",
"email": "vscopbld@microsoft.com",
"message": "Update gh-pages"
},
"sync": {
"fromBranch": "dev",
"targetBranch": "stable"
}
}
}
244 changes: 117 additions & 127 deletions tools/Deployment/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ let del = require("del");
let glob = require("glob");
let gulp = require("gulp");
let nconf = require("nconf");
let spawn = require("child-process-promise").spawn;

let configFile = path.join(__dirname, "config_gulp.json");
let Common = require("./out/common").Common;
let Guard = require("./out/common").Guard;
let Myget = require("./out/myget").Myget;
let Github = require("./out/github").Github;
let Chocolatey = require("./out/chocolatey").Chocolatey;

let configFile = path.resolve("config_gulp.json");

if (!fs.existsSync(configFile)) {
throw new Error("Can't find config file");
}
Expand All @@ -22,70 +28,29 @@ nconf.add("configuration", { type: "file", file: configFile });
let config = {
"docfx": nconf.get("docfx"),
"firefox": nconf.get("firefox"),
"myget": nconf.get("myget")
"myget": nconf.get("myget"),
"git": nconf.get("git"),
"choco": nconf.get("choco")
};

if (!config.docfx) {
throw new Error("Can't find docfx configuration.");
}

if (!config.firefox) {
throw new Error("Can't find firefox configuration.");
}

if (!config.myget) {
throw new Error("Can't find myget configuration.");
}

config.myget["apiKey"] = process.env.MGAPIKEY;

function exec(command, args, workDir) {
let cwd = process.cwd();
if (workDir) {
process.chdir(path.join(__dirname, workDir));
}

let promise = spawn(command, args);
let childProcess = promise.childProcess;
childProcess.stdout.on("data", (data) => {
process.stdout.write(data.toString());
});
childProcess.stderr.on("data", (data) => {
process.stderr.write(data.toString());
})
return promise.then(() => {
process.chdir(cwd);
});
}

function publish(artifactsFolder, mygetCommand, mygetKey, mygetUrl) {
let packages = glob.sync(artifactsFolder + "/**/!(*.symbols).nupkg");
let promises = packages.map(p => {
return exec(mygetCommand, ["push", p, mygetKey, "-Source", mygetUrl]);
});
return Promise.all(promises);
}
Guard.argumentNotNull(config.docfx, "config.docfx", "Can't find docfx configuration.");
Guard.argumentNotNull(config.firefox, "config.docfx", "Can't find firefox configuration.");
Guard.argumentNotNull(config.myget, "config.docfx", "Can't find myget configuration.");
Guard.argumentNotNull(config.git, "config.docfx", "Can't find git configuration.");
Guard.argumentNotNull(config.choco, "config.docfx", "Can't find choco configuration.");

gulp.task("build", () => {
if (!config.docfx || !config.docfx["home"]) {
throw new Error("Can't find docfx home directory in configuration.");
}
Guard.argumentNotNullOrEmpty(config.docfx.home, "config.docfx.home", "Can't find docfx home directory in configuration.");

return exec("powershell", ["./build.ps1", "-prod"], config.docfx["home"]);
return Common.execAsync("powershell", ["./build.ps1", "-prod"], config.docfx.home);
});

gulp.task("clean", () => {
if (!config.docfx["artifactsFolder"]) {
throw new Error("Can't find docfx artifacts folder in configuration.");
}

let artifactsFolder = path.join(__dirname, config.docfx["artifactsFolder"]);
Guard.argumentNotNullOrEmpty(config.docfx.artifactsFolder, "config.docfx.artifactsFolder", "Can't find docfx artifacts folder in configuration.");
Guard.argumentNotNullOrEmpty(config.docfx.targetFolder, "config.docfx.targetFolder", "Can't find docfx target folder in configuration.");

if (!config.docfx["targetFolder"]) {
throw new Error("Can't find docfx target folder in configuration.");
}

let targetFolder = path.join(__dirname, config.docfx["targetFolder"]);
let artifactsFolder = path.resolve(config.docfx.artifactsFolder);
let targetFolder = path.resolve(config.docfx["targetFolder"]);

return del([artifactsFolder, targetFolder], { force: true }).then((paths) => {
if (!paths || paths.length === 0) {
Expand All @@ -97,108 +62,133 @@ gulp.task("clean", () => {
});

gulp.task("e2eTest:installFirefox", () => {
if (!config.firefox["version"]) {
throw new Error("Can't find firefox version in configuration.");
}
Guard.argumentNotNullOrEmpty(config.firefox.version, "config.firefox.version", "Can't find firefox version in configuration.");

return exec("choco", ["install", "firefox", "--version=" + config.firefox["version"], "-y"]);
return Common.execAsync("choco", ["install", "firefox", "--version=" + config.firefox.version, "-y"]);
});

gulp.task("e2eTest:buildSeed", () => {
if (!config.docfx["exe"]) {
throw new Error("Can't find docfx.exe in configuration.");
}

if (!config.docfx["docfxSeedHome"]) {
throw new Error("Can't find docfx-seed in configuration.");
}
Guard.argumentNotNullOrEmpty(config.docfx.exe, "config.docfx.exe", "Can't find docfx.exe in configuration.");
Guard.argumentNotNullOrEmpty(config.docfx.docfxSeedHome, "config.docfx.docfxSeedHome", "Can't find docfx-seed in configuration.");

return exec(path.join(__dirname, config.docfx["exe"]), ["docfx.json"], config.docfx["docfxSeedHome"]);
return Common.execAsync(path.resolve(config.docfx["exe"]), ["docfx.json"], config.docfx.docfxSeedHome);
});

gulp.task("e2eTest:restore", () => {
if (!config.docfx["e2eTestsHome"]) {
throw new Error("Can't find E2ETest directory in configuration.");
}
Guard.argumentNotNullOrEmpty(config.docfx.e2eTestsHome, "config.docfx.e2eTestsHome", "Can't find E2ETest directory in configuration.");

return exec("dotnet", ["restore"], config.docfx["e2eTestsHome"]);
return Common.execAsync("dotnet", ["restore"], config.docfx.e2eTestsHome);
});

gulp.task("e2eTest:test", () => {
if (!config.docfx["e2eTestsHome"]) {
throw new Error("Can't find E2ETest directory in configuration.");
}
Guard.argumentNotNullOrEmpty(config.docfx.e2eTestsHome, "config.docfx.e2eTestsHome", "Can't find E2ETest directory in configuration.");

return exec("dotnet", ["test"], config.docfx["e2eTestsHome"]);
return Common.execAsync("dotnet", ["test"], config.docfx.e2eTestsHome);
});

gulp.task("e2eTest", gulp.series("e2eTest:installFirefox", "e2eTest:buildSeed", "e2eTest:restore", "e2eTest:test"));

gulp.task("publish:myget-dev", () => {
if (!config.docfx["artifactsFolder"]) {
throw new Error("Can't find artifacts folder in configuration.");
}

if (!config.myget["exe"]) {
throw new Error("Can't find nuget command in configuration.");
}

if (!config.myget["apiKey"]) {
throw new Error("Can't find myget api key in configuration.");
}

if (!config.myget["devUrl"]) {
throw new Error("Can't find myget url for docfx dev feed in configuration.");
}

let artifactsFolder = path.join(__dirname, config.docfx["artifactsFolder"]);
return publish(artifactsFolder, config.myget["exe"], config.myget["apiKey"], config.myget["devUrl"]);
Guard.argumentNotNullOrEmpty(config.docfx.artifactsFolder, "config.docfx.artifactsFolder", "Can't find artifacts folder in configuration.");
Guard.argumentNotNullOrEmpty(config.myget.exe, "config.myget.exe", "Can't find nuget command in configuration.");
Guard.argumentNotNullOrEmpty(config.myget.apiKey, "config.myget.apiKey", "Can't find myget api key in configuration.");
Guard.argumentNotNullOrEmpty(config.myget.devUrl, "config.myget.devUrl", "Can't find myget url for docfx dev feed in configuration.");
Guard.argumentNotNullOrEmpty(process.env.MGAPIKEY, "process.env.MGAPIKEY", "Can't find myget key in Environment Variables.");

let mygetToken = process.env.MGAPIKEY;
let artifactsFolder = path.resolve(config.docfx["artifactsFolder"]);
return Myget.publishToMygetAsync(artifactsFolder, config.myget["exe"], mygetToken, config.myget["devUrl"]);
});

gulp.task("publish:myget-test", () => {
if (!config.docfx["artifactsFolder"]) {
throw new Error("Can't find artifacts folder in configuration.");
}

if (!config.myget["exe"]) {
throw new Error("Can't find nuget command in configuration.");
}

if (!config.myget["apiKey"]) {
throw new Error("Can't find myget api key in configuration.");
}
Guard.argumentNotNullOrEmpty(config.docfx.artifactsFolder, "config.docfx.artifactsFolder", "Can't find artifacts folder in configuration.");
Guard.argumentNotNullOrEmpty(config.myget.exe, "config.myget.exe", "Can't find nuget command in configuration.");
Guard.argumentNotNullOrEmpty(config.myget.apiKey, "config.myget.apiKey", "Can't find myget api key in configuration.");
Guard.argumentNotNullOrEmpty(config.myget.testUrl, "config.myget.testUrl", "Can't find myget url for docfx test feed in configuration.");
Guard.argumentNotNullOrEmpty(process.env.MGAPIKEY, "process.env.MGAPIKEY", "Can't find myget key in Environment Variables.");

let artifactsFolder = path.resolve(config.docfx["artifactsFolder"]);
return Myget.publishToMygetAsync(artifactsFolder, config.myget["exe"], mygetToken, config.myget["testUrl"]);
});

if (!config.myget["testUrl"]) {
throw new Error("Can't find myget url for docfx test feed in configuration.");
}
gulp.task("publish:myget-master", () => {
Guard.argumentNotNullOrEmpty(config.docfx.artifactsFolder, "config.docfx.artifactsFolder", "Can't find artifacts folder in configuration.");
Guard.argumentNotNullOrEmpty(config.myget.exe, "config.myget.exe", "Can't find nuget command in configuration.");
Guard.argumentNotNullOrEmpty(config.myget.apiKey, "config.myget.apiKey", "Can't find myget api key in configuration.");
Guard.argumentNotNullOrEmpty(config.myget.masterUrl, "config.myget.masterUrl", "Can't find myget url for docfx master feed in configuration.");
Guard.argumentNotNullOrEmpty(process.env.MGAPIKEY, "process.env.MGAPIKEY", "Can't find myget key in Environment Variables.");
Guard.argumentNotNullOrEmpty(config.docfx.releaseNotePath, "config.docfx.releaseNotePath", "Can't find RELEASENOTE.md in configuartion.");

let releaseNotePath = path.resolve(config.docfx["releaseNotePath"]);
let artifactsFolder = path.resolve(config.docfx["artifactsFolder"]);
return Myget.publishToMygetAsync(artifactsFolder, config.myget["exe"], mygetToken, config.myget["masterUrl"], releaseNotePath);
});

let artifactsFolder = path.join(__dirname, config.docfx["artifactsFolder"]);
return publish(artifactsFolder, config.myget["exe"], config.myget["apiKey"], config.myget["testUrl"]);
gulp.task("updateGhPage", () => {
Guard.argumentNotNullOrEmpty(config.docfx.repoUrl, "config.docfx.repoUrl", "Can't find docfx repo url in configuration.");
Guard.argumentNotNullOrEmpty(config.docfx.siteFolder, "config.docfx.siteFolder", "Can't find docfx site folder in configuration.");
Guard.argumentNotNullOrEmpty(config.git.name, "config.git.name", "Can't find git user name in configuration");
Guard.argumentNotNullOrEmpty(config.git.email, "config.git.email", "Can't find git user email in configuration");
Guard.argumentNotNullOrEmpty(config.git.message, "config.git.message", "Can't find git commit message in configuration");

let promise = Github.updateGhPagesAsync(config.docfx.repoUrl, config.docfx.siteFolder, config.git.name, config.git.email, config.git.message);
promise.then(() => {
console.log("Update github pages successfully.");
}).catch(err => {
console.log(`Failed to update github pages, ${err}`);
process.exit(1);
})
});

gulp.task("publish:myget-master", () => {
if (!config.docfx["artifactsFolder"]) {
throw new Error("Can't find artifacts folder in configuration.");
}
gulp.task("publish:gh-release", () => {
Guard.argumentNotNullOrEmpty(config.docfx.releaseNotePath, "config.docfx.releaseNotePath", "Can't find RELEASENOTE.md in configuartion.");
Guard.argumentNotNullOrEmpty(config.docfx.releaseFolder, "config.docfx.releaseFolder", "Can't find zip source folder in configuration.");
Guard.argumentNotNullOrEmpty(config.docfx.assetZipPath, "config.docfx.assetZipPath", "Can't find asset zip destination folder in configuration.");
Guard.argumentNotNullOrEmpty(process.env.TOKEN, "process.env.TOKEN", "No github account token in the environment.");

if (!config.myget["exe"]) {
throw new Error("Can't find nuget command in configuration.");
}
let githubToken = process.env.TOKEN;

if (!config.myget["apiKey"]) {
throw new Error("Can't find myget api key in configuration.");
}
let releaseNotePath = path.resolve(config.docfx["releaseNotePath"]);
let releaseFolder = path.resolve(config.docfx["releaseFolder"]);
let assetZipPath = path.resolve(config.docfx["assetZipPath"]);

if (!config.myget["masterUrl"]) {
throw new Error("Can't find myget url for docfx master feed in configuration.");
}
let promise = Github.updateGithubReleaseAsync(config.docfx["repoUrl"], releaseNotePath, releaseFolder, assetZipPath, githubToken);
promise.then(() => {
console.log("Update github release and assets successfully.");
}).catch(err => {
console.log(`Failed to update github release and assets, ${err}`);
process.exit(1);
});
});

let artifactsFolder = path.join(__dirname, config.docfx["artifactsFolder"]);
return publish(artifactsFolder, config.myget["exe"], config.myget["apiKey"], config.myget["masterUrl"]);
gulp.task("publish:chocolatey", () => {
Guard.argumentNotNullOrEmpty(config.choco.homeDir, "config.choco.homeDir", "Can't find homedir for chocolatey in configuration.");
Guard.argumentNotNullOrEmpty(config.choco.nuspec, "config.choco.nuspec", "Can't find nuspec for chocolatey in configuration.");
Guard.argumentNotNullOrEmpty(config.choco.chocoScript, "config.choco.chocoScript", "Can't find script for chocolatey in configuration.");
Guard.argumentNotNullOrEmpty(config.docfx.releaseNotePath, "config.docfx.releaseNotePath", "Can't find RELEASENOTE path in configuration.");
Guard.argumentNotNullOrEmpty(config.docfx.assetZipPath, "config.docfx.assetZipPath", "Can't find released zip path in configuration.");
Guard.argumentNotNullOrEmpty(process.env.CHOCO_TOKEN, "process.env.CHOCO_TOKEN", "No chocolatey.org account token in the environment.");

let chocoToken = process.env.CHOCO_TOKEN;

let releaseNotePath = path.resolve(config.docfx["releaseNotePath"]);
let assetZipPath = path.resolve(config.docfx["assetZipPath"]);

let chocoScript = path.resolve(config.choco["chocoScript"]);
let nuspec = path.resolve(config.choco["nuspec"]);
let homeDir = path.resolve(config.choco["homeDir"]);

let promise = Chocolatey.publishToChocolateyAsync(releaseNotePath, assetZipPath, chocoScript, nuspec, homeDir, chocoToken);
promise.then(() => {
console.log("Publish to chocolatey successfully.");
}).catch(err => {
console.log(`Failed to publish to chocolatey, ${err}`);
process.exit(1);
});
});

gulp.task("test", gulp.series("clean", "build", "e2eTest", "publish:myget-test"));
gulp.task("dev", gulp.series("clean", "build", "e2eTest"));
gulp.task("stable", gulp.series("clean", "build", "e2eTest", "publish:myget-dev"));

gulp.task("master", gulp.series("clean", "build", "e2eTest", "updateGhPage", "publish:gh-release", "publish:chocolatey", "publish:myget-master"));
gulp.task("default", gulp.series("dev"));
Loading

0 comments on commit 26b3303

Please sign in to comment.