Skip to content

Commit 52e9dbc

Browse files
chore: update next-version to handle using the next bump package.json… (#25599)
Co-authored-by: Bill Glesias <bglesias@gmail.com>
1 parent b507141 commit 52e9dbc

11 files changed

+254
-59
lines changed

.circleci/workflows.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ mainBuildFilters: &mainBuildFilters
2828
only:
2929
- develop
3030
- /^release\/\d+\.\d+\.\d+$/
31-
- 'mschile/chrome_memory_fix'
31+
- 'emily/next-version'
3232

3333
# usually we don't build Mac app - it takes a long time
3434
# but sometimes we want to really confirm we are doing the right thing
@@ -130,7 +130,7 @@ commands:
130130
- run:
131131
name: Check current branch to persist artifacts
132132
command: |
133-
if [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "mschile/chrome_memory_fix" ]]; then
133+
if [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "emily/next-version" ]]; then
134134
echo "Not uploading artifacts or posting install comment for this branch."
135135
circleci-agent step halt
136136
fi

cli/lib/tasks/cache.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ const clear = () => {
3333

3434
const prune = () => {
3535
const cacheDir = state.getCacheDir()
36-
const currentVersion = util.pkgVersion()
36+
const checkedInBinaryVersion = util.pkgVersion()
3737

3838
let deletedBinary = false
3939

4040
return fs.readdirAsync(cacheDir)
4141
.then((versions) => {
4242
return Bluebird.all(versions.map((version) => {
43-
if (version !== currentVersion) {
43+
if (version !== checkedInBinaryVersion) {
4444
deletedBinary = true
4545

4646
const versionDir = join(cacheDir, version)
@@ -51,7 +51,7 @@ const prune = () => {
5151
})
5252
.then(() => {
5353
if (deletedBinary) {
54-
logger.always(`Deleted all binary caches except for the ${currentVersion} binary cache.`)
54+
logger.always(`Deleted all binary caches except for the ${checkedInBinaryVersion} binary cache.`)
5555
} else {
5656
logger.always(`No binary caches found to prune.`)
5757
}

cli/test/lib/tasks/cache_spec.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,14 @@ describe('lib/tasks/cache', () => {
136136
it('deletes cache binaries for all version but the current one', async () => {
137137
await cache.prune()
138138

139-
const currentVersion = util.pkgVersion()
139+
const checkedInBinaryVersion = util.pkgVersion()
140140

141141
const files = await fs.readdir('/.cache/Cypress')
142142

143143
expect(files.length).to.eq(1)
144144

145145
files.forEach((file) => {
146-
expect(file).to.eq(currentVersion)
146+
expect(file).to.eq(checkedInBinaryVersion)
147147
})
148148

149149
defaultSnapshot()
@@ -155,14 +155,14 @@ describe('lib/tasks/cache', () => {
155155
await fs.removeAsync(dir)
156156
await cache.prune()
157157

158-
const currentVersion = util.pkgVersion()
158+
const checkedInBinaryVersion = util.pkgVersion()
159159

160160
const files = await fs.readdirAsync('/.cache/Cypress')
161161

162162
expect(files.length).to.eq(1)
163163

164164
files.forEach((file) => {
165-
expect(file).to.eq(currentVersion)
165+
expect(file).to.eq(checkedInBinaryVersion)
166166
})
167167

168168
defaultSnapshot()

scripts/binary/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-console */
12
// store the cwd
23
const cwd = process.cwd()
34

@@ -194,7 +195,7 @@ const deploy = {
194195

195196
return askMissingOptions(['version', 'platform'])(options)
196197
.then(() => {
197-
debug('building binary: platform %s version %s', options.platform, options.version)
198+
console.log('building binary: platform %s version %s', options.platform, options.version)
198199

199200
return build.buildCypressApp(options)
200201
})

scripts/get-next-version.js

+19-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
/* eslint-disable no-console */
22

3-
// See ../guides/next-version.md for documentation.
4-
53
const path = require('path')
64
const semver = require('semver')
75
const bumpCb = require('conventional-recommended-bump')
86
const { promisify } = require('util')
97

10-
const currentVersion = require('../package.json').version
8+
const checkedInBinaryVersion = require('../package.json').version
119
const { changeCatagories } = require('./semantic-commits/change-categories')
10+
const { getCurrentReleaseData } = require('./semantic-commits/get-current-release-data')
11+
1212
const bump = promisify(bumpCb)
1313
const paths = ['packages', 'cli']
1414

1515
const getNextVersionForPath = async (path) => {
16+
const { version: releasedVersion } = await getCurrentReleaseData(false)
17+
1618
let commits
1719
const whatBump = (foundCommits) => {
1820
// semantic version bump: 0 - major, 1 - minor, 2 - patch
@@ -48,9 +50,20 @@ const getNextVersionForPath = async (path) => {
4850
path,
4951
})
5052

53+
let nextVersion = semver.inc(checkedInBinaryVersion, releaseType || 'patch')
54+
55+
const hasVersionBump = checkedInBinaryVersion !== releasedVersion
56+
57+
// See ../guides/next-version.md for documentation.
58+
// for the time being, honoring this ENV -- ideally this will be deleted to remove manually overriding without a PR
59+
if (process.env.NEXT_VERSION) {
60+
nextVersion = process.env.NEXT_VERSION
61+
} else if (hasVersionBump) {
62+
nextVersion = checkedInBinaryVersion
63+
}
64+
5165
return {
52-
// allow the semantic next version to be overridden by environment
53-
nextVersion: process.env.NEXT_VERSION || semver.inc(currentVersion, releaseType || 'patch'),
66+
nextVersion,
5467
commits,
5568
}
5669
}
@@ -93,7 +106,7 @@ if (require.main !== module) {
93106

94107
const { nextVersion } = await getNextVersionForBinary()
95108

96-
if (process.argv.includes('--npm')) {
109+
if (process.argv.includes('--npm') && checkedInBinaryVersion !== nextVersion) {
97110
const cmd = `npm --no-git-tag-version version ${nextVersion}`
98111

99112
console.log(`Running '${cmd}'...`)

scripts/npm-release.js

+3-14
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
/* eslint-disable no-console */
66
const execa = require('execa')
77
const fs = require('fs')
8-
const path = require('path')
98
const semverSortNewestFirst = require('semver/functions/rcompare')
9+
const checkedInBinaryVersion = require('../package.json').version
1010

1111
const { getCurrentBranch, getPackagePath, readPackageJson, independentTagRegex } = require('./utils')
1212

@@ -27,14 +27,6 @@ const getTags = async () => {
2727
return stdout.split('\n')
2828
}
2929

30-
const getBinaryVersion = async () => {
31-
const { stdout: root } = await execa('git', ['rev-parse', '--show-toplevel'])
32-
const rootPath = path.join(root, 'package.json')
33-
const rootPackage = JSON.parse(fs.readFileSync(rootPath))
34-
35-
return rootPackage.version
36-
}
37-
3830
const parseSemanticReleaseOutput = (output) => {
3931
const currentVersion = (output.match(/associated with version (\d+\.\d+\.\d+-?\S*)/) || [])[1]
4032
const nextVersion = (output.match(/next release version is (\d+\.\d+\.\d+-?\S*)/) || [])[1]
@@ -71,13 +63,11 @@ const getCurrentVersion = async (name) => {
7163
const getPackageVersions = async (packages) => {
7264
console.log(`Finding package versions...\n`)
7365

74-
const binaryVersion = await getBinaryVersion()
75-
76-
console.log(`Cypress binary: ${binaryVersion}`)
66+
console.log(`Cypress binary: ${checkedInBinaryVersion}`)
7767

7868
const versions = {
7969
cypress: {
80-
currentVersion: binaryVersion,
70+
currentVersion: checkedInBinaryVersion,
8171
nextVersion: undefined,
8272
},
8373
}
@@ -232,7 +222,6 @@ if (require.main === module) {
232222
}
233223

234224
module.exports = {
235-
getBinaryVersion,
236225
parseSemanticReleaseOutput,
237226
readPackageJson,
238227
releasePackages,

scripts/semantic-commits/get-binary-release-data.js

+4-23
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,14 @@
11
/* eslint-disable no-console */
2-
const execa = require('execa')
2+
const childProcess = require('child_process')
33
const _ = require('lodash')
44
const { Octokit } = require('@octokit/core')
55

6+
const { getCurrentReleaseData } = require('./get-current-release-data')
67
const { getNextVersionForBinary } = require('../get-next-version')
78
const { getLinkedIssues } = require('./get-linked-issues')
89

910
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN })
1011

11-
/**
12-
* Get the version, commit date and git sha of the latest tag published on npm.
13-
*/
14-
const getCurrentReleaseData = async () => {
15-
console.log('Get Current Release Information\n')
16-
const { stdout } = await execa('npm', ['info', 'cypress', '--json'])
17-
const npmInfo = JSON.parse(stdout)
18-
19-
const latestReleaseInfo = {
20-
version: npmInfo['dist-tags'].latest,
21-
commitDate: npmInfo.buildInfo.commitDate,
22-
buildSha: npmInfo.buildInfo.commitSha,
23-
}
24-
25-
console.log({ latestReleaseInfo })
26-
27-
return latestReleaseInfo
28-
}
29-
3012
/**
3113
* Get the list of file names that have been added, deleted or changed since the git
3214
* sha associated with the latest tag published on npm.
@@ -36,8 +18,8 @@ const getCurrentReleaseData = async () => {
3618
* @param {string} latestReleaseInfo.commitDate - data of release
3719
* @param {string} latestReleaseInfo.buildSha - git commit associated with published content
3820
*/
39-
const getChangedFilesSinceLastRelease = async (latestReleaseInfo) => {
40-
const { stdout } = await execa('git', ['diff', `${latestReleaseInfo.buildSha}..`, '--name-only'])
21+
const getChangedFilesSinceLastRelease = (latestReleaseInfo) => {
22+
const stdout = childProcess.execSync(`git diff ${latestReleaseInfo.buildSha}.. --name-only`)
4123

4224
if (!stdout) {
4325
console.log('no files changes since last release')
@@ -117,7 +99,6 @@ const getReleaseData = async (latestReleaseInfo) => {
11799

118100
if (require.main !== module) {
119101
module.exports = {
120-
getCurrentReleaseData,
121102
getReleaseData,
122103
}
123104

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* eslint-disable no-console */
2+
const childProcess = require('child_process')
3+
4+
/**
5+
* Get the version, commit date and git sha of the latest tag published on npm.
6+
*/
7+
const getCurrentReleaseData = (verbose = true) => {
8+
verbose && console.log('Get Current Release Information\n')
9+
10+
const stdout = childProcess.execSync('npm info cypress --json')
11+
const npmInfo = JSON.parse(stdout)
12+
13+
const latestReleaseInfo = {
14+
version: npmInfo['dist-tags'].latest,
15+
commitDate: npmInfo.buildInfo.commitDate,
16+
buildSha: npmInfo.buildInfo.commitSha,
17+
}
18+
19+
verbose && console.log({ latestReleaseInfo })
20+
21+
return latestReleaseInfo
22+
}
23+
24+
module.exports = {
25+
getCurrentReleaseData,
26+
}

scripts/semantic-commits/validate-binary-changelog.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
/* eslint-disable no-console */
2-
const { getBinaryVersion } = require('../npm-release')
32
const { validateChangelog } = require('./validate-changelog')
4-
const { getCurrentReleaseData, getReleaseData } = require('./get-binary-release-data')
3+
const { getCurrentReleaseData } = require('./get-current-release-data')
4+
const { getReleaseData } = require('./get-binary-release-data')
5+
const checkedInBinaryVersion = require('../../package.json').version
56

67
const changelog = async () => {
78
const latestReleaseInfo = await getCurrentReleaseData()
89

910
if (process.env.CIRCLECI) {
10-
const checkedInBinaryVersion = await getBinaryVersion()
11-
1211
console.log({ checkedInBinaryVersion })
1312

1413
const hasVersionBump = checkedInBinaryVersion !== latestReleaseInfo.version
1514

16-
if (process.env.CIRCLE_BRANCH !== 'develop' || !/^release\/\d+\.\d+\.\d+$/.test(process.env.CIRCLE_BRANCH) || !hasVersionBump) {
15+
if (process.env.CIRCLE_BRANCH !== 'develop' && !/^release\/\d+\.\d+\.\d+$/.test(process.env.CIRCLE_BRANCH) && !hasVersionBump) {
1716
console.log('Only verify the entire changelog for develop, a release branch or any branch that bumped to the Cypress version in the package.json.')
1817

1918
return

0 commit comments

Comments
 (0)