mirror of https://github.com/dbcli/pgcli
Updated release script with a --dry-run and --confirm-steps option.
This commit is contained in:
parent
764f69a47b
commit
ded45c4dd9
93
release.py
93
release.py
|
@ -4,8 +4,44 @@ import re
|
||||||
import ast
|
import ast
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
from optparse import OptionParser
|
||||||
|
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
|
CONFIRM_STEPS = False
|
||||||
|
DRY_RUN = False
|
||||||
|
|
||||||
|
|
||||||
|
def skip_step():
|
||||||
|
"""
|
||||||
|
Asks for user's response whether to run a step. Default is yes.
|
||||||
|
:return: boolean
|
||||||
|
"""
|
||||||
|
global CONFIRM_STEPS
|
||||||
|
|
||||||
|
if CONFIRM_STEPS:
|
||||||
|
choice = raw_input("--- Confirm step? (y/N) [y] ")
|
||||||
|
if choice.lower() == 'n':
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def run_step(*args):
|
||||||
|
"""
|
||||||
|
Prints out the command and asks if it should be run.
|
||||||
|
If yes (default), runs it.
|
||||||
|
:param args: list of strings (command and args)
|
||||||
|
"""
|
||||||
|
global DRY_RUN
|
||||||
|
|
||||||
|
cmd = args
|
||||||
|
print(' '.join(cmd))
|
||||||
|
if skip_step():
|
||||||
|
print('--- Skipping...')
|
||||||
|
elif DRY_RUN:
|
||||||
|
print('--- Pretending to run...')
|
||||||
|
else:
|
||||||
|
subprocess.check_output(cmd)
|
||||||
|
|
||||||
|
|
||||||
def version(version_file):
|
def version(version_file):
|
||||||
_version_re = re.compile(r'__version__\s+=\s+(.*)')
|
_version_re = re.compile(r'__version__\s+=\s+(.*)')
|
||||||
|
@ -16,41 +52,31 @@ def version(version_file):
|
||||||
|
|
||||||
return ver
|
return ver
|
||||||
|
|
||||||
|
|
||||||
def commit_for_release(version_file, ver):
|
def commit_for_release(version_file, ver):
|
||||||
cmd = ['git', 'reset']
|
run_step('git', 'reset')
|
||||||
print(' '.join(cmd))
|
run_step('git', 'add', version_file)
|
||||||
subprocess.check_output(cmd)
|
run_step('git', 'commit', '--message', 'Releasing version %s' % ver)
|
||||||
cmd = ['git', 'add', version_file]
|
|
||||||
print(' '.join(cmd))
|
|
||||||
subprocess.check_output(cmd)
|
|
||||||
cmd = ['git', 'commit', '--message', 'Releasing version %s' % ver]
|
|
||||||
print(' '.join(cmd))
|
|
||||||
subprocess.check_output(cmd)
|
|
||||||
|
|
||||||
def create_git_tag(tag_name):
|
def create_git_tag(tag_name):
|
||||||
cmd = ['git', 'tag', tag_name]
|
run_step('git', 'tag', tag_name)
|
||||||
print(' '.join(cmd))
|
|
||||||
subprocess.check_output(cmd)
|
|
||||||
|
|
||||||
def register_with_pypi():
|
def register_with_pypi():
|
||||||
cmd = ['python', 'setup.py', 'register']
|
run_step('python', 'setup.py', 'register')
|
||||||
print(' '.join(cmd))
|
|
||||||
subprocess.check_output(cmd)
|
|
||||||
|
|
||||||
def create_source_tarball():
|
def create_source_tarball():
|
||||||
cmd = ['python', 'setup.py', 'sdist']
|
run_step('python', 'setup.py', 'sdist')
|
||||||
print(' '.join(cmd))
|
|
||||||
subprocess.check_output(cmd)
|
|
||||||
|
|
||||||
def push_to_github():
|
def push_to_github():
|
||||||
cmd = ['git', 'push', 'origin', 'master']
|
run_step('git', 'push', 'origin', 'master')
|
||||||
print(' '.join(cmd))
|
|
||||||
subprocess.check_output(cmd)
|
|
||||||
|
|
||||||
def push_tags_to_github():
|
def push_tags_to_github():
|
||||||
cmd = ['git', 'push', '--tags', 'origin']
|
run_step('git', 'push', '--tags', 'origin')
|
||||||
print(' '.join(cmd))
|
|
||||||
subprocess.check_output(cmd)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -59,9 +85,26 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
ver = version('pgcli/__init__.py')
|
ver = version('pgcli/__init__.py')
|
||||||
print('Releasing Version:', ver)
|
print('Releasing Version:', ver)
|
||||||
choice = raw_input('Are you sure? (y/N)')
|
|
||||||
|
parser = OptionParser()
|
||||||
|
parser.add_option(
|
||||||
|
"-c", "--confirm-steps", action="store_true", dest="confirm_steps",
|
||||||
|
default=False, help=("Confirm every step. If the step is not "
|
||||||
|
"confirmed, it will be skipped.")
|
||||||
|
)
|
||||||
|
parser.add_option(
|
||||||
|
"-d", "--dry-run", action="store_true", dest="dry_run",
|
||||||
|
default=False, help="Print out, but not actually run any steps."
|
||||||
|
)
|
||||||
|
|
||||||
|
popts, pargs = parser.parse_args()
|
||||||
|
CONFIRM_STEPS = popts.confirm_steps
|
||||||
|
DRY_RUN = popts.dry_run
|
||||||
|
|
||||||
|
choice = raw_input('Are you sure? (y/N) [n] ')
|
||||||
if choice.lower() != 'y':
|
if choice.lower() != 'y':
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
commit_for_release('pgcli/__init__.py', ver)
|
commit_for_release('pgcli/__init__.py', ver)
|
||||||
create_git_tag('v%s' % ver)
|
create_git_tag('v%s' % ver)
|
||||||
register_with_pypi()
|
register_with_pypi()
|
||||||
|
|
Loading…
Reference in New Issue