diff --git a/README.md b/README.md index 80e52088..00d51fb8 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,6 @@ Commands: configure [options] [source] [target] gets environment variables from Vault and uploads them to the current app deploy-static [options] [otherSources...] Deploys static to S3. Requires AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY env vars run [options] Runs the local app through the router - rebuild [options] [apps...] DEPRECATED. Trigger a rebuild of the latest master on Circle gtg [app] Runs gtg checks for an app review-app [options] [appName] Create or find an existing heroku review app and print out the app name. [appName] is the package.json name (which is also the value of VAULT_NAME). On the first build of a branch, Heroku will create a review app with a build. On subsequent builds, Heroku will automatically generate a new build, which this task looks for. See https://devcenter.heroku.com/articles/review-apps-beta for more details of the internals upload-assets-to-s3 [options] Uploads a folder of assets to an S3 bucket diff --git a/bin/n-heroku-tools.js b/bin/n-heroku-tools.js index 9c14754b..13d1f00f 100755 --- a/bin/n-heroku-tools.js +++ b/bin/n-heroku-tools.js @@ -21,7 +21,6 @@ program.version(require('../package.json').version); require('../tasks/configure')(program, utils); require('../tasks/deploy-static')(program, utils); require('../tasks/run')(program, utils); -require('../tasks/rebuild')(program, utils); require('../tasks/gtg')(program, utils); require('../tasks/review-app')(program, utils); require('../tasks/upload-assets-to-s3')(program, utils); diff --git a/package.json b/package.json index 607d3547..eb20dd0a 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,6 @@ "commander": "^3.0.0", "denodeify": "^1.2.0", "dotenv": "^8.0.0", - "fetchres": "^1.0.4", "foreman": "^3.0.0", "glob": "^7.1.6", "is-image": "^3.0.0", diff --git a/tasks/rebuild.js b/tasks/rebuild.js deleted file mode 100644 index dd43358a..00000000 --- a/tasks/rebuild.js +++ /dev/null @@ -1,99 +0,0 @@ -const fetchres = require('fetchres'); -const keys = require('../lib/keys'); - -const DEFAULT_REGISTRY_URI = 'https://next-registry.ft.com/v2/services.json'; - -const getCircleToken = () => - process.env.CIRCLECI_REBUILD_KEY - ? Promise.resolve(process.env.CIRCLECI_REBUILD_KEY) - : keys().then(env => env.CIRCLECI_REBUILD_KEY); - -async function circleFetch (path, opts) { - const defaultOptions = { - timeout: 3000, - headers: { - 'Content-Type': 'application/json', - 'Accept': 'application/json' - } - }; - - const circleToken = await getCircleToken(); - const options = Object.assign(defaultOptions, opts); - const url = `https://circleci.com/api/v1.1/project/github/Financial-Times${path}?circle-token=${circleToken}`; - - const res = await fetch(url, options); - - if (res.ok) { - return res.json(); - } else { - console.log(`Response not OK for ${path}, got: ${res.status}`); // eslint-disable-line no-console - throw new Error(res.status); - } -} - -const triggerMasterBuild = (project) => circleFetch(`/${project}/build`, { method: 'POST', body: JSON.stringify({ branch: 'master' }) }); - -const lastMasterBuild = (project) => circleFetch(`/${project}/tree/master`); - -const getRepoName = ({ repository }) => { - if (/https?:\/\/github\.com\/Financial-Times\//.test(repository)) { - return repository - .replace(/https?:\/\/github\.com\/Financial-Times\//, '') - .replace(/\/$/, ''); // trim trailing "/" - } -}; - -const serves = type => app => type ? app.types && app.types.includes(type) : true; - -async function task (options) { - const apps = options.apps; - const allApps = options.all; - const registry = options.registry || DEFAULT_REGISTRY_URI; - let appsToRebuild = []; - - const areAppsToRebuild = (apps.length) || allApps; - if (!areAppsToRebuild) { - console.log('Use the --all flag to rebuild all apps or supply a specific app name.'); // eslint-disable-line no-console - process.exit(1); - } - - if (apps.length) { - appsToRebuild = apps; - } else if (allApps) { - const registryData = await fetch(registry).then(fetchres.json); - appsToRebuild = registryData - .filter(serves(options.serves)) - .map(getRepoName) - .filter(repo => repo); - } - - return Promise.all(appsToRebuild.map(async app => { - console.log(`Considering whether to rebuild ${app}`); // eslint-disable-line no-console - try { - const [lastBuild] = await lastMasterBuild(app); - console.log(`Triggering master build for ${app} (git commit: ${lastBuild.vcs_revision})`); // eslint-disable-line no-console - await triggerMasterBuild(app); - } catch (error) { - console.log(`Skipped rebuild of ${app}, probably because Circle CI not set up for this repo`); // eslint-disable-line no-console - } - })); -}; - -module.exports = function (program, utils) { - program - .command('rebuild [apps...]') - .option('--all', 'Trigger rebuilds of all apps.') - .option('--registry [registry-uri]', `use this registry, instead of the default: ${DEFAULT_REGISTRY_URI}`, DEFAULT_REGISTRY_URI) - .option('--serves ', 'Trigger rebuilds of apps where type is served.') - .description('Trigger a rebuild of the latest master on Circle') - .action((apps, opts) => { - return task({ - apps: apps, - serves: opts.serves, - registry: opts.registry, - all: opts.all - }).catch(utils.exit); - }); -}; - -module.exports.task = task;