UNPKG

@salesforce/plugin-release-management

Version:
142 lines 6.48 kB
"use strict"; /* * Copyright (c) 2020, salesforce.com, inc. * All rights reserved. * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ Object.defineProperty(exports, "__esModule", { value: true }); const os = require("os"); const command_1 = require("@salesforce/command"); const shelljs_1 = require("shelljs"); const ts_types_1 = require("@salesforce/ts-types"); const kit_1 = require("@salesforce/kit"); const core_1 = require("@octokit/core"); const chalk_1 = require("chalk"); const core_2 = require("@salesforce/core"); const repository_1 = require("../../../repository"); core_2.Messages.importMessagesDirectory(__dirname); const messages = core_2.Messages.loadMessages('@salesforce/plugin-release-management', 'cli.latestrc.build'); class build extends command_1.SfdxCommand { async run() { let auth; const pushChangesToGitHub = !this.flags['build-only']; if (pushChangesToGitHub) { auth = (0, ts_types_1.ensureString)(new kit_1.Env().getString('GH_TOKEN') ?? new kit_1.Env().getString('GITHUB_TOKEN'), 'The GH_TOKEN env var is required to push changes to GitHub. Use the --build-only flag to skip GitHub operations (a manual push will then be needed)'); } // get the current version and implement the patch version for a default rc build const repo = await repository_1.PackageRepo.create({ ux: this.ux }); const nextRCVersion = repo.package.getNextRCVersion(this.flags.rctag, this.flags.patch); repo.nextVersion = nextRCVersion; this.ux.log(`starting on main and will checkout ${repo.nextVersion}`); // start the latest-rc build process on a clean main branch this.exec('git checkout main'); this.exec('git pull'); this.exec(`git checkout -b ${nextRCVersion}`); // bump the version in the pjson to the new latest-rc this.ux.log(`setting the version to ${nextRCVersion}`); repo.package.setNextVersion(nextRCVersion); repo.package.packageJson.version = nextRCVersion; const only = this.flags.only; if (only) { this.ux.log(`bumping the following dependencies only: ${only.join(', ')}`); const bumped = repo.package.bumpDependencyVersions(only); if (!bumped.length) { throw new core_2.SfError('No version changes made. Confirm you are passing the correct dependency and version to --only.'); } } else { // bump resolution deps if (this.flags.resolutions) { this.ux.log('bumping resolutions in the package.json to their "latest"'); repo.package.bumpResolutions('latest'); } // pin the pinned dependencies if (this.flags['pinned-deps']) { this.ux.log('pinning dependencies in pinnedDependencies to "latest-rc"'); repo.package.pinDependencyVersions('latest-rc'); } } repo.package.writePackageJson(); this.exec('yarn install'); // streamline the lockfile this.exec('npx yarn-deduplicate'); if (this.flags.snapshot) { this.ux.log('updating snapshots'); this.exec(`./bin/${repo.name === 'sfdx-cli' ? 'dev.sh' : 'dev'} snapshot:generate`, { silent: false }); } if (this.flags.schema) { this.ux.log('updating schema'); this.exec('sf-release cli:schemas:collect', { silent: false }); } if (pushChangesToGitHub) { const octokit = new core_1.Octokit({ auth }); await this.maybeSetGitConfig(octokit); // commit package.json/yarn.lock and potentially command-snapshot changes this.exec('git add .'); this.exec(`git commit -m "chore(latest-rc): bump to ${nextRCVersion}"`); this.exec(`git push --set-upstream origin ${nextRCVersion} --no-verify`, { silent: false }); const repoOwner = repo.package.packageJson.repository.split('/')[0]; const repoName = repo.package.packageJson.repository.split('/')[1]; await octokit.request(`POST /repos/${repoOwner}/${repoName}/pulls`, { owner: repoOwner, repo: repoName, head: nextRCVersion, base: 'main', title: `Release v${nextRCVersion} as latest-rc`, body: 'Building latest-rc [skip-validate-pr]', }); } } exec(cmd, options = { silent: true }) { this.log((0, chalk_1.bold)(cmd)); (0, shelljs_1.exec)(cmd, options); } async maybeSetGitConfig(octokit) { const username = (0, shelljs_1.exec)('git config user.name', { silent: true }).stdout.trim(); const email = (0, shelljs_1.exec)('git config user.email', { silent: true }).stdout.trim(); if (!username || !email) { const user = await octokit.request('GET /user'); if (!username) this.exec(`git config user.name "${user.data.name}"`); if (!email) this.exec(`git config user.email "${user.data.email}"`); } } } exports.default = build; build.description = messages.getMessage('description'); build.examples = messages.getMessage('examples').split(os.EOL); build.flagsConfig = { rctag: command_1.flags.string({ description: messages.getMessage('flags.rctag'), default: 'latest-rc', }), 'build-only': command_1.flags.boolean({ description: messages.getMessage('flags.buildOnly'), default: false, }), resolutions: command_1.flags.boolean({ description: messages.getMessage('flags.resolutions'), default: true, allowNo: true, }), only: command_1.flags.array({ description: messages.getMessage('flags.only'), }), 'pinned-deps': command_1.flags.boolean({ description: messages.getMessage('flags.pinnedDeps'), default: true, allowNo: true, }), patch: command_1.flags.boolean({ description: messages.getMessage('flags.patch'), }), snapshot: command_1.flags.boolean({ description: messages.getMessage('flags.snapshot'), }), schema: command_1.flags.boolean({ description: messages.getMessage('flags.schema'), }), }; //# sourceMappingURL=build.js.map