add separate clone script to be run as heroku-prebuild script or locally by docs writers

This commit is contained in:
Sarah Schneider 2020-10-22 11:20:09 -04:00
Родитель 4341a92e7f
Коммит 129641c359
2 изменённых файлов: 58 добавлений и 1 удалений

Просмотреть файл

@ -140,7 +140,7 @@
"prevent-pushes-to-main": "node script/prevent-pushes-to-main.js", "prevent-pushes-to-main": "node script/prevent-pushes-to-main.js",
"pa11y-ci": "pa11y-ci", "pa11y-ci": "pa11y-ci",
"pa11y-test": "start-server-and-test browser-test-server 4001 pa11y-ci", "pa11y-test": "start-server-and-test browser-test-server 4001 pa11y-ci",
"heroku-prebuild": "rm -rf content/early-access-test && git clone https://${TEMP_KEY_ACCESS_KEY}@github.com/docs/early-access-test content/early-access-test && rm -rf content/early-access-test/.git" "heroku-prebuild": "node script/clone-early-access.js"
}, },
"engines": { "engines": {
"node": "12 - 14" "node": "12 - 14"

57
script/clone-early-access.js Executable file
Просмотреть файл

@ -0,0 +1,57 @@
#!/usr/bin/env node
// [start-readme]
//
// This script is run as a prebuild script during staging and deployments on Heroku.
// If you have access to the PAT, it can also be run locally to clone https://github.com/docs/early-access.
// The script clones a branch in the early-access repo that matches the current branch in the docs repo;
// if one can't be found, it clones the `main` branch.
//
// [end-readme]
require('dotenv').config()
const { GITHUB_DOCUBOT_REPO_PAT } = process.env
// TODO...
// // Exit if early access is not enabled
// if (!process.env.EARLY_ACCESS_ENABLED) {
// console.log('Skipping early access, not enable')
// process.exit(0)
// }
// Exit if PAT is not found
if (!process.env.GITHUB_DOCUBOT_REPO_PAT) {
console.log('Skipping early access, not authorized')
process.exit(0)
}
const { execSync } = require('child_process')
const rimraf = require('rimraf').sync
const fs = require('fs')
const path = require('path')
// Early Access details
const earlyAccessDir = 'early-access-test'
const earlyAccessRepo = `https://${GITHUB_DOCUBOT_REPO_PAT}@github.com/docs/${earlyAccessDir}`
const earlyAccessContentDir = path.join(process.cwd(), 'content', earlyAccessDir)
// Look for a branch in early-access that matches the current docs branch;
// otherwise fall back to `main`
const docsBranch = execSync('git branch --show-current').toString().trim()
const earlyAccessBranch = execSync(`git ls-remote --heads ${earlyAccessRepo} ${docsBranch}`).toString()
? docsBranch
: 'main'
// Remove any dir that may pre-exist
rimraf(earlyAccessContentDir)
// Clone the repo
execSync(`git clone --single-branch --branch ${earlyAccessBranch} ${earlyAccessRepo} ${earlyAccessContentDir}`)
console.log(`Branch: ${earlyAccessBranch}`)
// Remove the .git dir
rimraf(`${earlyAccessContentDir}/.git`)
// Confirm the directory exists
fs.existsSync(earlyAccessContentDir)