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

Commit

Permalink
Merge pull request #145 from fabiendem/semaphore-compat
Browse files Browse the repository at this point in the history
Add retro-compatibility for Semaphore 1.x and maintain support for 2.x
  • Loading branch information
eddiemoore authored Sep 20, 2019
2 parents 8371836 + 0c57093 commit f628c33
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 14 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
16 changes: 10 additions & 6 deletions lib/services/semaphore.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
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',
branch: process.env.SEMAPHORE_GIT_BRANCH,
build: process.env.SEMAPHORE_WORKFLOW_ID,
commit: process.env.SEMAPHORE_GIT_SHA,
service: 'semaphore1x',
build:
process.env.SEMAPHORE_BUILD_NUMBER +
'.' +
process.env.SEMAPHORE_CURRENT_THREAD,
commit: process.env.REVISION,
branch: process.env.BRANCH_NAME,
slug: process.env.SEMAPHORE_REPO_SLUG,
}
},
}
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,
}
},
}
34 changes: 27 additions & 7 deletions test/services/semaphore.test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
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('can get semaphore env info', function() {
process.env.SEMAPHORE_GIT_BRANCH = 'development'
process.env.SEMAPHORE_GIT_SHA = '5c84719708b9b649b9ef3b56af214f38cee6acde'
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',
branch: 'development',
build: '65c9bb1c-aeb6-41f0-b8d9-6fa177241cdf',
commit: '5c84719708b9b649b9ef3b56af214f38cee6acde',
service: 'semaphore1x',
commit: '5678',
build: '1234.1',
branch: 'master',
slug: 'owner/repo',
})
})
})
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 semaphore2 = 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(semaphore2.detect()).toBe(true)
})

it('does not detect semaphore 1.x', function() {
process.env.SEMAPHORE = 'true'
process.env.SEMAPHORE_REPO_SLUG = 'owner/repo'
expect(semaphore2.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(semaphore2.configuration()).toEqual({
service: 'semaphore2x',
branch: 'development',
build: '65c9bb1c-aeb6-41f0-b8d9-6fa177241cdf',
commit: '5c84719708b9b649b9ef3b56af214f38cee6acde',
})
})
})

0 comments on commit f628c33

Please sign in to comment.