This repository has been archived by the owner on Jan 10, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module.exports = { | ||
detect: function() { | ||
return !!process.env.CODEBUILD_CI | ||
}, | ||
|
||
configuration: function() { | ||
console.log(' AWS CodeBuild Detected') | ||
return { | ||
service: 'codebuild', | ||
build: process.env.CODEBUILD_BUILD_ID, | ||
job: process.env.CODEBUILD_BUILD_ID, | ||
commit: process.env.CODEBUILD_RESOLVED_SOURCE_VERSION, | ||
branch: detectBranchName(), | ||
pr: detectPRNumber(), | ||
slug: detectRepoSlug(), | ||
} | ||
function detectBranchName() { | ||
if (process.env.CODEBUILD_WEBHOOK_HEAD_REF) { | ||
return process.env.CODEBUILD_WEBHOOK_HEAD_REF.replace( | ||
/^refs\/heads\//, | ||
'' | ||
) | ||
} | ||
throw new Error('Cannot detect branch name.') | ||
} | ||
function detectPRNumber() { | ||
if (process.env.CODEBUILD_SOURCE_VERSION) { | ||
return process.env.CODEBUILD_SOURCE_VERSION.replace(/^pr\//, '') | ||
} | ||
throw new Error('Cannot detect PR number.') | ||
} | ||
function detectRepoSlug() { | ||
if (process.env.CODEBUILD_SOURCE_REPO_URL) { | ||
return process.env.CODEBUILD_SOURCE_REPO_URL.replace( | ||
/^.*github.com\//, | ||
'' | ||
).replace(/\.git$/, '') | ||
} | ||
throw new Error('Cannot detect repository slug.') | ||
} | ||
}, | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
var codebuild = require('../../lib/services/codebuild') | ||
|
||
describe('AWS CodeBuild Provider', function() { | ||
it('can detect codebuild', function() { | ||
process.env.CODEBUILD_CI = 'true' | ||
expect(codebuild.detect()).toBe(true) | ||
}) | ||
|
||
it('can get codebuild env info', function() { | ||
process.env.CODEBUILD_CI = 'true' | ||
process.env.CODEBUILD_BUILD_ID = | ||
'my-project:e016b9d9-f2c8-4749-8373-7ca673b6d969' | ||
process.env.CODEBUILD_RESOLVED_SOURCE_VERSION = | ||
'39ec2418eca4c539d765574a1c68f3bd77e8c549' | ||
process.env.CODEBUILD_WEBHOOK_HEAD_REF = 'refs/heads/master' | ||
process.env.CODEBUILD_SOURCE_VERSION = 'pr/1' | ||
process.env.CODEBUILD_SOURCE_REPO_URL = | ||
'https://github.com/my-org/my-project.git' | ||
expect(codebuild.configuration()).toEqual({ | ||
service: 'codebuild', | ||
build: 'my-project:e016b9d9-f2c8-4749-8373-7ca673b6d969', | ||
job: 'my-project:e016b9d9-f2c8-4749-8373-7ca673b6d969', | ||
commit: '39ec2418eca4c539d765574a1c68f3bd77e8c549', | ||
branch: 'master', | ||
pr: '1', | ||
slug: 'my-org/my-project', | ||
}) | ||
}) | ||
|
||
it('throws if branch name cannot be detected', function() { | ||
delete process.env.CODEBUILD_WEBHOOK_HEAD_REF | ||
expect(function() { | ||
codebuild.configuration() | ||
}).toThrow() | ||
}) | ||
|
||
it('throws if pr number cannot be detected', function() { | ||
delete process.env.CODEBUILD_SOURCE_VERSION | ||
expect(function() { | ||
codebuild.configuration() | ||
}).toThrow() | ||
}) | ||
|
||
it('throws if slug cannot be detected', function() { | ||
delete process.env.CODEBUILD_SOURCE_REPO_URL | ||
expect(function() { | ||
codebuild.configuration() | ||
}).toThrow() | ||
}) | ||
}) |