collect GitLab pipeline id and url for #2343 (#2345)

* collect GitLab pipeline id and url for #2343

* collect gitlab CI_COMMIT_REF_NAME for branch or tag name

* no need to send gitlab commit ref name

* print all API request objects without [object Object] shortcuts

* fix GitLab CI detection

* use explicit git and ci commit branch information

* update record test

* add appveyor ci branch name test
This commit is contained in:
Gleb Bahmutov
2018-08-16 12:02:01 -04:00
committed by Brian Mann
parent 3c0a8ab2e0
commit 8f0a31aaa3
6 changed files with 91 additions and 29 deletions

View File

@@ -47,8 +47,9 @@ rp = request.defaults (params = {}, callback) ->
method = params.method.toLowerCase()
# use %j argument to ensure deep nested properties are serialized
debug(
"request to url: %s with params: %o",
"request to url: %s with params: %j",
"#{params.method} #{params.url}",
_.pick(params, "body", "headers")
)

View File

@@ -219,6 +219,18 @@ updateInstance = (options = {}) ->
else
null
getCommitFromGitOrCi = (git) ->
la(check.object(git), 'expected git information object', git)
ciProvider.commitDefaults({
sha: git.sha
branch: git.branch
authorName: git.author
authorEmail: git.email
message: git.message
remoteOrigin: git.remote
defaultBranch: null
})
createRun = (options = {}) ->
_.defaults(options, {
group: null,
@@ -251,6 +263,10 @@ createRun = (options = {}) ->
specs = _.map(specs, getSpecRelativePath)
commit = getCommitFromGitOrCi(git)
debug("commit information from Git or from environment variables")
debug(commit)
makeRequest = ->
api.createRun({
specs
@@ -265,15 +281,7 @@ createRun = (options = {}) ->
params: ciProvider.ciParams()
provider: ciProvider.provider()
}
commit: ciProvider.commitDefaults({
sha: git.sha
branch: git.branch
authorName: git.author
authorEmail: git.email
message: git.message
remoteOrigin: git.remote
defaultBranch: null
})
commit
})
api.retryWithBackoff(makeRequest, { onBeforeRetry })
@@ -415,6 +423,9 @@ createRunAndRecordSpecs = (options = {}) ->
commitInfo.commitInfo(projectRoot)
.then (git) ->
debug("found the following git information")
debug(git)
platform = {
osCpus: sys.osCpus
osName: sys.osName
@@ -545,4 +556,5 @@ module.exports = {
createRunAndRecordSpecs
getCommitFromGitOrCi
}

View File

@@ -1,6 +1,7 @@
_ = require("lodash")
la = require("lazy-ass")
check = require("check-more-types")
debug = require("debug")("cypress:server")
join = (char, pieces...) ->
_.chain(pieces).compact().join(char).value()
@@ -15,7 +16,7 @@ isCodeship = ->
process.env.CI_NAME and process.env.CI_NAME is "codeship"
isGitlab = ->
process.env.GITLAB_CI or (process.env.CI_SERVER_NAME and process.env.CI_SERVER_NAME is "GitLab CI")
process.env.GITLAB_CI or (process.env.CI_SERVER_NAME and /^GitLab/.test(process.env.CI_SERVER_NAME))
isJenkins = ->
process.env.JENKINS_URL or
@@ -41,8 +42,8 @@ CI_PROVIDERS = {
"snap": "SNAP_CI"
"teamcity": "TEAMCITY_VERSION"
"teamfoundation": "TF_BUILD"
"travis": "TRAVIS"
"wercker": isWercker
"travis": "TRAVIS"
"wercker": isWercker
}
_detectProviderName = ->
@@ -114,10 +115,16 @@ _providerCiParams = ->
"DRONE_BUILD_NUMBER"
"DRONE_PULL_REQUEST"
])
# see https://docs.gitlab.com/ee/ci/variables/
gitlab: extract([
# pipeline is common among all jobs
"CI_PIPELINE_ID",
"CI_PIPELINE_URL",
# individual jobs
"CI_BUILD_ID" # build id and job id are aliases
"CI_JOB_ID"
"CI_JOB_URL"
"CI_BUILD_ID"
# other information
"GITLAB_HOST"
"CI_PROJECT_ID"
"CI_PROJECT_URL"
@@ -302,6 +309,8 @@ commitParams = ->
commitDefaults = (existingInfo) ->
commitParamsObj = commitParams() or {}
debug("commit params object")
debug(commitParamsObj)
## based on the existingInfo properties
## merge in the commitParams if null or undefined

View File

@@ -81,7 +81,7 @@
},
"dependencies": {
"@cypress/browserify-preprocessor": "1.1.0",
"@cypress/commit-info": "^1.2.2",
"@cypress/commit-info": "2.0.0",
"@cypress/icons": "0.5.4",
"@cypress/mocha-teamcity-reporter": "^1.0.0",
"@ffmpeg-installer/ffmpeg": "1.0.15",

View File

@@ -243,9 +243,14 @@ describe "lib/util/ci_provider", ->
it "gitlab", ->
process.env.GITLAB_CI = true
# Gitlab has job id and build id as synonyms
process.env.CI_BUILD_ID = "ciJobId"
process.env.CI_JOB_ID = "ciJobId"
process.env.CI_JOB_URL = "ciJobUrl"
process.env.CI_BUILD_ID = "ciBuildId"
process.env.CI_PIPELINE_ID = "ciPipelineId"
process.env.CI_PIPELINE_URL = "ciPipelineUrl"
process.env.GITLAB_HOST = "gitlabHost"
process.env.CI_PROJECT_ID = "ciProjectId"
process.env.CI_PROJECT_URL = "ciProjectUrl"
@@ -262,7 +267,9 @@ describe "lib/util/ci_provider", ->
expectsCiParams({
ciJobId: "ciJobId"
ciJobUrl: "ciJobUrl"
ciBuildId: "ciBuildId"
ciBuildId: "ciJobId"
ciPipelineId: "ciPipelineId"
ciPipelineUrl: "ciPipelineUrl"
gitlabHost: "gitlabHost"
ciProjectId: "ciProjectId"
ciProjectUrl: "ciProjectUrl"
@@ -283,6 +290,12 @@ describe "lib/util/ci_provider", ->
expectsName("gitlab")
resetEnv()
process.env.CI_SERVER_NAME = "GitLab"
expectsName("gitlab")
it "jenkins", ->
process.env.JENKINS_URL = true

View File

@@ -2,6 +2,7 @@ require("../../spec_helper")
_ = require("lodash")
os = require("os")
debug = require("debug")("test")
commitInfo = require("@cypress/commit-info")
api = require("#{root}../lib/api")
errors = require("#{root}../lib/errors")
@@ -19,43 +20,69 @@ initialEnv = _.clone(process.env)
describe "lib/modes/record", ->
## QUESTION: why are these tests here when
## this is a module... ?
context "commitInfo.getBranch", ->
context "getCommitFromGitOrCi", ->
gitCommit = {
branch: null
}
beforeEach ->
delete process.env.CIRCLE_BRANCH
delete process.env.TRAVIS_BRANCH
delete process.env.BUILDKITE_BRANCH
delete process.env.CI_BRANCH
delete process.env.CIRCLECI
delete process.env.TRAVIS
delete process.env.BUILDKITE
delete process.env.CI_NAME
delete process.env.APPVEYOR
delete process.env.APPVEYOR_REPO_BRANCH
afterEach ->
process.env = initialEnv
it "gets branch from process.env.CIRCLE_BRANCH", ->
process.env.CIRCLECI = "1"
process.env.CIRCLE_BRANCH = "bem/circle"
process.env.TRAVIS_BRANCH = "bem/travis"
process.env.CI_BRANCH = "bem/ci"
commitInfo.getBranch().then (ret) ->
expect(ret).to.eq("bem/circle")
commit = recordMode.getCommitFromGitOrCi(gitCommit)
debug(commit)
expect(commit.branch).to.eq("bem/circle")
it "gets branch from process.env.TRAVIS_BRANCH", ->
process.env.TRAVIS = "1"
process.env.TRAVIS_BRANCH = "bem/travis"
process.env.CI_BRANCH = "bem/ci"
commitInfo.getBranch().then (ret) ->
expect(ret).to.eq("bem/travis")
commit = recordMode.getCommitFromGitOrCi(gitCommit)
debug(commit)
expect(commit.branch).to.eq("bem/travis")
it "gets branch from process.env.BUILDKITE_BRANCH", ->
process.env.BUILDKITE_BRANCH = "bem/buildkite"
process.env.BUILDKITE = "1"
process.env.BUILDKITE_BRANCH = "bem/buildkite"
process.env.CI_BRANCH = "bem/ci"
commit = recordMode.getCommitFromGitOrCi(gitCommit)
debug(commit)
expect(commit.branch).to.eq("bem/buildkite")
it "gets branch from process.env.CI_BRANCH for codeship", ->
process.env.CI_NAME = "codeship"
process.env.CI_BRANCH = "bem/ci"
commitInfo.getBranch().then (ret) ->
expect(ret).to.eq("bem/buildkite")
commit = recordMode.getCommitFromGitOrCi(gitCommit)
debug(commit)
expect(commit.branch).to.eq("bem/ci")
it "gets branch from process.env.CI_BRANCH", ->
process.env.CI_BRANCH = "bem/ci"
it "gets branch from process.env.APPVEYOR_REPO_BRANCH for AppVeyor", ->
process.env.APPVEYOR = "1"
process.env.APPVEYOR_REPO_BRANCH = "bem/app"
commitInfo.getBranch().then (ret) ->
expect(ret).to.eq("bem/ci")
commit = recordMode.getCommitFromGitOrCi(gitCommit)
debug(commit)
expect(commit.branch).to.eq("bem/app")
it "gets branch from git"
# this is tested inside @cypress/commit-info