Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
feat: initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
Seth Yates committed Apr 27, 2016
1 parent 2beff29 commit da0e882
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# common
coverage
node_modules
*.log
.DS_Store
.nyc_output
23 changes: 23 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
sudo: false

language: node_js

cache:
directories:
- node_modules

notifications:
email: false

node_js:
- 5

before_install:
- npm i -g npm@^2.0.0

before_script:
- npm prune

after_success:
- npm run coverage:upload
- npm run semantic-release
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
# condition-jenkins

[![npm version](https://badge.fury.io/js/%40krux%2Fcondition-jenkins.svg)](http://badge.fury.io/js/%40krux%2Fcondition-jenkins)
[![Build Status](https://jenkins-ci.org/krux/condition-jenkins.svg)](https://jenkins-ci.org/krux/condition-jenkins)
[![Coverage Status](https://coveralls.io/repos/krux/condition-jenkins/badge.svg?service=github)](https://coveralls.io/github/krux/condition-jenkins)

[![Dependency Status](https://david-dm.org/krux/condition-jenkins/master.svg)](https://david-dm.org/krux/condition-jenkins/master)
[![devDependency Status](https://david-dm.org/krux/condition-jenkins/master/dev-status.svg)](https://david-dm.org/krux/condition-jenkins/master#info=devDependencies)
26 changes: 26 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var SRError = require('@semantic-release/error')

module.exports = function (pluginConfig, config, cb) {
var env = config.env
var options = config.options

if (!env.hasOwnProperty('JENKINS_URL')) {
return cb(new SRError(
'semantic-release didn’t run on Jenkins CI and therefore a new version won’t be published.\n' +
'You can customize this behavior using "verifyConditions" plugins: git.io/sr-plugins',
'ENOJENKINS'
))
}

if (options.branch !== env.GIT_BRANCH) {
return cb(new SRError(
'This test run was triggered on the branch ' + env.GIT_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'
))
}

cb(null)
}
50 changes: 50 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "@krux/condition-jenkins",
"description": "make sure things only the right builds on jenkins get published",
"version": "0.0.0-placeholder",
"author": "Stephan Bönnemann <[email protected]> (http://boennemann.me)",
"bugs": {
"url": "https://github.com/krux/condition-jenkins/issues"
},
"dependencies": {
"@semantic-release/error": "^1.0.0",
"semver": "^5.0.3"
},
"devDependencies": {
"coveralls": "^2.11.2",
"nyc": "^5.0.0",
"proxyquire": "^1.7.1",
"semantic-release": "^6.0.3",
"standard": "^6.0.3",
"tap": "^5.0.0"
},
"files": [
"index.js"
],
"homepage": "https://github.com/krux/condition-jenkins#readme",
"keywords": [
"publish",
"release",
"semantic-release",
"jenkins-ci"
],
"license": "MIT",
"publishConfig": {
"access": "public",
"tag": "next"
},
"release": {
"branch": "next"
},
"repository": {
"type": "git",
"url": "https://github.com/krux/condition-jenkins.git"
},
"scripts": {
"coverage": "nyc report",
"coverage:upload": "npm run -s coverage -- --reporter=text-lcov | coveralls",
"pretest": "standard",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"test": "nyc tap --no-cov test.js"
}
}
60 changes: 60 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
var proxyquire = require('proxyquire')
var test = require('tap').test
var SRError = require('@semantic-release/error')

var condition = proxyquire('./', {})

test('raise errors in jenkins environment', function (t) {
t.test('only runs on jenkins', function (tt) {
tt.plan(2)

condition({}, {env: {}}, function (err) {
tt.ok(err instanceof SRError)
tt.is(err.code, 'ENOJENKINS')
})
})

t.test('only running on specified branch', function (tt) {
tt.plan(5)

condition({}, {
env: {
JENKINS_URL: 'http://localhost/',
GIT_BRANCH: 'origin/master'
},
options: {
branch: 'origin/master'
}
}, function (err) {
tt.is(err, null)
})

condition({}, {
env: {
JENKINS_URL: 'http://localhost/',
GIT_BRANCH: 'origin/notmaster'
},
options: {
branch: 'origin/master'
}
}, function (err) {
tt.ok(err instanceof SRError)
tt.is(err.code, 'EBRANCHMISMATCH')
})

condition({}, {
env: {
JENKINS_URL: 'http://localhost/',
GIT_BRANCH: 'origin/master'
},
options: {
branch: 'origin/foo'
}
}, function (err) {
tt.ok(err instanceof SRError)
tt.is(err.code, 'EBRANCHMISMATCH')
})
})

t.end()
})

0 comments on commit da0e882

Please sign in to comment.