Skip to content

Commit

Permalink
Merge pull request #35 from holidayextras/ci-skip
Browse files Browse the repository at this point in the history
skip ci on automated commit
  • Loading branch information
hxpaul authored Dec 20, 2017
2 parents 7bf1794 + 3bc7457 commit 9787432
Show file tree
Hide file tree
Showing 4 changed files with 257 additions and 17 deletions.
7 changes: 4 additions & 3 deletions nodeApps/generateSignedFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ const addProductionFile = addFile.bind(null, `${distPath}/${name}.min.${version}
const addChangelog = addFile.bind(null, 'CHANGELOG.md')

const commit = callback => {
let message = ':airplane: Release via CI build -ci'
let message = ':airplane: Release via CI build '
if (process.env.CIRCLE_BUILD_NUM) {
message = message + ` [${process.env.CIRCLE_BUILD_NUM}](https://circleci.com/gh/${process.env.npm_package_name}/${process.env.CIRCLE_BUILD_NUM})`
message = message + `[${process.env.CIRCLE_BUILD_NUM}](https://circleci.com/gh/${process.env.npm_package_name}/${process.env.CIRCLE_BUILD_NUM})`
} else if (process.env.TRAVIS_JOB_NUMBER) {
message = message + ` [${process.env.TRAVIS_JOB_ID}](https://travis-ci.com/${process.env.npm_package_name}/jobs/${process.env.TRAVIS_JOB_ID})`
message = message + `[${process.env.TRAVIS_JOB_ID}](https://travis-ci.com/${process.env.npm_package_name}/jobs/${process.env.TRAVIS_JOB_ID})`
}
message = message + '\n\n[skip ci]'
git.commit(message, (err, result) => {
callback(err)
})
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "deployment-helpers",
"version": "1.8.1",
"version": "1.8.2",
"description": "A collection of scripts that can be used as part of a deployment process.",
"main": "src/utils",
"bin": {
Expand All @@ -24,10 +24,10 @@
"html",
"text"
],
"statements": 10,
"lines": 10,
"branches": 10,
"functions": 10,
"statements": 90,
"lines": 90,
"branches": 60,
"functions": 90,
"exclude": [
"coverage",
"nodeApps"
Expand Down
6 changes: 3 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ utils.name = process.env.npm_package_name
utils.ownerAndName = `holidayextras/${utils.name}`
utils.distFolder = process.env.DIST_FOLDER || 'dist'
const repo = ('' + process.env.npm_package_repository_url).split('/')
/* istanbul ignore else */
if (repo.pop() === `${utils.name}.git`) {
utils.ownerAndName = `${repo.pop()}/${utils.name}`
}
Expand Down Expand Up @@ -108,7 +109,7 @@ utils.getCommitMessagesSinceLastRelease = callback => {
}

utils.tagVersion = (tag, notes, callback) => {
let message = ':airplane: Release via CI build (skip ci)'
let message = ':airplane: Release via CI build '
if (process.env.CIRCLE_BUILD_NUM) {
message = message + `[${process.env.CIRCLE_BUILD_NUM}](https://circleci.com/gh/${utils.ownerAndName}/${process.env.CIRCLE_BUILD_NUM})`
} else if (process.env.TRAVIS_JOB_NUMBER) {
Expand All @@ -127,7 +128,6 @@ utils.tagVersion = (tag, notes, callback) => {
}
const releaseJSON = JSON.stringify(release).replace(/'/g, '')
const cmd = `curl ${credentials} --data '${releaseJSON}' https://api.github.com/repos/${utils.ownerAndName}/releases`
console.log('cmd is', cmd)
utils.exec(cmd, err => {
if (err) console.warn(err)
callback()
Expand Down Expand Up @@ -178,7 +178,7 @@ utils.reportSize = (size, previousSize, callback) => {
console.warn(`⚠️ file size has gone up from ${previousSize} to ${size} bytes`)
if (delta > 1) console.warn('🙀 this is more than 1% increase!')
} else if (delta < -1) {
console.log('🐭 good file size reducing!')
console.info('🐭 good file size reducing!')
}
callback()
}
Expand Down
251 changes: 245 additions & 6 deletions test/unit/utilsTest.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const utils = require('../../src/utils')
const async = require('async')
const childProcess = require('child_process')
// const git = require('simple-git')()

describe('utils', function () {
let callback = null
Expand Down Expand Up @@ -162,23 +161,263 @@ describe('utils', function () {
})
})

describe('getCommitMessagesSinceLastRelease', function () {
describe('getEmail', function () {
it('does not throw', function () {
expect(function () {
utils.getEmail(callback)
}).not.to.throw()
})
})

describe('setEmail', function () {
describe('with email', function () {
it('does not throw', function () {
expect(function () {
utils.setEmail('EMAIL', callback)
}).not.to.throw()
})
})

describe('without email', function () {
it('does not throw', function () {
expect(function () {
utils.setEmail(null, callback)
}).not.to.throw()
})
})
})

describe('getUser', function () {
it('does not throw', function () {
expect(function () {
utils.getUser(callback)
}).not.to.throw()
})
})

describe('setUser', function () {
describe('with user', function () {
it('does not throw', function () {
expect(function () {
utils.setUser('USER', callback)
}).not.to.throw()
})
})

describe('without user', function () {
it('does not throw', function () {
expect(function () {
utils.setUser(null, callback)
}).not.to.throw()
})
})
})

describe('getBranch', function () {
it('does not throw', function () {
expect(function () {
utils.getBranch(callback)
}).not.to.throw()
})
})

describe('checkBranch', function () {
beforeEach(function () {
sandbox.stub(utils, 'getBranch').yields(null, 'foo')
})

describe('when branch matches', function () {
beforeEach(function () {
utils.checkBranch('foo', callback)
})

it('yields', function () {
expect(callback).to.have.been.calledOnce()
.and.calledWithExactly()
})
})

describe('when branch does not match', function () {
beforeEach(function () {
utils.checkBranch('bar', callback)
})

it('yields an error', function () {
expect(callback).to.have.been.calledOnce()
.and.calledWithExactly(sandbox.match.string)
})
})
})

describe('checkAlreadyReleased', function () {
let version = null

beforeEach(function () {
version = utils.versionTag
utils.versionTag = 'VERSION'
sandbox.stub(utils, 'exec').yields()
})

describe('something', function () {
afterEach(function () {
utils.versionTag = version
})

describe('when an error', function () {
beforeEach(function () {
utils.getCommitMessagesSinceLastRelease(callback)
utils.exec.yields('oops')
utils.checkAlreadyReleased(callback)
})

it('calls exec', function () {
expect(utils.exec).to.have.been.calledOnce()
it('yields the error', function () {
expect(callback).to.have.been.calledOnce()
.and.calledWithExactly('oops')
})
})

describe('when already released', function () {
beforeEach(function () {
utils.exec.yields(null, 'VERSION\n')
utils.checkAlreadyReleased(callback)
})

it('yields the error', function () {
expect(callback).to.have.been.calledOnce()
.and.calledWithExactly(sandbox.match.string)
})
})

describe('when not already released', function () {
beforeEach(function () {
utils.exec.yields(null, 'TAG\n')
utils.checkAlreadyReleased(callback)
})

it('yields', function () {
expect(callback).to.have.been.calledOnce()
.and.calledWithExactly()
})
})
})

describe('getCommitMessagesSinceLastRelease', function () {
beforeEach(function () {
sandbox.stub(utils, 'exec').yields()
utils.getCommitMessagesSinceLastRelease(callback)
})

it('calls exec', function () {
expect(utils.exec).to.have.been.calledOnce()
})

it('yields', function () {
expect(callback).to.have.been.calledOnce()
})
})

describe('tagVersion', function () {
it('does not throw', function () {
expect(function () {
utils.tagVersion('foo', 'bar', callback)
}).not.to.throw()
})
})

describe('deleteTag', function () {
it('does not throw', function () {
expect(function () {
utils.deleteTag('foo', callback)
}).not.to.throw()
})
})

describe('confirmOnFeatureBranch', function () {
it('does not throw', function () {
expect(function () {
utils.confirmOnFeatureBranch(callback)
}).not.to.throw()
})
})

describe('getSize', function () {
it('does not throw', function () {
expect(function () {
utils.getSize('FILE', callback)
}).not.to.throw()
})
})

describe('reportSize', function () {
beforeEach(function () {
sandbox.stub(console, 'info')
sandbox.stub(console, 'warn')
})

describe('when size is sligthly smaller', function () {
beforeEach(function () {
utils.reportSize(666, 667, callback)
})

it('does not log it', function () {
expect(console.info).not.to.have.been.called()
})

it('does not warn us', function () {
expect(console.warn).not.to.have.been.called()
})
})

describe('when size is significantly smaller', function () {
beforeEach(function () {
utils.reportSize(666, 777, callback)
})

it('logs it in a friendly way', function () {
expect(console.info).to.have.been.called()
})

it('does not warn us', function () {
expect(console.warn).not.to.have.been.called()
})
})

describe('when size is slightly bigger', function () {
beforeEach(function () {
utils.reportSize(667, 666, callback)
})

it('has no friendly message', function () {
expect(console.info).not.to.have.been.called()
})

it('warns us', function () {
expect(console.warn).to.have.been.calledOnce()
})
})

describe('when size is significantly bigger', function () {
beforeEach(function () {
utils.reportSize(777, 666, callback)
})

it('warns us twice', function () {
expect(console.warn).to.have.been.calledTwice()
})
})
})

describe('getBuiltSizeOfBranch', function () {
it('does not throw', function () {
expect(function () {
utils.getBuiltSizeOfBranch('foo', callback)
}).not.to.throw()
})
})

describe('getBuiltAssetStats', function () {
it('does not throw', function () {
expect(function () {
utils.getBuiltAssetStats(callback)
}).not.to.throw()
})
})
})

0 comments on commit 9787432

Please sign in to comment.