From a9dcfdff3163ba9e54c7b31c01f8a133df730e6a Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Thu, 5 Oct 2017 14:13:11 +0000 Subject: [PATCH] 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 --- __snapshots__/utils-spec.js | 38 ++++++++++++++++++++++++++++++ package.json | 3 ++- scripts/binary/bump.coffee | 5 ++++ scripts/test-other-projects.js | 18 +++++++++++---- scripts/unit/utils-spec.js | 42 ++++++++++++++++++++++++++++++++++ scripts/utils.js | 20 ++++++++++++++++ 6 files changed, 121 insertions(+), 5 deletions(-) create mode 100644 __snapshots__/utils-spec.js create mode 100644 scripts/unit/utils-spec.js diff --git a/__snapshots__/utils-spec.js b/__snapshots__/utils-spec.js new file mode 100644 index 0000000000..48e04aa4bd --- /dev/null +++ b/__snapshots__/utils-spec.js @@ -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" +} diff --git a/package.json b/package.json index d625150e05..d5d23df4f5 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/scripts/binary/bump.coffee b/scripts/binary/bump.coffee index 46b280682a..1216d47abb 100644 --- a/scripts/binary/bump.coffee +++ b/scripts/binary/bump.coffee @@ -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 + } } }) diff --git a/scripts/test-other-projects.js b/scripts/test-other-projects.js index 3fef0f92d9..e9aad61597 100644 --- a/scripts/test-other-projects.js +++ b/scripts/test-other-projects.js @@ -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) => { diff --git a/scripts/unit/utils-spec.js b/scripts/unit/utils-spec.js new file mode 100644 index 0000000000..8c98250982 --- /dev/null +++ b/scripts/unit/utils-spec.js @@ -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 }) + }) +}) diff --git a/scripts/utils.js b/scripts/utils.js index 7f2a15d74c..8340c6fa4d 100644 --- a/scripts/utils.js +++ b/scripts/utils.js @@ -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, }