Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update next-version to handle using the next bump package.json… #25599

Merged
merged 7 commits into from
Jan 27, 2023
4 changes: 2 additions & 2 deletions .circleci/workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mainBuildFilters: &mainBuildFilters
only:
- develop
- /^release\/\d+\.\d+\.\d+$/
- 'mschile/chrome_memory_fix'
- 'emily/next-version'

# usually we don't build Mac app - it takes a long time
# but sometimes we want to really confirm we are doing the right thing
Expand Down Expand Up @@ -130,7 +130,7 @@ commands:
- run:
name: Check current branch to persist artifacts
command: |
if [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "mschile/chrome_memory_fix" ]]; then
if [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "emily/next-version" ]]; then
echo "Not uploading artifacts or posting install comment for this branch."
circleci-agent step halt
fi
Expand Down
6 changes: 3 additions & 3 deletions cli/lib/tasks/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ const clear = () => {

const prune = () => {
const cacheDir = state.getCacheDir()
const currentVersion = util.pkgVersion()
const checkedInBinaryVersion = util.pkgVersion()

let deletedBinary = false

return fs.readdirAsync(cacheDir)
.then((versions) => {
return Bluebird.all(versions.map((version) => {
if (version !== currentVersion) {
if (version !== checkedInBinaryVersion) {
deletedBinary = true

const versionDir = join(cacheDir, version)
Expand All @@ -51,7 +51,7 @@ const prune = () => {
})
.then(() => {
if (deletedBinary) {
logger.always(`Deleted all binary caches except for the ${currentVersion} binary cache.`)
logger.always(`Deleted all binary caches except for the ${checkedInBinaryVersion} binary cache.`)
} else {
logger.always(`No binary caches found to prune.`)
}
Expand Down
8 changes: 4 additions & 4 deletions cli/test/lib/tasks/cache_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ describe('lib/tasks/cache', () => {
it('deletes cache binaries for all version but the current one', async () => {
await cache.prune()

const currentVersion = util.pkgVersion()
const checkedInBinaryVersion = util.pkgVersion()

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

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

files.forEach((file) => {
expect(file).to.eq(currentVersion)
expect(file).to.eq(checkedInBinaryVersion)
})

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

const currentVersion = util.pkgVersion()
const checkedInBinaryVersion = util.pkgVersion()

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

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

files.forEach((file) => {
expect(file).to.eq(currentVersion)
expect(file).to.eq(checkedInBinaryVersion)
})

defaultSnapshot()
Expand Down
3 changes: 2 additions & 1 deletion scripts/binary/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
// store the cwd
const cwd = process.cwd()

Expand Down Expand Up @@ -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)
})
Expand Down
25 changes: 19 additions & 6 deletions scripts/get-next-version.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
/* eslint-disable no-console */

// See ../guides/next-version.md for documentation.

const path = require('path')
const semver = require('semver')
const bumpCb = require('conventional-recommended-bump')
const { promisify } = require('util')

const currentVersion = require('../package.json').version
const checkedInBinaryVersion = require('../package.json').version
const { changeCatagories } = require('./semantic-commits/change-categories')
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(false)

let commits
const whatBump = (foundCommits) => {
// semantic version bump: 0 - major, 1 - minor, 2 - patch
Expand Down Expand Up @@ -48,9 +50,20 @@ const getNextVersionForPath = async (path) => {
path,
})

let nextVersion = semver.inc(checkedInBinaryVersion, releaseType || 'patch')

const hasVersionBump = checkedInBinaryVersion !== releasedVersion

// 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) {
nextVersion = process.env.NEXT_VERSION
} else if (hasVersionBump) {
nextVersion = checkedInBinaryVersion
}

return {
// allow the semantic next version to be overridden by environment
nextVersion: process.env.NEXT_VERSION || semver.inc(currentVersion, releaseType || 'patch'),
nextVersion,
commits,
}
}
Expand Down Expand Up @@ -93,7 +106,7 @@ if (require.main !== module) {

const { nextVersion } = await getNextVersionForBinary()

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

console.log(`Running '${cmd}'...`)
Expand Down
17 changes: 3 additions & 14 deletions scripts/npm-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
/* eslint-disable no-console */
const execa = require('execa')
const fs = require('fs')
const path = require('path')
const semverSortNewestFirst = require('semver/functions/rcompare')
const checkedInBinaryVersion = require('../package.json').version

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

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

const getBinaryVersion = async () => {
const { stdout: root } = await execa('git', ['rev-parse', '--show-toplevel'])
const rootPath = path.join(root, 'package.json')
const rootPackage = JSON.parse(fs.readFileSync(rootPath))

return rootPackage.version
}

const parseSemanticReleaseOutput = (output) => {
const currentVersion = (output.match(/associated with version (\d+\.\d+\.\d+-?\S*)/) || [])[1]
const nextVersion = (output.match(/next release version is (\d+\.\d+\.\d+-?\S*)/) || [])[1]
Expand Down Expand Up @@ -71,13 +63,11 @@ const getCurrentVersion = async (name) => {
const getPackageVersions = async (packages) => {
console.log(`Finding package versions...\n`)

const binaryVersion = await getBinaryVersion()

console.log(`Cypress binary: ${binaryVersion}`)
console.log(`Cypress binary: ${checkedInBinaryVersion}`)

const versions = {
cypress: {
currentVersion: binaryVersion,
currentVersion: checkedInBinaryVersion,
nextVersion: undefined,
},
}
Expand Down Expand Up @@ -232,7 +222,6 @@ if (require.main === module) {
}

module.exports = {
getBinaryVersion,
parseSemanticReleaseOutput,
readPackageJson,
releasePackages,
Expand Down
27 changes: 4 additions & 23 deletions scripts/semantic-commits/get-binary-release-data.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,14 @@
/* eslint-disable no-console */
const execa = require('execa')
const childProcess = require('child_process')
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.
Expand All @@ -36,8 +18,8 @@ const getCurrentReleaseData = async () => {
* @param {string} latestReleaseInfo.commitDate - data of release
* @param {string} latestReleaseInfo.buildSha - git commit associated with published content
*/
const getChangedFilesSinceLastRelease = async (latestReleaseInfo) => {
const { stdout } = await execa('git', ['diff', `${latestReleaseInfo.buildSha}..`, '--name-only'])
const getChangedFilesSinceLastRelease = (latestReleaseInfo) => {
const stdout = childProcess.execSync(`git diff ${latestReleaseInfo.buildSha}.. --name-only`)

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

if (require.main !== module) {
module.exports = {
getCurrentReleaseData,
getReleaseData,
}

Expand Down
26 changes: 26 additions & 0 deletions scripts/semantic-commits/get-current-release-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* eslint-disable no-console */
const childProcess = require('child_process')

/**
* Get the version, commit date and git sha of the latest tag published on npm.
*/
const getCurrentReleaseData = (verbose = true) => {
verbose && console.log('Get Current Release Information\n')

const stdout = childProcess.execSync('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,
}
9 changes: 4 additions & 5 deletions scripts/semantic-commits/validate-binary-changelog.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
/* eslint-disable no-console */
const { getBinaryVersion } = require('../npm-release')
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 () => {
const latestReleaseInfo = await getCurrentReleaseData()

if (process.env.CIRCLECI) {
const checkedInBinaryVersion = await getBinaryVersion()

console.log({ checkedInBinaryVersion })

const hasVersionBump = checkedInBinaryVersion !== latestReleaseInfo.version

if (process.env.CIRCLE_BRANCH !== 'develop' || !/^release\/\d+\.\d+\.\d+$/.test(process.env.CIRCLE_BRANCH) || !hasVersionBump) {
if (process.env.CIRCLE_BRANCH !== 'develop' && !/^release\/\d+\.\d+\.\d+$/.test(process.env.CIRCLE_BRANCH) && !hasVersionBump) {
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.')

return
Expand Down
Loading