From 9cfb4967c7d80acccd9f06bc890f253953060592 Mon Sep 17 00:00:00 2001 From: Tristan Davey Date: Wed, 2 May 2018 06:58:27 +1000 Subject: [PATCH] Add buildkite support (#177) * Add buildkite support * Add committer name, email, commit message and pull request number * Add buildkite to support CIs in README.md --- README.md | 2 +- lib/getOptions.js | 15 ++++++++++++++- test/getOptions.js | 30 ++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index df52f416..46acc078 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [Coveralls.io](https://coveralls.io/) support for node.js. Get the great coverage reporting of coveralls.io and add a cool coverage button ( like the one above ) to your README. -Supported CI services: [travis-ci](https://travis-ci.org/), [codeship](https://www.codeship.io/), [circleci](https://circleci.com/), [jenkins](http://jenkins-ci.org/), [Gitlab CI](http://gitlab.com/), [AppVeyor](http://appveyor.com/) +Supported CI services: [travis-ci](https://travis-ci.org/), [codeship](https://www.codeship.io/), [circleci](https://circleci.com/), [jenkins](http://jenkins-ci.org/), [Gitlab CI](http://gitlab.com/), [AppVeyor](http://appveyor.com/), [Buildkite](https://buildkite.com/) ## Installation: Add the latest version of `coveralls` to your package.json: diff --git a/lib/getOptions.js b/lib/getOptions.js index 2030f6c5..d30020fc 100644 --- a/lib/getOptions.js +++ b/lib/getOptions.js @@ -25,7 +25,6 @@ var getBaseOptions = function(cb){ git_branch = process.env.TRAVIS_BRANCH; } - if (process.env.DRONE){ options.service_name = 'drone'; options.service_job_id = process.env.DRONE_BUILD_NUMBER; @@ -93,12 +92,26 @@ var getBaseOptions = function(cb){ git_commit = process.env.SURF_SHA1; git_branch = process.env.SURF_REF; } + + if(process.env.BUILDKITE){ + options.service_name = 'buildkite'; + options.service_job_number = process.env.BUILDKITE_BUILD_NUMBER; + options.service_job_id = process.env.BUILDKITE_BUILD_ID; + options.service_pull_request = process.env.BUILDKITE_PULL_REQUEST; + git_commit = process.env.BUILDKITE_COMMIT; + git_branch = process.env.BUILDKITE_BRANCH; + git_committer_name = process.env.BUILDKITE_BUILD_CREATOR; + git_committer_email = process.env.BUILDKITE_BUILD_CREATOR_EMAIL; + git_message = process.env.BUILDKITE_MESSAGE; + } + if(process.env.SEMAPHORE){ options.service_name = 'semaphore'; options.service_job_id = process.env.SEMAPHORE_BUILD_NUMBER; git_commit = process.env.REVISION; git_branch = process.env.BRANCH_NAME; } + options.run_at = process.env.COVERALLS_RUN_AT || JSON.stringify(new Date()).slice(1, -1); if (process.env.COVERALLS_SERVICE_NAME){ options.service_name = process.env.COVERALLS_SERVICE_NAME; diff --git a/test/getOptions.js b/test/getOptions.js index 9602d765..dd70a9b6 100644 --- a/test/getOptions.js +++ b/test/getOptions.js @@ -55,6 +55,9 @@ describe("getBaseOptions", function(){ it ("should set service_name and service_job_id if it's running on wercker", function(done){ testWercker(getBaseOptions, done); }); + it ("should set service_name and service_job_id if it's running on Buildkite", function(done){ + testBuildkite(getBaseOptions, done); + }); }); describe("getOptions", function(){ @@ -143,6 +146,9 @@ describe("getOptions", function(){ it ("should set service_name and service_job_id if it's running via Surf", function(done){ testSurf(getOptions, done); }); + it ("should set service_name and service_job_id if it's running via Buildkite", function(done){ + testBuildkite(getOptions, done); + }); it ("should set service_name and service_job_id if it's running via Semaphore", function(done){ testSemaphore(getOptions, done); }); @@ -448,6 +454,30 @@ var testSurf = function(sut, done) { }); }; +var testBuildkite = function(sut, done) { + process.env.BUILDKITE = true; + process.env.BUILDKITE_BUILD_NUMBER = "1234"; + process.env.BUILDKITE_COMMIT = "e3e3e3e3e3e3e3e3e"; + process.env.BUILDKITE_BRANCH = "feature"; + process.env.BUILDKITE_BUILD_CREATOR = 'john doe'; + process.env.BUILDKITE_BUILD_CREATOR_EMAIL = 'john@doe.com'; + process.env.BUILDKITE_MESSAGE = 'msgmsgmsg'; + sut(function(err, options){ + options.service_name.should.equal("buildkite"); + options.git.should.eql({ head: + { id: 'e3e3e3e3e3e3e3e3e', + author_name: 'Unknown Author', + author_email: '', + committer_name: 'john doe', + committer_email: 'john@doe.com', + message: 'msgmsgmsg' }, + branch: 'feature', + remotes: [] }); + done(); + }); +}; + + var testSemaphore = function(sut, done) { process.env.SEMAPHORE = true; process.env.SEMAPHORE_BUILD_NUMBER = '1234';