Skip to content

Commit

Permalink
fixes #316 - automate release process
Browse files Browse the repository at this point in the history
  • Loading branch information
jantman committed Dec 2, 2017
1 parent 7ab289f commit 05d39a6
Show file tree
Hide file tree
Showing 5 changed files with 954 additions and 171 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ after development was ceased. The test framework used by awslimitchecker, pytest
* `Issue #314 <https://github.com/jantman/awslimitchecker/issues/314>`_ - Update RDS service default limits; ``DB snapshots per user`` default limit increased from 50 to 100 and ``Subnet Groups`` limit increased from 20 to 50. This should not have affected any users, as these limits are retrieved in realtime via the RDS API.
* `Issue #293 <https://github.com/jantman/awslimitchecker/issues/293>`_ - Increase maximum number of retries (boto3/botocore) for ``elbv2`` API calls, to attempt to deal with the large number of calls we have to make in order to count the ALB listeners and rules. This requires botocore >= 1.6.0, which requires boto3 >= 1.4.6.
* `Issue #315 <https://github.com/jantman/awslimitchecker/issues/315>`_ - Add new instance types: 'c5.18xlarge', 'c5.2xlarge', 'c5.4xlarge', 'c5.9xlarge', 'c5.large', 'c5.xlarge', 'g3.16xlarge', 'g3.4xlarge', 'g3.8xlarge', 'h1.16xlarge', 'h1.2xlarge', 'h1.4xlarge', 'h1.8xlarge', 'm5.12xlarge', 'm5.24xlarge', 'm5.2xlarge', 'm5.4xlarge', 'm5.large', 'm5.xlarge', 'p3.16xlarge', 'p3.2xlarge', 'p3.8xlarge', 'x1e.32xlarge', 'x1e.xlarge'
* `Issue #316 <https://github.com/jantman/awslimitchecker/issues/316>`_ - Automate release process.

2.0.0 (2017-10-12)
------------------
Expand Down
168 changes: 168 additions & 0 deletions dev/github_releaser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
"""
Development script to convert current version release notes to markdown and
either upload to Github as a gist, or create a Github release for the version.
awslimitchecker/dev/release.py
The latest version of this package is available at:
<https://github.com/jantman/awslimitchecker>
################################################################################
Copyright 2015-2017 Jason Antman <[email protected]>
This file is part of awslimitchecker, also known as awslimitchecker.
awslimitchecker is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
awslimitchecker is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with awslimitchecker. If not, see <http://www.gnu.org/licenses/>.
The Copyright and Authors attributions contained herein may not be removed or
otherwise altered, except to add the Author attribution of a contributor to
this work. (Additional Terms pursuant to Section 7b of the AGPL v3)
################################################################################
While not legally required, I sincerely request that anyone who finds
bugs please submit them at <https://github.com/jantman/pydnstest> or
to me via email, and that you send any contributions or improvements
either as a pull request on GitHub, or to me via email.
################################################################################
AUTHORS:
Jason Antman <[email protected]> <http://www.jasonantman.com>
################################################################################
"""

import os
import sys
import logging
import subprocess
import re
from datetime import datetime
from awslimitchecker.version import _VERSION
from distutils.spawn import find_executable

try:
from github3 import login
except ImportError:
raise SystemExit('ERROR: you must "pip install github3.py==1.0.0a4"')

logger = logging.getLogger(__name__)


class GithubReleaser(object):

head_re = re.compile(r'^## (\d+\.\d+\.\d+).*')

def __init__(self):
self._pandoc = find_executable('pandoc')
if self._pandoc is None:
sys.stderr.write("ERROR: pandoc not found on PATH.\n")
raise SystemExit(1)
self._gh_token = os.environ.get('GITHUB_TOKEN', None)
if self._gh_token is None:
sys.stderr.write("ERROR: GITHUB_TOKEN env var must be set\n")
raise SystemExit(1)
self._gh = login(token=self._gh_token)
self._repo = self._gh.repository('jantman', 'awslimitchecker')

def run(self, action):
logger.info('Github Releaser running action: %s', action)
logger.info('Current awslimitchecker version: %s', _VERSION)
md = self._get_markdown()
print("Markdown:\n%s\n" % md)
try:
raw_input(
'Does this look right? <Enter> to continue or Ctrl+C otherwise'
)
except Exception:
input(
'Does this look right? <Enter> to continue or Ctrl+C otherwise'
)
if action == 'release':
self._release(md)
else:
self._gist(md)

def get_tag(self, version):
"""
Check GitHub for a release with the specified tag name. If present,
return a 2-tuple of the release name and release HTML URL. Otherwise,
return a 2-tuple of None, None (tag not present).
:param version: the tag name to check for
:type version: str
:return: 2-tuple of release name, release HTML URL for the specified
release tag, or 2-tuple of None, None if no such release
:rtype: tuple
"""
for rel in self._repo.releases():
if rel.tag_name == version:
return rel.name, rel.html_url
return None, None

def _release(self, markdown):
tagname, tagurl = self.get_tag(_VERSION)
if (tagname, tagurl) != (None, None):
logger.error('Error: Release already present for %s: "%s" (%s)',
_VERSION, tagname, tagurl)
raise SystemExit(1)
name = '%s released %s' % (
_VERSION, datetime.now().strftime('%Y-%m-%d')
)
logger.info('Creating release: %s', name)
r = self._repo.create_release(
_VERSION,
name=name,
body=markdown,
draft=False,
prerelease=False
)
logger.info('Created release: %s', r.html_url)

def _gist(self, markdown):
logger.info('Creating private gist...')
g = self._gh.create_gist(
'awslimitchecker %s release notes test' % _VERSION,
{
'release_notes.md': {'content': markdown}
},
public=False
)
logger.info('Created gist: %s', g.html_url)
return g.html_url

def _get_markdown(self):
fpath = os.path.abspath(os.path.join(
os.path.dirname(os.path.realpath(__file__)),
'..',
'CHANGES.rst'
))
cmd = [
self._pandoc,
'-f', 'rst',
'-t', 'markdown',
'--normalize',
'--wrap=none',
'--atx-headers',
fpath
]
logger.debug('Running: %s', cmd)
markdown = subprocess.check_output(cmd)
buf = ''
in_ver = False
for line in markdown.decode().split("\n"):
if not in_ver and line.startswith('## %s ' % _VERSION):
in_ver = True
elif in_ver and line.startswith('## '):
return buf
elif in_ver:
buf += line + "\n"
return buf
Loading

0 comments on commit 05d39a6

Please sign in to comment.