Skip to content

Commit

Permalink
chore(scripts): deploy document by travis (eggjs#325)
Browse files Browse the repository at this point in the history
Use nodejs rewrite doc tools, and support auto publish gh-pages on travis.

Only run publishing when commit to master branch.

Closes eggjs#86
  • Loading branch information
popomore authored and fengmk2 committed Feb 7, 2017
1 parent 85e3c8f commit df4f04e
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 271 deletions.
6 changes: 4 additions & 2 deletions .autod.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ module.exports = {
exclude: [
'test/fixtures',
'examples',
'benchmarks',
"docs",
],
devdep: [
'autod',
'autod-egg',
'eslint',
'egg-plugin-puml'
'eslint-config-egg',
'egg-bin',
'egg-plugin-puml',
],
keep: [
],
semver: [
],
test: 'scripts',
};
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ script:
- npm run ci
after_script:
- npminstall codecov && codecov
- scripts/doc_travis.sh
env:
global:
- ENCRYPTION_LABEL: a62186272189
26 changes: 9 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"dependencies": {
"accepts": "^1.3.3",
"agentkeepalive": "^3.0.0",
"cluster-client": "^1.0.3",
"cluster-client": "^1.1.0",
"co": "^4.6.0",
"debug": "^2.6.0",
"delegates": "^1.0.0",
Expand Down Expand Up @@ -51,33 +51,27 @@
"devDependencies": {
"autod": "^2.7.1",
"autod-egg": "^1.0.0",
"beautify-benchmark": "^0.2.4",
"benchmark": "^2.1.0",
"coffee": "^3.3.0",
"cross-env": "^2.0.1",
"egg-alinode": "^1.0.3",
"egg-bin": "^1.3.0",
"egg-ci": "^1.0.3",
"egg-bin": "^2.0.2",
"egg-mock": "^2.3.1",
"egg-plugin-puml": "^1.0.0",
"egg-view-nunjucks": "^0.5.0",
"eslint": "^3.15.0",
"eslint-config-egg": "^3.1.0",
"estraverse": "^4.1.1",
"eslint-config-egg": "^3.2.0",
"formstream": "^1.1.0",
"gh-pages": "^0.12.0",
"glob": "^7.1.1",
"ko-sleep": "^1.0.2",
"merge-descriptors": "^1.0.1",
"mm": "^2.1.0",
"moment": "^2.17.1",
"mz": "^2.4.0",
"npminstall": "^2.1.1",
"mz": "^2.6.0",
"once": "^1.3.3",
"pedding": "^1.1.0",
"rds": "^0.1.0",
"rimraf": "^2.5.4",
"runscript": "^1.2.0",
"should": "^11.2.0",
"stream-wormhole": "^1.0.0",
"supertest": "^3.0.0"
},
"main": "index.js",
Expand All @@ -94,8 +88,9 @@
"test-local": "egg-bin test",
"cov": "egg-bin cov",
"ci": "npm run lint && npm run cov",
"doc-server": "./scripts/doc.sh server",
"doc-deploy": "./scripts/doc.sh deploy",
"doc-server": "./scripts/doc.js server",
"doc-build": "./scripts/doc.js build",
"doc-deploy": "./scripts/doc.js deploy",
"autod": "autod",
"puml": "puml . --dest ./docs",
"commits": "./scripts/commits.sh"
Expand All @@ -108,8 +103,5 @@
"engines": {
"node": ">=6.0.0"
},
"ci": {
"version": "6, 7"
},
"license": "MIT"
}
Binary file added scripts/deploy_key.enc
Binary file not shown.
77 changes: 77 additions & 0 deletions scripts/doc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env node

'use strict';

const fs = require('mz/fs');
const co = require('co');
const rimraf = require('rimraf');
const runscript = require('runscript');
const ghpages = require('gh-pages');

// The branch that pushing document
const BRANCH = 'gh-pages';
const DOC_PUBLISHER_NAME = 'Auto Doc Publisher';
const DOC_PUBLISHER_EMAIL = '[email protected]';
const command = process.argv[2];

co(function* () {
const exists = yield fs.exists('node_modules');
if (!exists) {
throw new Error('should run `npm install` first');
}

console.log('Copying CONTRIBUTING.md');
yield copyFile('CONTRIBUTING.md', 'docs/source/contributing.md');
yield copyFile('CONTRIBUTING.zh-CN.md', 'docs/source/zh-cn/contributing.md');

yield rm('docs/public');
yield runscript('npminstall', { cwd: 'docs' });

switch (command) {
case 'server':
yield runscript('hexo --cwd docs server -l');
break;
case 'build':
yield runscript('hexo --cwd docs generate --force');
break;
case 'deploy':
yield runscript('hexo --cwd docs generate --force');
yield deploy();
break;
default:
}
}).catch(err => {
console.error(err.stack);
process.exit(1);
});

function* deploy() {
console.log('Pushing to %s', BRANCH);
let repo = yield runscript('git config remote.origin.url', { stdio: 'pipe' });
repo = repo.stdout.toString().slice(0, -1);
if (/^http/.test(repo)) {
repo = repo.replace('https://github.com/', '[email protected]:');
}
yield publish('docs/public', {
logger(message) { console.log(message); },
user: {
name: DOC_PUBLISHER_NAME,
email: DOC_PUBLISHER_EMAIL,
},
branch: BRANCH,
repo,
});
}

function* copyFile(src, dist) {
const buf = yield fs.readFile(src);
yield fs.writeFile(dist, buf);
}

function rm(dir) {
return done => rimraf(dir, done);
}

function publish(basePath, options) {
return done => ghpages.publish(basePath, options, done);
}
49 changes: 0 additions & 49 deletions scripts/doc.sh

This file was deleted.

25 changes: 25 additions & 0 deletions scripts/doc_travis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#! /usr/bin/env bash

# https://gist.github.com/domenic/ec8b0fc8ab45f39403dd#sign-up-for-travis-and-add-your-project

# Only deply on master branch
SOURCE_BRANCH="master"

# Pull requests and commits to other branches shouldn't try to deploy, just build to verify
if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]; then
echo "Skip deploy, TRAVIS_PULL_REQUEST=$TRAVIS_PULL_REQUEST, TRAVIS_BRANCH=$TRAVIS_BRANCH"
exit 0
fi

# Get the deploy key by using Travis's stored variables to decrypt deploy_key.enc
ENCRYPTED_KEY_VAR="encrypted_${ENCRYPTION_LABEL}_key"
ENCRYPTED_IV_VAR="encrypted_${ENCRYPTION_LABEL}_iv"
ENCRYPTED_KEY=${!ENCRYPTED_KEY_VAR}
ENCRYPTED_IV=${!ENCRYPTED_IV_VAR}
# echo "key: $ENCRYPTED_KEY, iv: $ENCRYPTED_IV"
openssl aes-256-cbc -K $ENCRYPTED_KEY -iv $ENCRYPTED_IV -in scripts/deploy_key.enc -out deploy_key -d
chmod 600 deploy_key
eval `ssh-agent -s`
ssh-add deploy_key

npm run doc-deploy
Loading

0 comments on commit df4f04e

Please sign in to comment.