2013-05-02 10:55:51 +02:00
|
|
|
# Copyright (c) 2013 Yubico AB
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or
|
|
|
|
# without modification, are permitted provided that the following
|
|
|
|
# conditions are met:
|
|
|
|
#
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above
|
|
|
|
# copyright notice, this list of conditions and the following
|
|
|
|
# disclaimer in the documentation and/or other materials provided
|
|
|
|
# with the distribution.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2013-05-02 12:38:01 +02:00
|
|
|
from distutils import log
|
2013-05-02 10:55:51 +02:00
|
|
|
from distutils.core import Command
|
|
|
|
from distutils.errors import DistutilsSetupError
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
from datetime import date
|
|
|
|
|
|
|
|
|
|
|
|
class release(Command):
|
|
|
|
description = "create and release a new version"
|
|
|
|
user_options = [
|
|
|
|
('keyid', None, "GPG key to sign with"),
|
|
|
|
('skip-tests', None, "skip running the tests"),
|
2013-05-02 12:22:39 +02:00
|
|
|
('pypi', None, "publish to pypi"),
|
2013-05-02 10:55:51 +02:00
|
|
|
]
|
2013-05-02 12:22:39 +02:00
|
|
|
boolean_options = ['skip-tests', 'pypi']
|
2013-05-02 10:55:51 +02:00
|
|
|
|
|
|
|
def initialize_options(self):
|
|
|
|
self.keyid = None
|
|
|
|
self.skip_tests = 0
|
2013-05-02 12:22:39 +02:00
|
|
|
self.pypi = 0
|
2013-05-02 10:55:51 +02:00
|
|
|
|
|
|
|
def finalize_options(self):
|
|
|
|
self.cwd = os.getcwd()
|
2013-05-02 11:04:50 +02:00
|
|
|
self.fullname = self.distribution.get_fullname()
|
2013-05-02 11:18:48 +02:00
|
|
|
self.name = self.distribution.get_name()
|
|
|
|
self.version = self.distribution.get_version()
|
2013-05-02 10:55:51 +02:00
|
|
|
|
2013-05-02 11:04:50 +02:00
|
|
|
def _verify_version(self):
|
2013-05-02 10:55:51 +02:00
|
|
|
with open('NEWS', 'r') as news_file:
|
|
|
|
line = news_file.readline()
|
|
|
|
now = date.today().strftime('%Y-%m-%d')
|
2013-05-02 11:18:48 +02:00
|
|
|
if not re.search(r'Version %s \(released %s\)' % (self.version, now),
|
|
|
|
line):
|
2013-05-02 10:55:51 +02:00
|
|
|
raise DistutilsSetupError("Incorrect date/version in NEWS!")
|
|
|
|
|
2013-05-02 11:04:50 +02:00
|
|
|
def _verify_tag(self):
|
|
|
|
if os.system('git tag | grep -q "^%s\$"' % self.fullname) == 0:
|
|
|
|
raise DistutilsSetupError(
|
|
|
|
"Tag '%s' already exists!" % self.fullname)
|
2013-05-02 10:55:51 +02:00
|
|
|
|
2013-05-02 11:04:50 +02:00
|
|
|
def _sign(self):
|
2013-05-02 12:22:39 +02:00
|
|
|
if os.path.isfile('dist/%s.tar.gz.asc' % self.fullname):
|
|
|
|
# Signature exists from upload, re-use it:
|
|
|
|
sign_opts = ['--output dist/%s.tar.gz.sig' % self.fullname,
|
2013-05-02 13:16:38 +02:00
|
|
|
'--dearmor dist/%s.tar.gz.asc' % self.fullname]
|
2013-05-02 12:22:39 +02:00
|
|
|
else:
|
|
|
|
# No signature, create it:
|
|
|
|
sign_opts = ['--detach-sign', 'dist/%s.tar.gz' % self.fullname]
|
|
|
|
if self.keyid:
|
|
|
|
sign_opts.insert(1, '--default-key ' + self.keyid)
|
2013-05-02 10:55:51 +02:00
|
|
|
self.execute(os.system, ('gpg ' + (' '.join(sign_opts)),))
|
|
|
|
|
2013-05-02 11:04:50 +02:00
|
|
|
if os.system('gpg --verify dist/%s.tar.gz.sig' % self.fullname) != 0:
|
2013-05-02 10:55:51 +02:00
|
|
|
raise DistutilsSetupError("Error verifying signature!")
|
|
|
|
|
2013-05-02 11:04:50 +02:00
|
|
|
def _tag(self):
|
|
|
|
tag_opts = ['-s', '-m ' + self.fullname, self.fullname]
|
2013-05-02 10:55:51 +02:00
|
|
|
if self.keyid:
|
|
|
|
tag_opts[0] = '-u ' + self.keyid
|
|
|
|
self.execute(os.system, ('git tag ' + (' '.join(tag_opts)),))
|
2013-05-02 11:04:50 +02:00
|
|
|
|
2013-05-03 12:21:44 +02:00
|
|
|
def _do_call_publish(self, cmd):
|
|
|
|
self._published = os.system(cmd) == 0
|
|
|
|
|
2013-05-02 11:18:48 +02:00
|
|
|
def _publish(self):
|
|
|
|
web_repo = os.getenv('YUBICO_GITHUB_REPO')
|
|
|
|
if web_repo and os.path.isdir(web_repo):
|
2013-05-02 13:16:38 +02:00
|
|
|
artifacts = [
|
|
|
|
'dist/%s.tar.gz' % self.fullname,
|
|
|
|
'dist/%s.tar.gz.sig' % self.fullname
|
|
|
|
]
|
|
|
|
cmd = '%s/publish %s %s %s' % (
|
|
|
|
web_repo, self.name, self.version, ' '.join(artifacts))
|
2013-05-03 12:21:44 +02:00
|
|
|
|
|
|
|
self.execute(self._do_call_publish, (cmd,))
|
|
|
|
if self._published:
|
2013-05-02 12:38:01 +02:00
|
|
|
self.announce("Release published! Don't forget to:", log.INFO)
|
2013-05-03 12:21:44 +02:00
|
|
|
self.announce("")
|
2013-05-02 12:38:01 +02:00
|
|
|
self.announce(" (cd %s && git push)" % web_repo, log.INFO)
|
2013-05-03 12:21:44 +02:00
|
|
|
self.announce("")
|
2013-05-02 11:50:31 +02:00
|
|
|
else:
|
|
|
|
self.warn("There was a problem publishing the release!")
|
2013-05-02 11:18:48 +02:00
|
|
|
else:
|
|
|
|
self.warn("YUBICO_GITHUB_REPO not set or invalid!")
|
|
|
|
self.warn("This release will not be published!")
|
|
|
|
|
2013-05-02 11:04:50 +02:00
|
|
|
def run(self):
|
|
|
|
if os.getcwd() != self.cwd:
|
|
|
|
raise DistutilsSetupError("Must be in package root!")
|
|
|
|
|
|
|
|
self._verify_version()
|
|
|
|
self._verify_tag()
|
|
|
|
|
|
|
|
self.execute(os.system, ('git2cl > ChangeLog',))
|
|
|
|
|
|
|
|
if not self.skip_tests:
|
|
|
|
self.run_command('check')
|
2013-05-02 12:22:39 +02:00
|
|
|
# Nosetests calls sys.exit(status)
|
2013-05-02 11:43:48 +02:00
|
|
|
try:
|
|
|
|
self.run_command('nosetests')
|
|
|
|
except SystemExit as e:
|
|
|
|
if e.code != 0:
|
|
|
|
raise DistutilsSetupError("There were test failures!")
|
2013-05-02 11:04:50 +02:00
|
|
|
|
2013-05-02 12:22:39 +02:00
|
|
|
self.run_command('sdist')
|
|
|
|
|
|
|
|
if self.pypi:
|
|
|
|
cmd_obj = self.distribution.get_command_obj('upload')
|
|
|
|
cmd_obj.sign = True
|
|
|
|
if self.keyid:
|
|
|
|
cmd_obj.identity = self.keyid
|
|
|
|
self.run_command('upload')
|
2013-05-02 11:04:50 +02:00
|
|
|
|
|
|
|
self._sign()
|
|
|
|
self._tag()
|
2013-05-02 11:18:48 +02:00
|
|
|
|
2013-05-02 11:50:31 +02:00
|
|
|
self._publish()
|
2013-05-02 12:25:07 +02:00
|
|
|
|
2013-05-02 12:38:01 +02:00
|
|
|
self.announce("Release complete! Don't forget to:", log.INFO)
|
2013-05-03 12:21:44 +02:00
|
|
|
self.announce("")
|
2013-05-02 12:38:01 +02:00
|
|
|
self.announce(" git push && git push --tags", log.INFO)
|
2013-05-03 12:21:44 +02:00
|
|
|
self.announce("")
|