-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #279 - add Github release process
- Loading branch information
Showing
4 changed files
with
199 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
#!/usr/bin/env python | ||
""" | ||
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 | ||
from github3 import login | ||
|
||
FORMAT = "[%(levelname)s %(filename)s:%(lineno)s - %(name)s.%(funcName)s() ] " \ | ||
"%(message)s" | ||
logging.basicConfig(level=logging.DEBUG, format=FORMAT) | ||
logger = logging.getLogger() | ||
|
||
for n in ['urllib3', 'urllib', 'requests', 'git', 'github3']: | ||
l = logging.getLogger(n) | ||
l.setLevel(logging.ERROR) | ||
l.propagate = True | ||
|
||
|
||
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 _release(self, markdown): | ||
_VERSION = 'foobar' | ||
for rel in self._repo.releases(): | ||
if rel.tag_name == _VERSION: | ||
logger.error('Error: Release already present for %s: "%s" (%s)', | ||
_VERSION, rel.name, rel.html_url) | ||
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) | ||
|
||
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.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 | ||
|
||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) < 2: | ||
sys.stderr.write("USAGE: release.py <gist|release>\n") | ||
raise SystemExit(1) | ||
|
||
action = sys.argv[1] | ||
if action not in ['gist', 'release']: | ||
sys.stderr.write("USAGE: release.py <gist|release>\n") | ||
raise SystemExit(1) | ||
GithubReleaser().run(action) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
tox | ||
twine | ||
webhook2lambda2sqs | ||
wheel | ||
github3.py==1.0.0a4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,12 +57,13 @@ To setup awslimitchecker for development: | |
$ cd awslimitchecker | ||
$ source bin/activate | ||
3. Install your fork in the virtualenv as an editable git clone | ||
3. Install your fork in the virtualenv as an editable git clone and install development dependencies: | ||
|
||
.. code-block:: bash | ||
$ pip install -e [email protected]:YOUR_NAME/awslimitchecker.git#egg=awslimitchecker | ||
$ cd src/awslimitchecker | ||
$ pip install -r dev/requirements_dev.txt | ||
4. Check out a new git branch. If you're working on a GitHub issue you opened, your | ||
branch should be called "issues/N" where N is the issue number. | ||
|
@@ -293,6 +294,11 @@ For issues: | |
Release Checklist | ||
----------------- | ||
|
||
Note that to perform releases, you will need: | ||
|
||
* Your Github access token exported as the ``GITHUB_TOKEN`` environment variable. | ||
* `pandoc <http://pandoc.org/>`_ installed on your local machine and in your ``PATH``. | ||
|
||
1. Open an issue for the release (the checklist below may help); cut a branch off ``develop`` for that issue. | ||
2. Build docs locally (``tox -e localdocs``) and ensure they're current; commit any changes. | ||
3. Run ``dev/terraform.py`` in the awslimitchecker source directory to update the | ||
|
@@ -301,12 +307,11 @@ Release Checklist | |
4. Ensure that Travis tests are passing in all environments. | ||
5. Ensure that test coverage is no less than the last release (ideally, 100%). | ||
6. Build docs for the branch (locally) and ensure they look correct. Commit any changes. | ||
7. Increment the version number in awslimitchecker/version.py and add version and release date to CHANGES.rst. | ||
Ensure that there are CHANGES.rst entries for all major changes since the last release, and that any breaking | ||
changes or new required IAM permissions are explicitly mentioned. Mention the issue in the commit for this, | ||
and push to GitHub. | ||
8. Confirm that README.rst renders correctly on GitHub. | ||
9. Upload package to testpypi, confirm that README.rst renders correctly. | ||
7. Increment the version number in awslimitchecker/version.py and add version and release date to CHANGES.rst. Ensure that there are CHANGES.rst entries for all major changes since the last release, and that any breaking changes or new required IAM permissions are explicitly mentioned. | ||
8. Run ``dev/release.py gist`` to convert the CHANGES.rst entry for the current version to Markdown and upload it as a Github Gist. View the gist and ensure that the Markdown rendered properly and all links are valid. Iterate on this until the rendered version looks correct. | ||
9. Commit all changes, mention the issue in the commit, and push to GitHub. | ||
10. Confirm that README.rst renders correctly on GitHub. | ||
11. Upload package to testpypi, confirm that README.rst renders correctly. | ||
|
||
* Make sure your ~/.pypirc file is correct (a repo called ``test`` for https://testpypi.python.org/pypi). | ||
* ``rm -Rf dist`` | ||
|
@@ -315,21 +320,22 @@ Release Checklist | |
* ``twine upload -r test dist/*`` | ||
* Check that the README renders at https://testpypi.python.org/pypi/awslimitchecker | ||
|
||
10. Create a pull request for the release to be merged into master. Upon successful Travis build, merge it. | ||
11. Tag the release in Git, push tag to GitHub: | ||
12. Create a pull request for the release to be merged into master. Upon successful Travis build, merge it. | ||
13. Tag the release in Git, push tag to GitHub: | ||
|
||
* tag the release with a signed tag: ``git tag -s -a X.Y.Z -m 'X.Y.Z released YYYY-MM-DD'`` | ||
* Verify the signature on the tag, just to be sure: ``git tag -v X.Y.Z`` | ||
* push the tag to GitHub: ``git push origin X.Y.Z`` | ||
|
||
12. Upload package to live pypi: | ||
14. Upload package to live pypi: | ||
|
||
* ``twine upload dist/*`` | ||
|
||
13. make sure any GH issues fixed in the release were closed. | ||
14. merge master back into develop | ||
15. Ensure that the issues are moved to Done on the `waffle.io board <https://waffle.io/jantman/awslimitchecker>`_ | ||
16. Blog, tweet, etc. about the new version. | ||
15. make sure any GH issues fixed in the release were closed. | ||
16. merge master back into develop | ||
17. Run ``dev/release.py release`` to create the release on GitHub. | ||
18. Ensure that the issues are moved to Done on the `waffle.io board <https://waffle.io/jantman/awslimitchecker>`_ | ||
19. Blog, tweet, etc. about the new version. | ||
|
||
Release Issue Template | ||
++++++++++++++++++++++ | ||
|