Skip to content

Instantly share code, notes, and snippets.

@tswicegood
Last active December 13, 2015 23:19
Show Gist options
  • Save tswicegood/4991032 to your computer and use it in GitHub Desktop.
Save tswicegood/4991032 to your computer and use it in GitHub Desktop.
Simple scripts for creating a new bugfix release that bumps the top allowed version of Django and handling the tagging and uploading of a release. These are meant to be used on Armstrong, and assume that they're being executed in the parent directory of each of the components.
"""
Script for bumping a Django version from one to the next minor version
"""
import os
import sys
import envoy
def main():
if len(sys.argv) is not 2:
sys.stderr.write("Usage: python bump_django.py {{ component }}")
sys.exit(1)
component = sys.argv[-1]
os.chdir(component)
latest_version = envoy.run('git tag | tail -1').std_out.strip()
bugfix_version = int(latest_version[-1]) + 1
new_version = '%s%d' % (latest_version[:-1], bugfix_version)
dev_version = '%salpha.0' % new_version[1:]
branch_name = '%s-prep' % new_version
print "Creating {0} {1}".format(component, new_version)
envoy.run('git checkout -b {0} {1}'.format(branch_name, latest_version))
r = envoy.run('grep Django package.json')
django_line = r.std_out
current_django = r.std_out.strip().split(',<=')[-1].strip('",')
new_django = '%s%d' % (current_django[:-1], int(current_django[-1]) + 1)
new_django_line = django_line.replace(current_django, new_django)
print "Bumping to Django v{0}".format(new_django)
with open('package.json', 'rb') as f:
original = f.read()
new_package_json = original.replace(django_line, new_django_line).replace(
latest_version[1:], dev_version)
with open('package.json', 'wb') as f:
f.write(new_package_json)
django_line = envoy.run('grep DJANGO_VERSION=%s .travis.yml' %
current_django).std_out
new_django_line = django_line.replace(current_django, new_django)
with open('.travis.yml', 'rb') as f:
original = f.read()
new_travis_yml = original.replace(django_line, new_django_line)
with open('.travis.yml', 'wb') as f:
f.write(new_travis_yml)
envoy.run('git add -u')
with open('commit.txt', 'wb') as f:
f.write('Bump Django to v{0}'.format(new_django))
envoy.run('git commit -F commit.txt'.format(new_django))
os.unlink('commit.txt')
envoy.run('git push origin {0}'.format(branch_name))
if __name__ == "__main__":
main()
"""
Script for taking a vX.X.X-prep branch and releasing it
"""
import os
import sys
import envoy
def main():
if len(sys.argv) is not 2:
sys.stderr.write("Usage: python bump_django.py {{ component }}")
sys.exit(1)
component = sys.argv[-1]
os.chdir(component)
# Assume that the latest *-prep branch is the one that we're
# releasing. It's brittle, but fine for now.
response = envoy.run('git branch | grep prep')
branch_name = response.std_out.strip().split('\n')[-1].split(' ')[-1]
new_version = branch_name.split('-')[0]
envoy.run('git checkout %s' % branch_name)
print 'Tagging %s %s' % (component, new_version)
# Find and swap out any ``alpha.0`` value to make this a real
# release. This assumes that there are no ``alpha.0`` dependencies
# in the package.json.
with open('package.json', 'rb') as f:
original = f.read()
new_package_json = original.replace('alpha.0', '')
with open('package.json', 'wb') as f:
f.write(new_package_json)
with open('commit.txt', 'wb') as f:
f.write('Release %s %s' % (component, new_version))
envoy.run('git add -u')
envoy.run('git commit -F commit.txt')
os.unlink('commit.txt')
envoy.run('git tag %s' % new_version)
envoy.run('python setup.py sdist upload')
envoy.run('cp dist/%s-%s.tar.gz ../pypi.armstrongcms.org/files/' % (
component, new_version[1:]))
envoy.run('git checkout master')
envoy.run('git merge -s recursive -X ours %s --no-commit' % new_version)
with open('commit.txt', 'wb') as f:
f.write('Merge %s' % new_version)
envoy.run('git commit -F commit.txt')
os.unlink('commit.txt')
envoy.run('git push armstrong master --tags')
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment