diff --git a/README.md b/README.md index 51412f3..932f8f2 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/index.js b/index.js index 0125a2b..96e8368 100644 --- a/index.js +++ b/index.js @@ -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', @@ -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( diff --git a/lib/resolve-config.js b/lib/resolve-config.js index 632766c..6359be1 100644 --- a/lib/resolve-config.js +++ b/lib/resolve-config.js @@ -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, }); diff --git a/test/condition-travis-test.js b/test/condition-travis-test.js index ad7ba49..c16d676 100644 --- a/test/condition-travis-test.js +++ b/test/condition-travis-test.js @@ -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 => { @@ -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()); }); @@ -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()); }); @@ -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()); }); @@ -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()); }); @@ -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()); }); @@ -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()); });