Skip to content

Instantly share code, notes, and snippets.

@jasonmerino
Created April 25, 2017 16:31
Show Gist options
  • Save jasonmerino/b6d2b0d6cf51c45e8b3844555bc186e4 to your computer and use it in GitHub Desktop.
Save jasonmerino/b6d2b0d6cf51c45e8b3844555bc186e4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
const prog = require('caporal');
const {
exec,
cd,
} = require('shelljs');
function trimTrailingNewLine(str) {
if (str.endsWith('\n')) {
return str.trimRight(2);
}
return str;
}
prog
.version('0.0.1')
.command('beta')
.action(function(args, options, logger) {
const silent = {
silent: true,
};
const gitStatus = exec('git status --porcelain', silent);
// Make sure the working directory is clean
if (gitStatus.stdout !== '') {
logger.info('Your working directory is not clean. Please commit or discard your current changes.');
process.exit(1);
}
logger.info('We need your password to make sure that fastlane is up to date.');
exec('sudo gem update fastlane');
cd('ios');
const fastlane = exec('fastlane beta');
// check if fastlane failed
if (fastlane.code !== 0) {
// reset changes made by reving build number
exec('git reset --hard');
logger.info('Fastlane failed to build. Check the errors. Make some changes. Keep crushin\' it!');
process.exit(1);
}
// get version and build numbers for tagging
const version = trimTrailingNewLine(exec('agvtool what-marketing-version -terse1', silent));
const build = trimTrailingNewLine(exec('agvtool what-version -terse', silent));
cd('..');
const changelog = exec('git log $(git log --all --grep="Build " -n 1 --format="%h")..HEAD --no-merges --format="- %s"', silent);
logger.info(`
-----
Changelog for build ${version}.${build}:
${changelog}
-----
`);
exec(`git tag ${version}.${build}`);
exec('git push origin --tags');
exec('git add .');
exec(`git commit -m "Build ${version}.${build}" --no-verify`);
exec('git push');
logger.info(`New beta ${version}.${build} shipped. Go kick back and enjoy a drink. :)`);
});
prog.parse(process.argv);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment