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

Commit

Permalink
feat: add support for Travis Enterprise
Browse files Browse the repository at this point in the history
Pass on `travisUrl` as `travisOpts` to `travisDeployOnce`

Fixes #100
  • Loading branch information
SimenB authored and pvdlg committed Dec 11, 2017
1 parent 425ab7a commit 0016a62
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ Verify that `semantic-release` is running:
| `githubToken` | **Required.** The Github token used to authenticate with Travis API. | `process.env.GH_TOKEN` or `process.env.GITHUB_TOKEN` |
| `githubUrl` | The GitHub Enterprise endpoint. | `process.env.GH_URL` or `process.env.GITHUB_URL` |
| `githubApiPathPrefix` | The GitHub Enterprise API prefix. | `process.env.GH_PREFIX` or `process.env.GITHUB_PREFIX` |
| `travisUrl` | The Travis Enterprise endpoint. | `process.env.TRAVIS_URL` |

## Configuration

The plugin is used by default by [semantic-release](https://github.com/semantic-release/semantic-release) so no specific configuration is requiered if `githubToken`, `githubUrl` and `githubApiPathPrefix` are set via environment variable.
The plugin is used by default by [semantic-release](https://github.com/semantic-release/semantic-release) so no specific configuration is required if `githubToken`, `githubUrl`, `githubApiPathPrefix` and `travisUrl` are set via environment variable.

## Travis configuration

Expand All @@ -42,7 +43,7 @@ after_success:
### With multiple jobs on different Node versions and OS
If there is multiple Node version and OS configured, [travis-deploy-once](https://github.com/semantic-release/travis-deploy-once) will guarantee that `semantic-release` is executed on the highest Node version, after all other jobs are successful, without any additionnal configurations.
If there are multiple Node versions and OSs configured, [travis-deploy-once](https://github.com/semantic-release/travis-deploy-once) will guarantee that `semantic-release` is executed on the highest Node version, after all other jobs are successful, without any additional configurations.

```yml
language: node_js
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const SemanticReleaseError = require('@semantic-release/error');
const resolveConfig = require('./lib/resolve-config');

module.exports = async function(pluginConfig, {options: {branch, repositoryUrl}}) {
const {githubToken, githubUrl, githubApiPathPrefix} = resolveConfig(pluginConfig);
const {githubToken, githubUrl, githubApiPathPrefix, travisUrl} = resolveConfig(pluginConfig);
if (process.env.TRAVIS !== 'true') {
throw new SemanticReleaseError(
'semantic-release didn’t run on Travis CI and therefore a new version won’t be published.\nYou can customize this behavior using "verifyConditions" plugins: git.io/sr-plugins',
Expand Down Expand Up @@ -46,7 +46,7 @@ module.exports = async function(pluginConfig, {options: {branch, repositoryUrl}}

const {data: {private: pro}} = await github.repos.get({owner, repo});

const result = await deployOnce({travisOpts: {pro}});
const result = await deployOnce({travisOpts: {pro, enterprise: travisUrl}});

if (result === null) {
throw new SemanticReleaseError(
Expand Down
3 changes: 2 additions & 1 deletion lib/resolve-config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = ({githubToken, githubUrl, githubApiPathPrefix}) => ({
module.exports = ({githubToken, githubUrl, githubApiPathPrefix, travisUrl}) => ({
githubToken: githubToken || process.env.GH_TOKEN || process.env.GITHUB_TOKEN,
githubUrl: githubUrl || process.env.GH_URL || process.env.GITHUB_URL,
githubApiPathPrefix: githubApiPathPrefix || process.env.GH_PREFIX || process.env.GITHUB_PREFIX,
travisUrl: travisUrl || process.env.TRAVIS_URL,
});
39 changes: 32 additions & 7 deletions test/condition-travis-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test.beforeEach(t => {
delete process.env.TRAVIS;
delete process.env.TRAVIS_PULL_REQUEST;
delete process.env.TRAVIS_BRANCH;
delete process.env.TRAVIS;
delete process.env.TRAVIS_URL;
});

test.afterEach.always(t => {
Expand Down Expand Up @@ -98,7 +98,7 @@ test.serial('travis-deploy-once resolves with true', async t => {

t.falsy(result);
t.true(travisDeployOnce.calledOnce);
t.deepEqual(travisDeployOnce.firstCall.args[0], {travisOpts: {pro}});
t.deepEqual(travisDeployOnce.firstCall.args[0], {travisOpts: {pro, enterprise: undefined}});
t.true(github.isDone());
});

Expand All @@ -122,7 +122,7 @@ test.serial('travis-deploy-once resolves with null', async t => {
t.true(error instanceof SemanticReleaseError);
t.is(error.code, 'ENOBUILDLEADER');
t.true(travisDeployOnce.calledOnce);
t.deepEqual(travisDeployOnce.firstCall.args[0], {travisOpts: {pro}});
t.deepEqual(travisDeployOnce.firstCall.args[0], {travisOpts: {pro, enterprise: undefined}});
t.true(github.isDone());
});

Expand All @@ -146,7 +146,7 @@ test.serial('travis-deploy-once resolves with false', async t => {
t.true(error instanceof SemanticReleaseError);
t.is(error.code, 'EOTHERSFAILED');
t.true(travisDeployOnce.calledOnce);
t.deepEqual(travisDeployOnce.firstCall.args[0], {travisOpts: {pro}});
t.deepEqual(travisDeployOnce.firstCall.args[0], {travisOpts: {pro, enterprise: undefined}});
t.true(github.isDone());
});

Expand All @@ -173,7 +173,7 @@ test.serial('travis-deploy-once rejects with error', async t => {
t.true(error instanceof Error);
t.is(error.message, 'travis-deploy-once error');
t.true(travisDeployOnce.calledOnce);
t.deepEqual(travisDeployOnce.firstCall.args[0], {travisOpts: {pro}});
t.deepEqual(travisDeployOnce.firstCall.args[0], {travisOpts: {pro, enterprise: undefined}});
t.true(github.isDone());
});

Expand Down Expand Up @@ -234,7 +234,7 @@ test.serial('Calls travis-run-once with pro parameter determined by github call'

t.falsy(result);
t.true(travisDeployOnce.calledOnce);
t.deepEqual(travisDeployOnce.firstCall.args[0], {travisOpts: {pro}});
t.deepEqual(travisDeployOnce.firstCall.args[0], {travisOpts: {pro, enterprise: undefined}});
t.true(github.isDone());
});

Expand All @@ -259,6 +259,31 @@ test.serial('Calls travis-run-once with pro parameter determined by github call

t.falsy(result);
t.true(travisDeployOnce.calledOnce);
t.deepEqual(travisDeployOnce.firstCall.args[0], {travisOpts: {pro}});
t.deepEqual(travisDeployOnce.firstCall.args[0], {travisOpts: {pro, enterprise: undefined}});
t.true(github.isDone());
});

test.serial('Calls travis-run-once with enterprise parameter', async t => {
const travisDeployOnce = stub().resolves(true);
const condition = proxyquire('../', {'travis-deploy-once': travisDeployOnce});
const owner = 'test_user';
const repo = 'test_repo';
const githubToken = 'github_token';
const pro = false;
const travisUrl = 'https://travis.example.com';
const github = authenticate({githubToken})
.get(`/repos/${owner}/${repo}`)
.reply(200, {private: pro});
process.env.TRAVIS = 'true';
process.env.TRAVIS_BRANCH = 'master';

const result = await condition(
{githubToken, travisUrl},
{options: {branch: 'master', repositoryUrl: `git+https://github.com/${owner}/${repo}.git`}}
);

t.falsy(result);
t.true(travisDeployOnce.calledOnce);
t.deepEqual(travisDeployOnce.firstCall.args[0], {travisOpts: {pro, enterprise: travisUrl}});
t.true(github.isDone());
});

0 comments on commit 0016a62

Please sign in to comment.