2017-08-03 04:13:30 +08:00
#!/usr/bin/env node
[none] (dev) Add script/daily
Summary:
Generating the daily build always takes a bit of effort, so I wrote the
script to automate the process and allow anyone to do it as well.
This script will:
- Check your current working directory is in a good state
- Bump the version number in package.json
- Edit CHANGELOG.md with the git log diff between current master and the last version tag (you can also manually edit it). This is so writing the CHANGELOG before a release takes less effort; you will just need to open the CHANGELOG file and edit the commit messages.
- Commit the changes with a commit message of: bump(version) <next_version>
- Add new version tags to nylas-mail and k2
- Push the changes to Github
- If provided with the flag, it will build the app. This is intended to be used in our mac mini machine
There are a few TODO's left in here, like updating the daily channel,
and emailing a notification when the channel is updated with the buid urls.
When this lands, we will configure our mac mini to run this script daily/nightly.
Also, any engineer should be able to trigger a daily build easily by just
running this script.
For sample output, see this commit which was generated by this script:
https://github.com/nylas/nylas-mail/commit/000fa88ebb52a6d7aa3a9bc30b918969b65f22a7
Test Plan: manually running it
Reviewers: halla, spang, mark, khamidou, evan
Reviewed By: evan
Subscribers: tomasz
Differential Revision: https://phab.nylas.com/D4123
2017-03-07 16:57:05 +08:00
const childProcess = require ( 'child_process' )
2017-03-18 01:08:00 +08:00
const path = require ( 'path' )
[none] (dev) Add script/daily
Summary:
Generating the daily build always takes a bit of effort, so I wrote the
script to automate the process and allow anyone to do it as well.
This script will:
- Check your current working directory is in a good state
- Bump the version number in package.json
- Edit CHANGELOG.md with the git log diff between current master and the last version tag (you can also manually edit it). This is so writing the CHANGELOG before a release takes less effort; you will just need to open the CHANGELOG file and edit the commit messages.
- Commit the changes with a commit message of: bump(version) <next_version>
- Add new version tags to nylas-mail and k2
- Push the changes to Github
- If provided with the flag, it will build the app. This is intended to be used in our mac mini machine
There are a few TODO's left in here, like updating the daily channel,
and emailing a notification when the channel is updated with the buid urls.
When this lands, we will configure our mac mini to run this script daily/nightly.
Also, any engineer should be able to trigger a daily build easily by just
running this script.
For sample output, see this commit which was generated by this script:
https://github.com/nylas/nylas-mail/commit/000fa88ebb52a6d7aa3a9bc30b918969b65f22a7
Test Plan: manually running it
Reviewers: halla, spang, mark, khamidou, evan
Reviewed By: evan
Subscribers: tomasz
Differential Revision: https://phab.nylas.com/D4123
2017-03-07 16:57:05 +08:00
const mkdirp = require ( 'mkdirp' )
const semver = require ( 'semver' )
const program = require ( 'commander' )
2017-03-22 00:29:46 +08:00
const TMP _DIR = path . join ( _ _dirname , '..' , 'tmp' )
[none] (dev) Add script/daily
Summary:
Generating the daily build always takes a bit of effort, so I wrote the
script to automate the process and allow anyone to do it as well.
This script will:
- Check your current working directory is in a good state
- Bump the version number in package.json
- Edit CHANGELOG.md with the git log diff between current master and the last version tag (you can also manually edit it). This is so writing the CHANGELOG before a release takes less effort; you will just need to open the CHANGELOG file and edit the commit messages.
- Commit the changes with a commit message of: bump(version) <next_version>
- Add new version tags to nylas-mail and k2
- Push the changes to Github
- If provided with the flag, it will build the app. This is intended to be used in our mac mini machine
There are a few TODO's left in here, like updating the daily channel,
and emailing a notification when the channel is updated with the buid urls.
When this lands, we will configure our mac mini to run this script daily/nightly.
Also, any engineer should be able to trigger a daily build easily by just
running this script.
For sample output, see this commit which was generated by this script:
https://github.com/nylas/nylas-mail/commit/000fa88ebb52a6d7aa3a9bc30b918969b65f22a7
Test Plan: manually running it
Reviewers: halla, spang, mark, khamidou, evan
Reviewed By: evan
Subscribers: tomasz
Differential Revision: https://phab.nylas.com/D4123
2017-03-07 16:57:05 +08:00
async function spawn ( cmd , args , opts = { } ) {
return new Promise ( ( resolve , reject ) => {
const env = Object . assign ( { } , process . env , opts . env || { } )
delete opts . env
const options = Object . assign ( { stdio : 'inherit' , env } , opts ) ;
const proc = childProcess . spawn ( cmd , args , options )
proc . on ( "error" , reject )
proc . on ( "exit" , resolve )
} )
}
function exec ( cmd , opts = { } ) {
return new Promise ( ( resolve , reject ) => {
childProcess . exec ( cmd , opts , ( err , stdout ) => {
if ( err ) {
return reject ( err )
}
return resolve ( stdout )
} )
} )
}
function git ( subCmd , opts = { } ) {
const optsString = Object . keys ( opts ) . reduce ( ( prev , key ) => {
const optVal = opts [ key ]
if ( optVal == null ) {
return key . length > 1 ? ` ${ prev } -- ${ key } ` : ` ${ prev } - ${ key } `
}
return key . length > 1 ? ` ${ prev } -- ${ key } = ${ optVal } ` : ` ${ prev } - ${ key } ${ optVal } `
} , '' )
return exec ( ` git ${ subCmd } ${ optsString } ` , { cwd : './' } )
}
async function prependToFile ( filepath , string ) {
2017-03-22 00:29:46 +08:00
await exec ( ` echo " ${ string } " > ${ TMP _DIR } /tmpfile ` )
await exec ( ` cat ${ filepath } >> ${ TMP _DIR } /tmpfile ` )
await exec ( ` mv ${ TMP _DIR } /tmpfile ${ filepath } ` )
[none] (dev) Add script/daily
Summary:
Generating the daily build always takes a bit of effort, so I wrote the
script to automate the process and allow anyone to do it as well.
This script will:
- Check your current working directory is in a good state
- Bump the version number in package.json
- Edit CHANGELOG.md with the git log diff between current master and the last version tag (you can also manually edit it). This is so writing the CHANGELOG before a release takes less effort; you will just need to open the CHANGELOG file and edit the commit messages.
- Commit the changes with a commit message of: bump(version) <next_version>
- Add new version tags to nylas-mail and k2
- Push the changes to Github
- If provided with the flag, it will build the app. This is intended to be used in our mac mini machine
There are a few TODO's left in here, like updating the daily channel,
and emailing a notification when the channel is updated with the buid urls.
When this lands, we will configure our mac mini to run this script daily/nightly.
Also, any engineer should be able to trigger a daily build easily by just
running this script.
For sample output, see this commit which was generated by this script:
https://github.com/nylas/nylas-mail/commit/000fa88ebb52a6d7aa3a9bc30b918969b65f22a7
Test Plan: manually running it
Reviewers: halla, spang, mark, khamidou, evan
Reviewed By: evan
Subscribers: tomasz
Differential Revision: https://phab.nylas.com/D4123
2017-03-07 16:57:05 +08:00
}
async function sliceFileLines ( filepath , idx ) {
2017-03-22 00:29:46 +08:00
await exec ( ` tail -n + ${ 1 + idx } ${ filepath } > ${ TMP _DIR } /tmpfile ` )
await exec ( ` mv ${ TMP _DIR } /tmpfile ${ filepath } ` )
[none] (dev) Add script/daily
Summary:
Generating the daily build always takes a bit of effort, so I wrote the
script to automate the process and allow anyone to do it as well.
This script will:
- Check your current working directory is in a good state
- Bump the version number in package.json
- Edit CHANGELOG.md with the git log diff between current master and the last version tag (you can also manually edit it). This is so writing the CHANGELOG before a release takes less effort; you will just need to open the CHANGELOG file and edit the commit messages.
- Commit the changes with a commit message of: bump(version) <next_version>
- Add new version tags to nylas-mail and k2
- Push the changes to Github
- If provided with the flag, it will build the app. This is intended to be used in our mac mini machine
There are a few TODO's left in here, like updating the daily channel,
and emailing a notification when the channel is updated with the buid urls.
When this lands, we will configure our mac mini to run this script daily/nightly.
Also, any engineer should be able to trigger a daily build easily by just
running this script.
For sample output, see this commit which was generated by this script:
https://github.com/nylas/nylas-mail/commit/000fa88ebb52a6d7aa3a9bc30b918969b65f22a7
Test Plan: manually running it
Reviewers: halla, spang, mark, khamidou, evan
Reviewed By: evan
Subscribers: tomasz
Differential Revision: https://phab.nylas.com/D4123
2017-03-07 16:57:05 +08:00
}
async function updateChangelogFile ( changelogString ) {
2017-03-22 00:29:46 +08:00
mkdirp . sync ( TMP _DIR )
2017-08-11 10:23:40 +08:00
await sliceFileLines ( './app/CHANGELOG.md' , 2 )
await prependToFile ( './app/CHANGELOG.md' , changelogString )
[none] (dev) Add script/daily
Summary:
Generating the daily build always takes a bit of effort, so I wrote the
script to automate the process and allow anyone to do it as well.
This script will:
- Check your current working directory is in a good state
- Bump the version number in package.json
- Edit CHANGELOG.md with the git log diff between current master and the last version tag (you can also manually edit it). This is so writing the CHANGELOG before a release takes less effort; you will just need to open the CHANGELOG file and edit the commit messages.
- Commit the changes with a commit message of: bump(version) <next_version>
- Add new version tags to nylas-mail and k2
- Push the changes to Github
- If provided with the flag, it will build the app. This is intended to be used in our mac mini machine
There are a few TODO's left in here, like updating the daily channel,
and emailing a notification when the channel is updated with the buid urls.
When this lands, we will configure our mac mini to run this script daily/nightly.
Also, any engineer should be able to trigger a daily build easily by just
running this script.
For sample output, see this commit which was generated by this script:
https://github.com/nylas/nylas-mail/commit/000fa88ebb52a6d7aa3a9bc30b918969b65f22a7
Test Plan: manually running it
Reviewers: halla, spang, mark, khamidou, evan
Reviewed By: evan
Subscribers: tomasz
Differential Revision: https://phab.nylas.com/D4123
2017-03-07 16:57:05 +08:00
}
function getFormattedLogs ( mainLog ) {
const formattedMainLog = (
mainLog
. filter ( line => line . length > 0 )
. filter ( line => ! /^bump/i . test ( line ) && ! /changelog/i . test ( line ) )
. map ( line => ` + ${ line . replace ( '*' , '\\*' ) } ` )
. join ( '\n' )
)
return ` ${ formattedMainLog } \n `
}
function getChangelogHeader ( nextVersion ) {
const date = new Date ( ) . toLocaleDateString ( )
return (
` # Nylas Mail Changelog
# # # $ { nextVersion } ( $ { date } )
`
)
}
function validateArgs ( args ) {
if ( args . editChangelog && ! process . env . EDITOR ) {
throw new Error ( ` You can't edit the changelog without a default EDITOR in your env ` )
}
}
// TODO add progress indicators with ora
// TODO add options
// --update-daily-channel
// --notify
// --quiet
async function main ( args ) {
validateArgs ( args )
// Pull latest changes
try {
await git ( ` checkout master ` )
await git ( ` pull --rebase ` )
} catch ( err ) {
console . error ( err )
process . exit ( 1 )
}
2017-08-11 10:23:40 +08:00
const pkg = require ( '../app/package.json' ) //eslint-disable-line
2017-04-07 02:57:34 +08:00
const currentVersion = pkg . version
const nextVersion = semver . inc ( currentVersion , 'patch' )
[none] (dev) Add script/daily
Summary:
Generating the daily build always takes a bit of effort, so I wrote the
script to automate the process and allow anyone to do it as well.
This script will:
- Check your current working directory is in a good state
- Bump the version number in package.json
- Edit CHANGELOG.md with the git log diff between current master and the last version tag (you can also manually edit it). This is so writing the CHANGELOG before a release takes less effort; you will just need to open the CHANGELOG file and edit the commit messages.
- Commit the changes with a commit message of: bump(version) <next_version>
- Add new version tags to nylas-mail and k2
- Push the changes to Github
- If provided with the flag, it will build the app. This is intended to be used in our mac mini machine
There are a few TODO's left in here, like updating the daily channel,
and emailing a notification when the channel is updated with the buid urls.
When this lands, we will configure our mac mini to run this script daily/nightly.
Also, any engineer should be able to trigger a daily build easily by just
running this script.
For sample output, see this commit which was generated by this script:
https://github.com/nylas/nylas-mail/commit/000fa88ebb52a6d7aa3a9bc30b918969b65f22a7
Test Plan: manually running it
Reviewers: halla, spang, mark, khamidou, evan
Reviewed By: evan
Subscribers: tomasz
Differential Revision: https://phab.nylas.com/D4123
2017-03-07 16:57:05 +08:00
// Make sure working directory is clean
try {
await exec ( 'git diff --exit-code && git diff --cached --exit-code' )
} catch ( err ) {
console . error ( 'Git working directory is not clean!' )
process . exit ( 1 )
}
// Make sure there is a diff to build
let mainLog = '' ;
try {
mainLog = ( await git ( ` log ${ currentVersion } ..master --format='%s' ` ) ) . split ( '\n' )
if ( mainLog . length <= 1 ) {
console . error ( ` There are no changes to build since ${ currentVersion } ` )
process . exit ( 1 )
}
} catch ( err ) {
console . error ( err )
process . exit ( 1 )
}
// Update CHANGELOG
try {
const commitLogSinceLatestVersion = await getFormattedLogs ( mainLog )
const changelogHeader = getChangelogHeader ( nextVersion )
const changelogString = ` ${ changelogHeader } ${ commitLogSinceLatestVersion } `
await updateChangelogFile ( changelogString )
console . log ( changelogString )
} catch ( err ) {
console . error ( 'Could not update changelog file' )
console . error ( err )
process . exit ( 1 )
}
// Allow editing
if ( args . editChangelog ) {
try {
2017-08-11 10:23:40 +08:00
await spawn ( process . env . EDITOR , [ './app/CHANGELOG.md' ] , { stdio : 'inherit' } )
[none] (dev) Add script/daily
Summary:
Generating the daily build always takes a bit of effort, so I wrote the
script to automate the process and allow anyone to do it as well.
This script will:
- Check your current working directory is in a good state
- Bump the version number in package.json
- Edit CHANGELOG.md with the git log diff between current master and the last version tag (you can also manually edit it). This is so writing the CHANGELOG before a release takes less effort; you will just need to open the CHANGELOG file and edit the commit messages.
- Commit the changes with a commit message of: bump(version) <next_version>
- Add new version tags to nylas-mail and k2
- Push the changes to Github
- If provided with the flag, it will build the app. This is intended to be used in our mac mini machine
There are a few TODO's left in here, like updating the daily channel,
and emailing a notification when the channel is updated with the buid urls.
When this lands, we will configure our mac mini to run this script daily/nightly.
Also, any engineer should be able to trigger a daily build easily by just
running this script.
For sample output, see this commit which was generated by this script:
https://github.com/nylas/nylas-mail/commit/000fa88ebb52a6d7aa3a9bc30b918969b65f22a7
Test Plan: manually running it
Reviewers: halla, spang, mark, khamidou, evan
Reviewed By: evan
Subscribers: tomasz
Differential Revision: https://phab.nylas.com/D4123
2017-03-07 16:57:05 +08:00
} catch ( err ) {
console . error ( 'Error editing CHANGELOG.md' )
console . error ( err )
process . exit ( 1 )
}
}
// Bump patch version in package.json
try {
2017-08-11 10:23:40 +08:00
await exec ( 'npm --no-git-tag-version version patch' , { cwd : './app' } )
[none] (dev) Add script/daily
Summary:
Generating the daily build always takes a bit of effort, so I wrote the
script to automate the process and allow anyone to do it as well.
This script will:
- Check your current working directory is in a good state
- Bump the version number in package.json
- Edit CHANGELOG.md with the git log diff between current master and the last version tag (you can also manually edit it). This is so writing the CHANGELOG before a release takes less effort; you will just need to open the CHANGELOG file and edit the commit messages.
- Commit the changes with a commit message of: bump(version) <next_version>
- Add new version tags to nylas-mail and k2
- Push the changes to Github
- If provided with the flag, it will build the app. This is intended to be used in our mac mini machine
There are a few TODO's left in here, like updating the daily channel,
and emailing a notification when the channel is updated with the buid urls.
When this lands, we will configure our mac mini to run this script daily/nightly.
Also, any engineer should be able to trigger a daily build easily by just
running this script.
For sample output, see this commit which was generated by this script:
https://github.com/nylas/nylas-mail/commit/000fa88ebb52a6d7aa3a9bc30b918969b65f22a7
Test Plan: manually running it
Reviewers: halla, spang, mark, khamidou, evan
Reviewed By: evan
Subscribers: tomasz
Differential Revision: https://phab.nylas.com/D4123
2017-03-07 16:57:05 +08:00
} catch ( err ) {
console . error ( 'Could not bump version in package.json' )
console . error ( err )
process . exit ( 1 )
}
if ( args . noCommit ) {
return
}
// Commit changes
try {
2017-03-09 14:24:17 +08:00
await git ( 'add .' )
[none] (dev) Add script/daily
Summary:
Generating the daily build always takes a bit of effort, so I wrote the
script to automate the process and allow anyone to do it as well.
This script will:
- Check your current working directory is in a good state
- Bump the version number in package.json
- Edit CHANGELOG.md with the git log diff between current master and the last version tag (you can also manually edit it). This is so writing the CHANGELOG before a release takes less effort; you will just need to open the CHANGELOG file and edit the commit messages.
- Commit the changes with a commit message of: bump(version) <next_version>
- Add new version tags to nylas-mail and k2
- Push the changes to Github
- If provided with the flag, it will build the app. This is intended to be used in our mac mini machine
There are a few TODO's left in here, like updating the daily channel,
and emailing a notification when the channel is updated with the buid urls.
When this lands, we will configure our mac mini to run this script daily/nightly.
Also, any engineer should be able to trigger a daily build easily by just
running this script.
For sample output, see this commit which was generated by this script:
https://github.com/nylas/nylas-mail/commit/000fa88ebb52a6d7aa3a9bc30b918969b65f22a7
Test Plan: manually running it
Reviewers: halla, spang, mark, khamidou, evan
Reviewed By: evan
Subscribers: tomasz
Differential Revision: https://phab.nylas.com/D4123
2017-03-07 16:57:05 +08:00
await git ( ` commit -m 'bump(version): ${ nextVersion } ' ` )
} catch ( err ) {
console . error ( 'Could not commit changes' )
console . error ( err )
process . exit ( 1 )
}
if ( args . noTag ) {
return
}
// Tag commit
try {
await git ( ` tag ${ nextVersion } ` )
} catch ( err ) {
console . error ( 'Could not tag commit' )
console . error ( err )
process . exit ( 1 )
}
if ( args . noPush ) {
return
}
// Push changes
try {
await git ( ` push origin master --tags ` )
} catch ( err ) {
console . error ( 'Could not tag commit' )
console . error ( err )
process . exit ( 1 )
}
// Build locally. This should only be used when building from our in-office
// coffee machine mac mini
if ( args . build ) {
try {
await spawn ( 'git' , [ 'clean' , '-xdf' ] )
2017-08-11 10:23:40 +08:00
await spawn ( 'cp' , [ '-r' , '../n1-keys-and-certificates' , 'app/build/resources/certs' ] )
2017-08-11 12:24:12 +08:00
await spawn ( 'npm' , [ 'install' ] , { env : { } } )
2017-03-14 06:48:45 +08:00
await spawn ( 'npm' , [ 'run' , 'build-client' ] , { env : { SIGN _BUILD : true } } )
2017-08-11 10:23:40 +08:00
await spawn ( 'codesign' , [ '--verify' , '--deep' , '--verbose=2' , '"app/dist/Nylas Mail-darwin-x64/Nylas Mail.app"' ] )
2017-08-12 02:38:25 +08:00
// await spawn('npm', ['run', 'upload-client'])
[none] (dev) Add script/daily
Summary:
Generating the daily build always takes a bit of effort, so I wrote the
script to automate the process and allow anyone to do it as well.
This script will:
- Check your current working directory is in a good state
- Bump the version number in package.json
- Edit CHANGELOG.md with the git log diff between current master and the last version tag (you can also manually edit it). This is so writing the CHANGELOG before a release takes less effort; you will just need to open the CHANGELOG file and edit the commit messages.
- Commit the changes with a commit message of: bump(version) <next_version>
- Add new version tags to nylas-mail and k2
- Push the changes to Github
- If provided with the flag, it will build the app. This is intended to be used in our mac mini machine
There are a few TODO's left in here, like updating the daily channel,
and emailing a notification when the channel is updated with the buid urls.
When this lands, we will configure our mac mini to run this script daily/nightly.
Also, any engineer should be able to trigger a daily build easily by just
running this script.
For sample output, see this commit which was generated by this script:
https://github.com/nylas/nylas-mail/commit/000fa88ebb52a6d7aa3a9bc30b918969b65f22a7
Test Plan: manually running it
Reviewers: halla, spang, mark, khamidou, evan
Reviewed By: evan
Subscribers: tomasz
Differential Revision: https://phab.nylas.com/D4123
2017-03-07 16:57:05 +08:00
} catch ( err ) {
console . error ( 'Errored while running build' )
console . error ( err )
process . exit ( 1 )
}
// TODO Update `daily` channel
// TODO send out notification email
}
console . log ( 'Done!' )
}
program
. version ( '0.0.1' )
. usage ( '[options]' )
. description ( 'This script will bump the version in package.json, edit the changelog with the latest\n git log (for easier editing), commit and tag the changes, and push to Github to trigger\n a build' )
. option ( '--edit-changelog' , 'Open your $EDITOR to edit CHANGELOG before commiting version bump.' )
. option ( '--no-commit' , 'Wether to commit changes to CHANGELOG.md and package.json' )
. option ( '--no-tag' , 'Wether to tag the version bump commit (no-op if --no-commit is used)' )
. option ( '--no-push' , 'Wether to push changes to the Github remote' )
. option ( '--build' , 'Wether to build the app locally. This should only be used when building from our in-office Mac Mini by the coffee machine' )
. parse ( process . argv )
main ( program )