Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Add retro-compatibility for Semaphore 1.x and maintain support for 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiendem committed Sep 10, 2019
1 parent a45a9b5 commit 5a5c489
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ var services = {
wercker: require('./services/wercker'),
jenkins: require('./services/jenkins'),
semaphore: require('./services/semaphore'),
semaphore2x: require('./services/semaphore2x'),
snap: require('./services/snap'),
gitlab: require('./services/gitlab'),
heroku: require('./services/heroku'),
teamcity: require('./services/teamcity')
teamcity: require('./services/teamcity'),
}

var detectProvider = function() {
Expand Down
6 changes: 3 additions & 3 deletions lib/services/semaphore.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module.exports = {
detect: function() {
return !!process.env.SEMAPHORE
return !!process.env.SEMAPHORE && !!process.env.SEMAPHORE_REPO_SLUG
},

configuration: function() {
console.log(' Semaphore CI Detected')
console.log(' Semaphore 1.x CI Detected')
return {
service: 'semaphore',
service: 'semaphore1x',
build:
process.env.SEMAPHORE_BUILD_NUMBER +
'.' +
Expand Down
15 changes: 15 additions & 0 deletions lib/services/semaphore2x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
detect: function() {
return !!process.env.SEMAPHORE && !!process.env.SEMAPHORE_WORKFLOW_ID
},

configuration: function() {
console.log(' Semaphore 2.x CI Detected')
return {
service: 'semaphore2x',
branch: process.env.SEMAPHORE_GIT_BRANCH,
build: process.env.SEMAPHORE_WORKFLOW_ID,
commit: process.env.SEMAPHORE_GIT_SHA,
}
},
}
19 changes: 18 additions & 1 deletion test/services/semaphore.test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
var semaphore = require('../../lib/services/semaphore')

describe('Semaphore CI Provider', function() {
var OLD_ENV = process.env

beforeEach(function() {
process.env = Object.assign({}, OLD_ENV)
})

afterEach(function() {
process.env = Object.assign({}, OLD_ENV)
})

it('can detect semaphore', function() {
process.env.SEMAPHORE = 'true'
process.env.SEMAPHORE_REPO_SLUG = 'owner/repo'
expect(semaphore.detect()).toBe(true)
})

it('does not detect semaphore 2.x', function() {
process.env.SEMAPHORE = 'true'
process.env.SEMAPHORE_WORKFLOW_ID = '65c9bb1c-aeb6-41f0-b8d9-6fa177241cdf'
expect(semaphore.detect()).toBe(false)
})

it('can get semaphore env info', function() {
process.env.SEMAPHORE_BUILD_NUMBER = '1234'
process.env.REVISION = '5678'
process.env.SEMAPHORE_CURRENT_THREAD = '1'
process.env.BRANCH_NAME = 'master'
process.env.SEMAPHORE_REPO_SLUG = 'owner/repo'
expect(semaphore.configuration()).toEqual({
service: 'semaphore',
service: 'semaphore1x',
commit: '5678',
build: '1234.1',
branch: 'master',
Expand Down
37 changes: 37 additions & 0 deletions test/services/semaphore2x.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
var semaphore = require('../../lib/services/semaphore2x')

describe('Semaphore 2.x CI Provider', function() {
var OLD_ENV = process.env

beforeEach(function() {
process.env = Object.assign({}, OLD_ENV)
})

afterEach(function() {
process.env = Object.assign({}, OLD_ENV)
})

it('can detect semaphore 2x', function() {
process.env.SEMAPHORE = 'true'
process.env.SEMAPHORE_WORKFLOW_ID = '65c9bb1c-aeb6-41f0-b8d9-6fa177241cdf'
expect(semaphore.detect()).toBe(true)
})

it('does not detect semaphore 1.x', function() {
process.env.SEMAPHORE = 'true'
process.env.SEMAPHORE_REPO_SLUG = 'owner/repo'
expect(semaphore.detect()).toBe(false)
})

it('can get semaphore env info', function() {
process.env.SEMAPHORE_GIT_BRANCH = 'development'
process.env.SEMAPHORE_GIT_SHA = '5c84719708b9b649b9ef3b56af214f38cee6acde'
process.env.SEMAPHORE_WORKFLOW_ID = '65c9bb1c-aeb6-41f0-b8d9-6fa177241cdf'
expect(semaphore.configuration()).toEqual({
service: 'semaphore2x',
branch: 'development',
build: '65c9bb1c-aeb6-41f0-b8d9-6fa177241cdf',
commit: '5c84719708b9b649b9ef3b56af214f38cee6acde',
})
})
})

0 comments on commit 5a5c489

Please sign in to comment.