Add comment how to install pre-release version (#4647)

* WIP: post install message on commit

* linting

* finish message contents

* linting

* fix npm and binary, circleci name

* comment on CI build on AppVeyor

* remove extra build branches
This commit is contained in:
Gleb Bahmutov
2019-07-08 12:10:13 -04:00
committed by GitHub
parent 178e9bf0ab
commit e338e23e5a
6 changed files with 180 additions and 36 deletions

View File

@@ -615,6 +615,12 @@ jobs:
name: Verify Cypress binary
working_directory: /tmp/testing
command: $(npm bin)/cypress verify
- run:
name: Post pre-release install comment
command: |
node scripts/add-install-comment.js \
--npm /tmp/urls/npm-package-url.json \
--binary /tmp/urls/binary-url.json
- run:
name: Running other test projects with new NPM package and binary
command: |
@@ -790,7 +796,6 @@ linux-workflow: &linux-workflow
branches:
only:
- develop
- binary-metadata
requires:
- build
- build-binary:
@@ -798,7 +803,6 @@ linux-workflow: &linux-workflow
branches:
only:
- develop
- binary-metadata
requires:
- build
- test-binary-and-npm-against-other-projects:
@@ -806,7 +810,6 @@ linux-workflow: &linux-workflow
branches:
only:
- develop
- binary-metadata
requires:
- build-npm-package
- build-binary

View File

@@ -72,7 +72,7 @@
"@cypress/env-or-json-file": "2.0.0",
"@cypress/npm-run-all": "4.0.5",
"@cypress/questions-remain": "1.0.1",
"@cypress/github-commit-status-check": "1.4.1",
"@cypress/github-commit-status-check": "1.5.0",
"@types/bluebird": "3.5.21",
"@types/chai": "3.5.2",
"@types/debug": "4.1.4",

View File

@@ -0,0 +1,85 @@
// this build utility script posts on the commit in the default branch "develop"
// telling the user how they can install pre-release build of the Test Runner
require('@packages/coffee/register')
const la = require('lazy-ass')
const is = require('check-more-types')
const os = require('os')
const {
getNameAndBinary,
getShortCommit,
getCIName,
getCIBuildUrl,
} = require('./utils')
const { addCommitComment } = require('@cypress/github-commit-status-check')
const { stripIndent } = require('common-tags')
/* eslint-disable no-console */
const { npm, binary } = getNameAndBinary(process.argv)
la(is.unemptyString(npm), 'missing npm url')
la(is.unemptyString(binary), 'missing binary url')
const commitInfo = getShortCommit()
la(is.object(commitInfo), 'could not determine current commit information')
const { sha } = commitInfo
la(is.commitId(sha), 'could not find commit SHA')
const platform = os.platform()
const arch = os.arch()
console.log('posting pre-release instructions')
console.log(' commit:', sha)
console.log(' npm:', npm)
console.log(' binary:', binary)
console.log(' platform:', platform)
console.log(' arch:', arch)
const ciName = getCIName() || 'unknown'
const buildUrl = getCIBuildUrl()
const buildInfo = buildUrl ? `The build is [here](${buildUrl})` : ''
const instructionsAt =
'https://on.cypress.io/installing-cypress#Install-pre-release-version'
const preamble = stripIndent`
${ciName} CI has built ${platform} ${arch} version of the Test Runner. ${buildInfo}
You can install this pre-release platform-specific build using instructions at [${instructionsAt}](${instructionsAt}).
You will need to use custom \`CYPRESS_INSTALL_BINARY\` url and install Cypress using an url instead of the version.
`
const getLinuxInstallMessage = () => {
return stripIndent`
${preamble}
export CYPRESS_INSTALL_BINARY=${binary}
npm install ${npm}
`
}
const getWindowsInstallMessage = () => {
return stripIndent`
${preamble}
set CYPRESS_INSTALL_BINARY=${binary}
npm install ${binary}
`
}
const getInstallMessage = () => {
return platform === 'win32'
? getWindowsInstallMessage()
: getLinuxInstallMessage()
}
addCommitComment({
owner: 'cypress-io',
repo: 'cypress',
sha,
comment: getInstallMessage(),
}).then(() => {
console.log('Comment posted for commit %s ✅', sha)
})

View File

@@ -2,7 +2,7 @@ require('@packages/coffee/register')
const la = require('lazy-ass')
const is = require('check-more-types')
const { getNameAndBinary, getJustVersion } = require('./utils')
const { getNameAndBinary, getJustVersion, getShortCommit } = require('./utils')
const bump = require('./binary/bump')
const { stripIndent } = require('common-tags')
const os = require('os')
@@ -31,24 +31,6 @@ const cliOptions = minimist(process.argv, {
},
})
const shorten = (s) => {
return s.substr(0, 7)
}
const getShortCommit = () => {
const sha =
process.env.APPVEYOR_REPO_COMMIT ||
process.env.CIRCLE_SHA1 ||
process.env.BUILDKITE_COMMIT
if (sha) {
return {
sha,
short: shorten(sha),
}
}
}
/**
* Returns given string surrounded by ```json + ``` quotes
* @param {string} s
@@ -121,7 +103,8 @@ const getStatusAndMessage = (projectRepoName) => {
status,
})
const jsonBlock = toMarkdownJsonBlock(commitMessageInstructions)
const footer = 'Use tool `@cypress/commit-message-install` to install from above block'
const footer =
'Use tool `@cypress/commit-message-install` to install from above block'
let message = `${subject}\n\n${jsonBlock}\n${footer}\n`
if (process.env.CIRCLE_BUILD_URL) {
@@ -158,5 +141,10 @@ const onError = (e) => {
}
bump
.runTestProjects(getStatusAndMessage, cliOptions.provider, shortNpmVersion, platform)
.runTestProjects(
getStatusAndMessage,
cliOptions.provider,
shortNpmVersion,
platform
)
.catch(onError)

View File

@@ -9,10 +9,8 @@ const fs = require('fs')
function getNameAndBinary (args = process.argv) {
const options = minimist(args)
la(is.unemptyString(options.npm),
'missing --npm option', options)
la(is.unemptyString(options.binary),
'missing --binary option', options)
la(is.unemptyString(options.npm), 'missing --npm option', options)
la(is.unemptyString(options.binary), 'missing --binary option', options)
let npm = options.npm
@@ -57,7 +55,60 @@ function getJustVersion (npmNameOrUrl) {
return npmNameOrUrl
}
const shorten = (s) => {
return s.substr(0, 7)
}
/**
* Grabs the full commit SHA and its short version from CI environment variables
*/
const getShortCommit = () => {
const sha =
process.env.APPVEYOR_REPO_COMMIT ||
process.env.CIRCLE_SHA1 ||
process.env.BUILDKITE_COMMIT
if (sha) {
return {
sha,
short: shorten(sha),
}
}
}
/**
* Returns CI name for know CIs
*/
const getCIName = () => {
if (process.env.CIRCLECI) {
return 'Circle'
}
if (process.env.APPVEYOR) {
return 'AppVeyor'
}
}
/**
* Returns the current CI build url
*/
const getCIBuildUrl = () => {
if (process.env.CIRCLECI) {
// https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables
return process.env.CIRCLE_BUILD_URL
}
if (process.env.APPVEYOR) {
// https://www.appveyor.com/docs/environment-variables/
// there is no single url, but we can form one
// TODO form AppVeyor build url
}
}
module.exports = {
getNameAndBinary,
getJustVersion,
getShortCommit,
getCIName,
getCIBuildUrl,
}

