mirror of
https://github.com/cypress-io/cypress.git
synced 2026-02-20 22:21:23 -06:00
docs: added doc scraping to deploy process
- explain how to add circle ci credentials - spin up circle instance to scrape the docs - messaging + error handling
This commit is contained in:
@@ -10,6 +10,7 @@ const Promise = require('bluebird')
|
||||
const inquirer = require('inquirer')
|
||||
const awspublish = require('gulp-awspublish')
|
||||
const parallelize = require('concurrent-transform')
|
||||
const scrape = require('./scrape')
|
||||
|
||||
const distDir = path.resolve('public')
|
||||
|
||||
@@ -126,7 +127,7 @@ function commitMessage (env, branch) {
|
||||
|
||||
console.log(
|
||||
'\n',
|
||||
'Commiting and pushing to remote origin:',
|
||||
'Committing and pushing to remote origin:',
|
||||
'\n',
|
||||
chalk.green(`(${branch})`),
|
||||
chalk.cyan(msg)
|
||||
@@ -142,6 +143,26 @@ function commitMessage (env, branch) {
|
||||
})
|
||||
}
|
||||
|
||||
function scrapeDocs (env, branch) {
|
||||
console.log('')
|
||||
|
||||
// if we aren't on master do nothing
|
||||
if (branch !== 'master') {
|
||||
console.log('Skipping doc scraping because you are not on branch:', chalk.cyan('master'))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// if we arent deploying to production return
|
||||
if (env !== 'production') {
|
||||
console.log('Skipping doc scraping because you deployed to:', chalk.cyan('production'))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
return scrape()
|
||||
}
|
||||
|
||||
getS3Credentials()
|
||||
.then(getCurrentBranch)
|
||||
.then((branch) => {
|
||||
@@ -169,6 +190,9 @@ getS3Credentials()
|
||||
.then(() => {
|
||||
return commitMessage(env, branch)
|
||||
})
|
||||
.then(() => {
|
||||
return scrapeDocs(env, branch)
|
||||
})
|
||||
})
|
||||
})
|
||||
.then(() => {
|
||||
|
||||
61
docs/cy_scripts/scrape.js
Normal file
61
docs/cy_scripts/scrape.js
Normal file
@@ -0,0 +1,61 @@
|
||||
/* eslint-disable no-console */
|
||||
|
||||
const path = require('path')
|
||||
const chalk = require('chalk')
|
||||
const request = require('request-promise')
|
||||
const Promise = require('bluebird')
|
||||
|
||||
const fs = Promise.promisifyAll(require('fs-extra'))
|
||||
|
||||
function getCircleCredentials () {
|
||||
const pathToCircleCreds = path.resolve('support', '.circle-credentials.json')
|
||||
|
||||
const example = JSON.stringify({
|
||||
token: 'foobarbaz',
|
||||
}, null, 2)
|
||||
|
||||
return fs.readJsonAsync(pathToCircleCreds)
|
||||
.catch({ code: "ENOENT" }, () => {
|
||||
return {}
|
||||
})
|
||||
.then((json) => {
|
||||
const token = json.token
|
||||
|
||||
if (!token) {
|
||||
console.log(chalk.red(`Cannot scrape docs.\n\nYou are missing your Circle CI token.\n\nPlease add your token here: ${pathToCircleCreds}\n\nIt should look like this:\n\n${example}\n`))
|
||||
}
|
||||
|
||||
return token
|
||||
})
|
||||
}
|
||||
|
||||
function scrape () {
|
||||
return getCircleCredentials()
|
||||
.then((token) => {
|
||||
// bail if we dont have a token
|
||||
if (!token) {
|
||||
console.log('After fixing this problem you can run scraping by itself with this command:', chalk.yellow('npm run scrape'), '\n')
|
||||
return
|
||||
}
|
||||
|
||||
return request({
|
||||
url: 'https://circleci.com/api/v1.1/project/github/cypress-io/cypress-docsearch-scraper/',
|
||||
method: 'POST',
|
||||
json: true,
|
||||
auth: {
|
||||
user: token,
|
||||
},
|
||||
})
|
||||
.then((body) => {
|
||||
console.log('\n', 'Started Circle CI build:', chalk.green(body.build_url), '\n')
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// if we're not being required
|
||||
// then kick off scraping
|
||||
if (!module.parent) {
|
||||
scrape()
|
||||
}
|
||||
|
||||
module.exports = scrape
|
||||
Reference in New Issue
Block a user