From 7e330969fe6360a46a539221e5c471f39c2c8aee Mon Sep 17 00:00:00 2001 From: Emily Rohrbough Date: Fri, 27 Jan 2023 08:49:30 -0600 Subject: [PATCH] only log next-version for scripting --- scripts/binary/index.js | 3 ++- scripts/get-next-version.js | 7 +++--- .../get-binary-release-data.js | 21 +--------------- .../get-current-release-data.js | 25 +++++++++++++++++++ .../validate-binary-changelog.js | 3 ++- scripts/unit/get-next-version-spec.js | 23 +++++++++-------- 6 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 scripts/semantic-commits/get-current-release-data.js diff --git a/scripts/binary/index.js b/scripts/binary/index.js index 00efe9790f68..d90a5985c26a 100644 --- a/scripts/binary/index.js +++ b/scripts/binary/index.js @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ // store the cwd const cwd = process.cwd() @@ -194,7 +195,7 @@ const deploy = { return askMissingOptions(['version', 'platform'])(options) .then(() => { - debug('building binary: platform %s version %s', options.platform, options.version) + console.log('building binary: platform %s version %s', options.platform, options.version) return build.buildCypressApp(options) }) diff --git a/scripts/get-next-version.js b/scripts/get-next-version.js index 572a632b4f80..2f71f5c6f159 100644 --- a/scripts/get-next-version.js +++ b/scripts/get-next-version.js @@ -7,12 +7,13 @@ const { promisify } = require('util') const checkedInBinaryVersion = require('../package.json').version const { changeCatagories } = require('./semantic-commits/change-categories') -const { getCurrentReleaseData } = require('./semantic-commits/get-binary-release-data') +const { getCurrentReleaseData } = require('./semantic-commits/get-current-release-data') + const bump = promisify(bumpCb) const paths = ['packages', 'cli'] const getNextVersionForPath = async (path) => { - const { version: releasedVersion } = await getCurrentReleaseData() + const { version: releasedVersion } = await getCurrentReleaseData(false) let commits const whatBump = (foundCommits) => { @@ -56,10 +57,8 @@ const getNextVersionForPath = async (path) => { // See ../guides/next-version.md for documentation. // for the time being, honoring this ENV -- ideally this will be deleted to remove manually overriding without a PR if (process.env.NEXT_VERSION) { - console.log('honoring process.env.NEXT_VERSION') nextVersion = process.env.NEXT_VERSION } else if (hasVersionBump) { - console.log('honoring the approved binary version bump') nextVersion = checkedInBinaryVersion } diff --git a/scripts/semantic-commits/get-binary-release-data.js b/scripts/semantic-commits/get-binary-release-data.js index c055af64dca2..53815bf0695c 100644 --- a/scripts/semantic-commits/get-binary-release-data.js +++ b/scripts/semantic-commits/get-binary-release-data.js @@ -3,30 +3,12 @@ const execa = require('execa') const _ = require('lodash') const { Octokit } = require('@octokit/core') +const { getCurrentReleaseData } = require('../get-current-release-data') const { getNextVersionForBinary } = require('../get-next-version') const { getLinkedIssues } = require('./get-linked-issues') const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN }) -/** - * Get the version, commit date and git sha of the latest tag published on npm. - */ -const getCurrentReleaseData = async () => { - console.log('Get Current Release Information\n') - const { stdout } = await execa('npm', ['info', 'cypress', '--json']) - const npmInfo = JSON.parse(stdout) - - const latestReleaseInfo = { - version: npmInfo['dist-tags'].latest, - commitDate: npmInfo.buildInfo.commitDate, - buildSha: npmInfo.buildInfo.commitSha, - } - - console.log({ latestReleaseInfo }) - - return latestReleaseInfo -} - /** * Get the list of file names that have been added, deleted or changed since the git * sha associated with the latest tag published on npm. @@ -117,7 +99,6 @@ const getReleaseData = async (latestReleaseInfo) => { if (require.main !== module) { module.exports = { - getCurrentReleaseData, getReleaseData, } diff --git a/scripts/semantic-commits/get-current-release-data.js b/scripts/semantic-commits/get-current-release-data.js new file mode 100644 index 000000000000..2bec16fa173d --- /dev/null +++ b/scripts/semantic-commits/get-current-release-data.js @@ -0,0 +1,25 @@ +/* eslint-disable no-console */ +const execa = require('execa') + +/** + * Get the version, commit date and git sha of the latest tag published on npm. + */ +const getCurrentReleaseData = async (verbose = true) => { + verbose && console.log('Get Current Release Information\n') + const { stdout } = await execa('npm', ['info', 'cypress', '--json']) + const npmInfo = JSON.parse(stdout) + + const latestReleaseInfo = { + version: npmInfo['dist-tags'].latest, + commitDate: npmInfo.buildInfo.commitDate, + buildSha: npmInfo.buildInfo.commitSha, + } + + verbose && console.log({ latestReleaseInfo }) + + return latestReleaseInfo +} + +module.exports = { + getCurrentReleaseData, +} diff --git a/scripts/semantic-commits/validate-binary-changelog.js b/scripts/semantic-commits/validate-binary-changelog.js index 7096544339cd..865d2b557346 100644 --- a/scripts/semantic-commits/validate-binary-changelog.js +++ b/scripts/semantic-commits/validate-binary-changelog.js @@ -1,6 +1,7 @@ /* eslint-disable no-console */ const { validateChangelog } = require('./validate-changelog') -const { getCurrentReleaseData, getReleaseData } = require('./get-binary-release-data') +const { getCurrentReleaseData } = require('./get-current-release-data') +const { getReleaseData } = require('./get-binary-release-data') const checkedInBinaryVersion = require('../../package.json').version const changelog = async () => { diff --git a/scripts/unit/get-next-version-spec.js b/scripts/unit/get-next-version-spec.js index 7ca9fd4deb07..bee10f39fc6e 100644 --- a/scripts/unit/get-next-version-spec.js +++ b/scripts/unit/get-next-version-spec.js @@ -20,10 +20,13 @@ describe('get-next-version', () => { bumpStub = sinon.stub() getCurrentReleaseDataStub = sinon.stub() + getCurrentReleaseDataStub.resolves({ + version: releasedVersion, + }) const npmRelease = proxyquire('../get-next-version', { 'conventional-recommended-bump': bumpStub, - './semantic-commits/get-binary-release-data': { + './semantic-commits/get-current-release-data': { getCurrentReleaseData: getCurrentReleaseDataStub, }, '../package.json': sinon.stub({ version: '12.2.0' }), @@ -47,7 +50,7 @@ describe('get-next-version', () => { return cb(undefined, { releaseType: 'patch' }) }) - const { nextVersion, commits } = await getNextVersionForPath('packages', releasedVersion) + const { nextVersion, commits } = await getNextVersionForPath('packages') expect(nextVersion).to.eq('12.2.1') expect(commits).to.contain.members(semanticCommits) @@ -67,7 +70,7 @@ describe('get-next-version', () => { return cb(undefined, { releaseType: 'minor' }) }) - const { nextVersion, commits } = await getNextVersionForPath('packages', releasedVersion) + const { nextVersion, commits } = await getNextVersionForPath('packages') expect(nextVersion).to.eq('12.3.0') expect(commits).to.contain.members(semanticCommits) @@ -88,7 +91,7 @@ describe('get-next-version', () => { return cb(undefined, { releaseType: 'major' }) }) - const { nextVersion, commits } = await getNextVersionForPath('packages', releasedVersion) + const { nextVersion, commits } = await getNextVersionForPath('packages') expect(nextVersion).to.eq('13.0.0') expect(commits).to.contain.members(semanticCommits) @@ -107,8 +110,12 @@ describe('get-next-version', () => { return cb(undefined, { releaseType: 'patch' }) }) - // package version !== release version assumed check in version is correct - const { nextVersion, commits } = await getNextVersionForPath('packages', '12.2.2') + getCurrentReleaseDataStub.resolves({ + // package version !== release version assumed check in version is correct + version: '12.2.2', + }) + + const { nextVersion, commits } = await getNextVersionForPath('packages') expect(nextVersion).to.eq('12.2.0') expect(commits).to.contain.members(semanticCommits) @@ -148,10 +155,6 @@ describe('get-next-version', () => { { type: 'feat', title: 'feat: add new command' }, ] - getCurrentReleaseDataStub.resolves({ - version: releasedVersion, - }) - bumpStub.callsFake(async ({ whatBump, _path }, cb) => { if (calls === 0) { const { level } = whatBump(packagesSemanticCommits)