diff --git a/index.js b/index.js index ba90f2d..f7cf6b2 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,4 @@ +var semver = require('semver') var SRError = require('@semantic-release/error') module.exports = function (pluginConfig, config, cb) { @@ -19,15 +20,21 @@ module.exports = function (pluginConfig, config, cb) { )) } - if (options.branch !== env.CI_BRANCH) { + if (options.branch === env.CI_BRANCH) return cb(null) + + if (semver.valid(env.CI_BRANCH)) { return cb(new SRError( - 'This test run was triggered on the branch ' + env.CI_BRANCH + - ', while semantic-release is configured to only publish from ' + - options.branch + '.\n' + - 'You can customize this behavior using the "branch" option: git.io/sr-options', - 'EBRANCHMISMATCH' + 'This test run was triggered by a git tag that was created by semantic-release itself.\n' + + 'Everything is okay. For log output of the actual publishing process look at the build that ran before this one.', + 'EGITTAG' )) } - cb(null) + return cb(new SRError( + 'This test run was triggered on the branch ' + env.CI_BRANCH + + ', while semantic-release is configured to only publish from ' + + options.branch + '.\n' + + 'You can customize this behavior using the "branch" option: git.io/sr-options', + 'EBRANCHMISMATCH' + )) } diff --git a/package.json b/package.json index 02c5adf..3e1d094 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "url": "https://github.com/semantic-release/condition-codeship/issues" }, "dependencies": { - "@semantic-release/error": "^1.0.0" + "@semantic-release/error": "^1.0.0", + "semver": "^5.1.0" }, "devDependencies": { "coveralls": "^2.11.2", diff --git a/test.js b/test.js index 4739b57..db7b967 100644 --- a/test.js +++ b/test.js @@ -68,5 +68,19 @@ test('raise errors in codeship environment', function (t) { }) }) + t.test('not running on tags', function (tt) { + tt.plan(2) + condition({}, { + env: { + CI_NAME: 'codeship', + CI_BRANCH: 'v1.0.0' + }, + options: {} + }, function (err) { + tt.ok(err instanceof SRError) + tt.is(err.code, 'EGITTAG') + }) + }) + t.end() })