Skip to content

Commit

Permalink
Merge pull request #33 from holidayextras/PAY-868
Browse files Browse the repository at this point in the history
add node script to release
  • Loading branch information
hxpaul authored Dec 18, 2017
2 parents 2345245 + 941205d commit 1625236
Show file tree
Hide file tree
Showing 11 changed files with 3,607 additions and 79 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
coverage
.nyc_output
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Changelog
4 changes: 4 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ notify:
- url: https://us-central1-hx-data-production.cloudfunctions.net/deploymentNotifier

deployment:
testing:
branch: PAY-868
commands:
- RELEASE_BRANCH=PAY-868 npm run prereleasejs
production:
branch: master
commands:
Expand Down
12 changes: 12 additions & 0 deletions nodeApps/checkBuiltAssetSize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env node

const async = require('async')
const utils = require('../src/utils')

async.waterfall([
utils.checkPrerequisites,
utils.confirmOnFeatureBranch,
utils.getBuiltAssetStats
], err => {
if (err) console.warn(err) // don't throw, just let us know
})
66 changes: 19 additions & 47 deletions nodeApps/generateSignedFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,16 @@ const path = require('path')
const utils = require('../src/utils')
const exec = require('child_process').exec
const git = require('simple-git')()
const releaseBranch = process.env.releaseBranch || 'staging'
const releaseBranch = process.env.RELEASE_BRANCH || 'staging'
const name = process.env.npm_package_name
const version = process.env.npm_package_version
const distPath = path.join(process.cwd(), '/dist')
const distPath = path.join(process.cwd(), '/dist/')

const checkPrerequisites = callback => {
if (!process.env.npm_package_name) return callback('ERROR: run this as an npm script (npm run release)')
callback()
}

const getEmail = callback => {
git.raw(['config', '--get', 'user.email'], callback)
}

const setEmail = (email, callback) => {
if (!email) git.addConfig('user.email', process.env.GITHUB_EMAIL)
callback()
}

const getUser = callback => {
git.raw(['config', '--get', 'user.name'], callback)
}

const setUser = (name, callback) => {
if (!name) git.addConfig('user.name', process.env.GITHUB_EMAIL)
callback()
}

const checkBranch = callback => {
git.revparse(['--abbrev-ref', 'HEAD'], (err, branch) => {
if (err) return callback(err)
const currentBranch = process.env.TRAVIS_BRANCH || process.env.CIRCLE_BRANCH || ('' + branch).replace(/\n/, '')
if (releaseBranch !== currentBranch) return callback(`Only releasing on ${releaseBranch}`)
callback()
})
}

const checkAlreadyReleased = callback => {
const fullPath = path.resolve(`${distPath}/${name}.min.${version}.js`)
const checkAlreadyVersioned = callback => {
const file = `${distPath}/${name}.min.${version}.js`
const fullPath = path.resolve(file)
if (fs.existsSync(fullPath)) {
return callback(`Already exported ${distPath}${name}.min.${version}.js`)
return callback(`Already exported ${file}`)
}
callback()
}
Expand All @@ -68,18 +37,24 @@ const getSignature = (file, callback) => {
})
}

const getCommitMessagesSinceLastRelease = (versionedFile, signature, callback) => {
utils.getCommitMessagesSinceLastRelease((err, notes) => {
callback(err, notes, versionedFile, signature)
})
}

const getSignedStagingFile = getSignature.bind(null, `${distPath}/${name}.staging.min.js`)
const getSignedProductionFile = getSignature.bind(null, `${distPath}/${name}.min.js`)

const updateChangelog = (versionedFile, signature, callback) => {
const updateChangelog = (notes, versionedFile, signature, callback) => {
fs.readFile('CHANGELOG.md', 'utf-8', (readErr, contents) => {
if (readErr) return callback(readErr)
const file = ('' + versionedFile).replace(distPath, '')
const existingLines = new RegExp(`.*${file}.*`, 'g')
const newContents = contents
.replace(existingLines, '')
.replace(/\n\s*\n/g, '\n')
.replace('# Changelog', `# Changelog \n\n- ${file} - signature: ${signature}`)
.replace('# Changelog', `# Changelog \n\n- ${file} - signature: ${signature}${notes}`)
fs.writeFile('CHANGELOG.md', newContents, function (writeErr) {
if (writeErr) return callback(writeErr)
callback()
Expand Down Expand Up @@ -118,18 +93,15 @@ const push = callback => {
}

async.waterfall([
checkPrerequisites,
getEmail,
setEmail,
getUser,
setUser,
checkBranch,
checkAlreadyReleased,
utils.checkPrerequisites,
utils.checkBranch.bind(utils, releaseBranch),
checkAlreadyVersioned,
build,
getSignedStagingFile,
getCommitMessagesSinceLastRelease,
updateChangelog,
getSignedProductionFile,
updateChangelog,
updateChangelog.bind(null, ''),
addChangelog,
addStagingFile,
addProductionFile,
Expand Down
14 changes: 14 additions & 0 deletions nodeApps/preRelease.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env node

const async = require('async')
const utils = require('../src/utils')

async.waterfall([
utils.checkPrerequisites,
utils.checkAlreadyReleased
], err => {
if (err) {
console.error(err)
process.exit(1)
}
})
20 changes: 20 additions & 0 deletions nodeApps/release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env node

const async = require('async')
const utils = require('../src/utils')
const releaseBranch = process.env.RELEASE_BRANCH || 'master'

async.waterfall([
utils.checkPrerequisites,
utils.checkBranch.bind(utils, releaseBranch),
utils.checkAlreadyReleased,
utils.untagMajorVersion,
utils.tagMajorVersion,
utils.untagMinorVersion,
utils.tagMinorVersion,
utils.getCommitMessagesSinceLastRelease,
utils.tagAbsoluteVersion
], (err, result) => {
if (err) console.warn(err) // don't throw, just let us know
console.log('done')
})
Loading

0 comments on commit 1625236

Please sign in to comment.