View File

@@ -19,8 +19,12 @@ shell.set('-e') // any error is fatal
// https://www.appveyor.com/docs/environment-variables/
const isRightBranch = () => {
const branch = process.env.APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH || process.env.APPVEYOR_REPO_BRANCH
const shouldForceBinaryBuild = (process.env.APPVEYOR_REPO_COMMIT_MESSAGE || '').includes('[build binary]')
const branch =
process.env.APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH ||
process.env.APPVEYOR_REPO_BRANCH
const shouldForceBinaryBuild = (
process.env.APPVEYOR_REPO_COMMIT_MESSAGE || ''
).includes('[build binary]')
return branch === 'develop' || shouldForceBinaryBuild
}
@@ -49,7 +53,9 @@ la(is.unemptyString(version), 'missing NEXT_DEV_VERSION')
console.log('building version', version)
shell.exec(`node scripts/binary.js upload-npm-package --file cli/build/${filename} --version ${version}`)
shell.exec(
`node scripts/binary.js upload-npm-package --file cli/build/${filename} --version ${version}`
)
const arch = os.arch()
@@ -64,11 +70,15 @@ const serverPackageFolder = 'C:/projects/cypress/dist/win32/packages/server'
shell.echo(`Checking prod and dev dependencies in ${serverPackageFolder}`)
shell.exec('npm ls --prod --depth 0 || true', { cwd: serverPackageFolder })
const result = shell.exec('npm ls --dev --depth 0 || true', { cwd: serverPackageFolder })
const result = shell.exec('npm ls --dev --depth 0 || true', {
cwd: serverPackageFolder,
})
if (result.stdout.includes('nodemon')) {
console.error('Hmm, server package includes dev dependency "coveralls"')
console.error('which means somehow we are including dev dependencies in the output bundle')
console.error(
'which means somehow we are including dev dependencies in the output bundle'
)
console.error('see https://github.com/cypress-io/cypress/issues/2896')
process.exit(1)
}
@@ -103,7 +113,14 @@ if (isPullRequest()) {
shell.exec('npm run binary-zip')
shell.ls('-l', '*.zip')
shell.exec(`node scripts/binary.js upload-unique-binary --file cypress.zip --version ${version}`)
shell.exec(
`node scripts/binary.js upload-unique-binary --file cypress.zip --version ${version}`
)
shell.cat('binary-url.json')
shell.exec('node scripts/test-other-projects.js --npm npm-package-url.json --binary binary-url.json --provider appVeyor')
shell.exec(
'node scripts/add-install-comment.js --npm npm-package-url.json --binary binary-url.json'
)
shell.exec(
'node scripts/test-other-projects.js --npm npm-package-url.json --binary binary-url.json --provider appVeyor'
)
}