select hexo config based on branch, disallow indexing for develop

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2019-06-19 08:58:26 -04:00
parent a0be63357f
commit 0aca6c36d4
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
6 changed files with 53 additions and 15 deletions

11
Jenkinsfile vendored
View File

@ -30,8 +30,15 @@ pipeline {
} }
} }
stage('Robot') {
when { expression { !GIT_BRANCH.endsWith('master') } }
steps { script {
sh 'echo "Disallow: /" >> public/robots.txt'
} }
}
stage('Publish Prod') { stage('Publish Prod') {
when { expression { env.GIT_BRANCH ==~ /.*master/ } } when { expression { GIT_BRANCH.endsWith('master') } }
steps { script { steps { script {
sshagent(credentials: ['status-im-auto-ssh']) { sshagent(credentials: ['status-im-auto-ssh']) {
sh 'npm run deploy' sh 'npm run deploy'
@ -40,7 +47,7 @@ pipeline {
} }
stage('Publish Devel') { stage('Publish Devel') {
when { expression { env.GIT_BRANCH ==~ /.*develop/ } } when { expression { !GIT_BRANCH.endsWith('master') } }
steps { script { steps { script {
sshagent(credentials: ['jenkins-ssh']) { sshagent(credentials: ['jenkins-ssh']) {
sh ''' sh '''

View File

@ -30,4 +30,4 @@ highlight:
disqus_shortname: hexojs disqus_shortname: hexojs
twitter: ethstatus twitter: ethstatus
github: staus-im github: status-im

View File

@ -30,4 +30,4 @@ highlight:
disqus_shortname: hexojs disqus_shortname: hexojs
twitter: ethstatus twitter: ethstatus
github: staus-im github: status-im

View File

@ -14,14 +14,23 @@ var minify = require('gulp-minify');
let cleanCSS = require('gulp-clean-css'); let cleanCSS = require('gulp-clean-css');
var rename = require("gulp-rename"); var rename = require("gulp-rename");
const gitBranch = require('./scripts/git-branch');
// generate html with 'hexo generate' // generate html with 'hexo generate'
var hexo = new Hexo(process.cwd(), {}); var hexo = new Hexo(process.cwd(), {});
const getEnv = function () {
return gitBranch() == 'master' ? 'prod' : 'dev'
}
gulp.task('generate', function(cb) { gulp.task('generate', function(cb) {
hexo.init().then(function() { var hexo = new Hexo(process.cwd(), {
return hexo.call('generate', { config: `_config.${getEnv()}.yml`,
watch: false watch: false,
}); });
hexo.init().then(function() {
return hexo.call('generate');
}).then(function() { }).then(function() {
return hexo.exit(); return hexo.exit();
}).then(function() { }).then(function() {

View File

@ -7,10 +7,9 @@
}, },
"scripts": { "scripts": {
"clean": "rm -rf public/*", "clean": "rm -rf public/*",
"build": "gulp run && hexo generate", "build": "gulp run",
"eslint": "eslint .", "eslint": "eslint .",
"deploy": "hexo deploy", "deploy": "hexo deploy"
"update-submodules": "git submodule update --recursive --remote"
}, },
"dependencies": { "dependencies": {
"cheerio": "^0.20.0", "cheerio": "^0.20.0",

23
scripts/git-branch.js Normal file
View File

@ -0,0 +1,23 @@
'use strict'
const fs = require('fs')
const path = require('path')
const util = require('util')
function parseBranch(buf) {
const match = /ref: refs\/heads\/([^\n]+)/.exec(buf.toString())
return match ? match[1] : null
}
function gitHeadPath(cwd) {
const filepath = path.join(process.cwd(), '.git/HEAD')
if (!fs.existsSync(filepath)) {
throw new Error('.git/HEAD does not exist')
}
return filepath
}
const gitBranch = function() {
return parseBranch(fs.readFileSync(gitHeadPath()))
}
module.exports = gitBranch