Version in commit subject 563 (#564)

* start unit testing npm version extract

* put short NPM version into trigger commit subject, close #563

* pass appVeyor token to bumpercar
This commit is contained in:
Gleb Bahmutov
2017-10-05 14:13:11 +00:00
committed by GitHub
parent 72d9fae4e0
commit a9dcfdff31
6 changed files with 121 additions and 5 deletions

View File

@@ -0,0 +1,38 @@
exports['getJustVersion returns semver if passed 1'] = `
0.20.1
`
exports['getJustVersion returns semver with tag if passed 1'] = `
1.0.0-dev
`
exports['getJustVersion returns name if starts with cypress 1'] = `
cypress@dev
`
exports['getJustVersion returns name if starts with cypress 2'] = `
cypress@alpha
`
exports['getJustVersion returns name if starts with cypress 3'] = `
cypress@0.20.3
`
exports['getJustVersion returns name if matches cypress 1'] = `
cypress
`
exports['getJustVersion extracts version from url 1'] = {
"url": "https://foo.com/npm/0.20.3/develop-sha-13992/cypress.tgz",
"version": "0.20.3"
}
exports['getJustVersion extracts version with dev from url 1'] = {
"url": "https://foo.com/npm/0.20.3-dev/develop-sha-13992/cypress.tgz",
"version": "0.20.3-dev"
}
exports['getJustVersion for anything else returns the input 1'] = {
"url": "babababa",
"version": "babababa"
}

View File

@@ -22,7 +22,7 @@
"lint-js": "eslint --fix scripts/*.js",
"lint-coffee": "coffeelint scripts/**/*.coffee",
"lint": "npm run lint-js && npm run lint-coffee",
"pretest": "npm run lint && npm run all lint",
"pretest": "npm run lint && npm run all lint && npm run test-scripts",
"precommit": "lint-staged",
"precommit-lint": "eslint --fix",
"prepush": "npm run stop-only",
@@ -35,6 +35,7 @@
"binary-purge": "node ./scripts/binary.js purge-version",
"binary-deploy-linux": "./scripts/build-linux-binary.sh",
"binary-release": "node ./scripts/binary.js release",
"test-scripts": "mocha --reporter spec scripts/unit/*spec.js",
"test-mocha": "mocha --reporter spec scripts/spec.js",
"test-mocha-snapshot": "mocha scripts/mocha-snapshot-spec.js"
},

View File

@@ -88,8 +88,10 @@ getCiConfig = ->
awaitEachProjectAndProvider = (fn) ->
creds = getCiConfig()
# TODO only check tokens for providers we really going to use
la(check.unemptyString(creds.githubToken), "missing githubToken")
la(check.unemptyString(creds.circleToken), "missing circleToken")
la(check.unemptyString(creds.appVeyorToken), "missing appVeyorToken")
## configure a new Bumpercar
car = bumpercar.create({
@@ -100,6 +102,9 @@ awaitEachProjectAndProvider = (fn) ->
circle: {
circleToken: creds.circleToken
}
appVeyor: {
appVeyorToken: creds.appVeyorToken
}
}
})

View File

@@ -2,7 +2,7 @@ require('@packages/coffee/register')
const la = require('lazy-ass')
const is = require('check-more-types')
const { getNameAndBinary } = require('./utils')
const { getNameAndBinary, getJustVersion } = require('./utils')
const bump = require('./binary/bump')
const { stripIndent } = require('common-tags')
const os = require('os')
@@ -27,13 +27,23 @@ bump.version(npm, binary, platform)
la(is.unemptyString(result.versionName), 'missing versionName', result)
la(is.unemptyString(result.binary), 'missing binary', result)
const message = stripIndent`
Testing new Cypress version
const shortNpmVersion = getJustVersion(result.versionName)
console.log('short NPM version', shortNpmVersion)
let message = stripIndent`
Testing new Cypress version ${shortNpmVersion}
NPM package: ${result.versionName}
Binary: ${result.binary}
CircleCI job url: ${process.env.CIRCLE_BUILD_URL}
`
if (process.env.CIRCLE_BUILD_URL) {
message += '\n'
message += stripIndent`
CircleCI job url: ${process.env.CIRCLE_BUILD_URL}
`
}
console.log('commit message')
console.log(message)
return bump.run(message)
})
.catch((e) => {

View File

@@ -0,0 +1,42 @@
const snapshot = require('snap-shot-it')
/* eslint-env mocha */
describe('getJustVersion', () => {
const { getJustVersion } = require('../utils')
it('returns semver if passed', () => {
snapshot(getJustVersion('0.20.1'))
})
it('returns semver with tag if passed', () => {
snapshot(getJustVersion('1.0.0-dev'))
})
it('returns name if starts with cypress', () => {
snapshot(getJustVersion('cypress@dev'))
snapshot(getJustVersion('cypress@alpha'))
snapshot(getJustVersion('cypress@0.20.3'))
})
it('returns name if matches cypress', () => {
snapshot(getJustVersion('cypress'))
})
it('extracts version from url', () => {
const url = 'https://foo.com/npm/0.20.3/develop-sha-13992/cypress.tgz'
const version = getJustVersion(url)
snapshot({ url, version })
})
it('extracts version with dev from url', () => {
const url = 'https://foo.com/npm/0.20.3-dev/develop-sha-13992/cypress.tgz'
const version = getJustVersion(url)
snapshot({ url, version })
})
it('for anything else returns the input', () => {
const url = 'babababa'
const version = getJustVersion(url)
snapshot({ url, version })
})
})

View File

@@ -34,6 +34,26 @@ function getNameAndBinary (args = process.argv) {
}
}
function getJustVersion (npmNameOrUrl) {
la(is.unemptyString(npmNameOrUrl), 'missing NPM string', npmNameOrUrl)
if (npmNameOrUrl.startsWith('cypress')) {
return npmNameOrUrl
}
if (is.url(npmNameOrUrl)) {
// try finding semver in the url
// https://something/0.20.3/something...
const re = /\/(\d+\.\d+\.\d+(-\w+)?)\//
const matches = re.exec(npmNameOrUrl)
if (matches) {
return matches[1]
}
}
return npmNameOrUrl
}
module.exports = {
getNameAndBinary,
getJustVersion,
}