From 67029634830620c8795cbf1e718f59caa00a26dd Mon Sep 17 00:00:00 2001 From: Vladislav S Date: Thu, 2 Aug 2018 12:03:03 +0300 Subject: [PATCH] Add Codefresh CI --- README.md | 2 +- index.js | 12 ++++++++++++ test.js | 13 +++++++++---- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index acdbb16..6d14e59 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@   -Supports travis, circle, wercker, drone and codeship. +Supports travis, circle, wercker, drone, codeship and codefresh. Kinda supports custom CI as well. [Specs here](https://github.com/siddharthkp/ci-env/blob/master/index.js#L68-L79) diff --git a/index.js b/index.js index b7f8c41..aea5017 100644 --- a/index.js +++ b/index.js @@ -66,6 +66,18 @@ if (process.env.TRAVIS) { pull_request_number = '' ci = 'codeship' +} else if (process.env.CF_BUILD_URL) { + // https://codefresh.io/docs/docs/codefresh-yaml/variables/ + + repo = process.env.CF_REPO_OWNER + '/' + process.env.CF_REPO_NAME + + sha = process.env.CF_REVISION + event = 'push' + commit_message = process.env.CF_COMMIT_MESSAGE + pull_request_number = process.env.CF_PULL_REQUEST_NUMBER + branch = process.env.CF_BRANCH + buildUrl = process.env.CF_BUILD_URL + ci = 'codefresh' } else if (process.env.CI) { // Generic variables for docker images, custom CI builds, etc. diff --git a/test.js b/test.js index 3b98d42..f7c690d 100644 --- a/test.js +++ b/test.js @@ -11,6 +11,7 @@ if (ci) { else if (process.env.WERCKER) t.is(ci, 'wercker') else if (process.env.DRONE) t.is(ci, 'drone') else if (process.env.CI_NAME === 'codeship') t.is(ci, 'codeship') + else if (process.env.CF_BUILD_URL) t.is(ci, 'codefresh') }) test('repo is correctly set', t => t.is(repo, 'siddharthkp/ci-env')) @@ -21,7 +22,8 @@ if (ci) { process.env.TRAVIS_COMMIT || process.env.CIRCLE_SHA1 || process.env.WERCKER_GIT_COMMIT || - process.env.DRONE_COMMIT + process.env.DRONE_COMMIT || + process.env.CF_REVISION t.is(sha, real_sha) }) @@ -31,8 +33,9 @@ if (ci) { process.env.TRAVIS_COMMIT_MESSAGE || process.env.CI_COMMIT_MESSAGE || process.env.CI_MESSAGE || + process.env.CF_COMMIT_MESSAGE || '' - // Only travis and codeship set commit message + // Only travis, codefresh and codeship set commit message t.is(commit_message, real_commit_message) }) @@ -45,6 +48,7 @@ if (ci) { process.env.TRAVIS_PULL_REQUEST || process.env.DRONE_PULL_REQUEST || circlePullRequestNumber || + process.env.CF_PULL_REQUEST_NUMBER || '' // wercker does not expose pull request number t.is(pull_request_number, real_pull_request_number) @@ -53,6 +57,7 @@ if (ci) { test('buildUrl is set', t => { let real_buildUrl if (process.env.TRAVIS) real_buildUrl = `https://travis-ci.org/${repo}/builds/${process.env.TRAVIS_JOB_ID}` + if (process.env.CF_BUILD_URL) real_buildUrl = process.env.CF_BUILD_URL t.is(buildUrl, real_buildUrl) }) @@ -70,8 +75,8 @@ if (ci) { process.env.CIRCLE_BRANCH || process.env.WERCKER_GIT_BRANCH || process.env.DRONE_BRANCH || - process.env.CI_BRANCH // codeship - + process.env.CI_BRANCH || // codeship + process.env.CF_BRANCH t.is(branch, real_branch) } })