From f6233af8a768b44e0e754c8af51417d4dd9ec842 Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Wed, 17 Feb 2021 14:08:51 -0500 Subject: [PATCH] feat: send CI variables for CloudFresh (#15117) --- packages/server/__snapshots__/cypress_spec.js | 3 ++ packages/server/lib/util/ci_provider.js | 21 +++++++++ packages/server/test/unit/ci_provider_spec.js | 46 +++++++++++++++++++ 3 files changed, 70 insertions(+) diff --git a/packages/server/__snapshots__/cypress_spec.js b/packages/server/__snapshots__/cypress_spec.js index f25827837ee3..fc962c31457e 100644 --- a/packages/server/__snapshots__/cypress_spec.js +++ b/packages/server/__snapshots__/cypress_spec.js @@ -68,6 +68,7 @@ The ciBuildId is automatically detected if you are running Cypress in any of the - codeshipBasic - codeshipPro - concourse +- codeFresh - drone - githubActions - gitlab @@ -104,6 +105,7 @@ The ciBuildId is automatically detected if you are running Cypress in any of the - codeshipBasic - codeshipPro - concourse +- codeFresh - drone - githubActions - gitlab @@ -141,6 +143,7 @@ The ciBuildId is automatically detected if you are running Cypress in any of the - codeshipBasic - codeshipPro - concourse +- codeFresh - drone - githubActions - gitlab diff --git a/packages/server/lib/util/ci_provider.js b/packages/server/lib/util/ci_provider.js index 275b34cc5099..7c57b713244a 100644 --- a/packages/server/lib/util/ci_provider.js +++ b/packages/server/lib/util/ci_provider.js @@ -96,6 +96,7 @@ const CI_PROVIDERS = { 'codeshipBasic': isCodeshipBasic, 'codeshipPro': isCodeshipPro, 'concourse': isConcourse, + codeFresh: 'CF_BUILD_ID', 'drone': 'DRONE', githubActions: 'GITHUB_ACTIONS', 'gitlab': isGitlab, @@ -218,6 +219,20 @@ const _providerCiParams = () => { 'BUILD_TEAM_NAME', 'ATC_EXTERNAL_URL', ]), + // https://codefresh.io/docs/docs/codefresh-yaml/variables/ + codeFresh: extract([ + 'CF_BUILD_ID', + 'CF_BUILD_URL', + 'CF_CURRENT_ATTEMPT', + 'CF_STEP_NAME', + 'CF_PIPELINE_NAME', + 'CF_PIPELINE_TRIGGER_ID', + // variables added for pull requests + 'CF_PULL_REQUEST_ID', + 'CF_PULL_REQUEST_IS_FORK', + 'CF_PULL_REQUEST_NUMBER', + 'CF_PULL_REQUEST_TARGET', + ]), drone: extract([ 'DRONE_JOB_NUMBER', 'DRONE_BUILD_LINK', @@ -465,6 +480,12 @@ const _providerCommitParams = () => { // remoteOrigin: ??? // defaultBranch: ??? }, + codeFresh: { + sha: env.CF_REVISION, + branch: env.CF_BRANCH, + message: env.CF_COMMIT_MESSAGE, + authorName: env.CF_COMMIT_AUTHOR, + }, drone: { sha: env.DRONE_COMMIT_SHA, branch: env.DRONE_COMMIT_BRANCH, diff --git a/packages/server/test/unit/ci_provider_spec.js b/packages/server/test/unit/ci_provider_spec.js index 343b86a09d93..c350739ca12a 100644 --- a/packages/server/test/unit/ci_provider_spec.js +++ b/packages/server/test/unit/ci_provider_spec.js @@ -458,6 +458,52 @@ describe('lib/util/ci_provider', () => { return expectsCommitParams(null) }) + it('codeFresh', () => { + resetEnv = mockedEnv({ + // build information + 'CF_BUILD_ID': 'cfBuildId', + 'CF_BUILD_URL': 'cfBuildUrl', + 'CF_CURRENT_ATTEMPT': 'cfCurrentAttempt', + 'CF_STEP_NAME': 'cfStepName', + 'CF_PIPELINE_NAME': 'cfPipelineName', + 'CF_PIPELINE_TRIGGER_ID': 'cfPipelineTriggerId', + + // variables added for pull requests + 'CF_PULL_REQUEST_ID': 'cfPullRequestId', + 'CF_PULL_REQUEST_IS_FORK': 'cfPullRequestIsFork', + 'CF_PULL_REQUEST_NUMBER': 'cfPullRequestNumber', + 'CF_PULL_REQUEST_TARGET': 'cfPullRequestTarget', + + // git information + CF_REVISION: 'cfRevision', + CF_BRANCH: 'cfBranch', + CF_COMMIT_MESSAGE: 'cfCommitMessage', + CF_COMMIT_AUTHOR: 'cfCommitAuthor', + }, { clear: true }) + + expectsName('codeFresh') + expectsCiParams({ + cfBuildId: 'cfBuildId', + cfBuildUrl: 'cfBuildUrl', + cfCurrentAttempt: 'cfCurrentAttempt', + cfStepName: 'cfStepName', + cfPipelineName: 'cfPipelineName', + cfPipelineTriggerId: 'cfPipelineTriggerId', + // pull request variables + cfPullRequestId: 'cfPullRequestId', + cfPullRequestIsFork: 'cfPullRequestIsFork', + cfPullRequestNumber: 'cfPullRequestNumber', + cfPullRequestTarget: 'cfPullRequestTarget', + }) + + expectsCommitParams({ + sha: 'cfRevision', + branch: 'cfBranch', + message: 'cfCommitMessage', + authorName: 'cfCommitAuthor', + }) + }) + it('drone', () => { resetEnv = mockedEnv({ DRONE: 'true',