Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streamline releasing #402

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added CHANGELOG.rst
Empty file.
55 changes: 55 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/sh

REMOTE="origin"
BRANCH="master"
#TODO: remove next line
BRANCH="nirizr/zestreleaser"

echo "Performing pre-release checks"
branch_name="$(git rev-parse --abbrev-ref HEAD)" || branch_name="(unnamed branch)" ;
if [ "$branch_name" != "$BRANCH" ] ; then
echo "Branch name is '$branch_name but $BRANCH is expected" ;
exit -1 ;
fi ;

if [ "$(git status -uno | grep "nothing to commit" | wc -l)" -eq "0" ] ; then
echo "local branch is dirty, can only release in clean workspaces"
exit -2 ;
fi ;

if [ "$(git rev-parse $BRANCH)" != "$(git ls-remote $REMOTE -h refs/heads/$BRANCH | cut -f 1 )" ] ; then
echo "local and remote branches are out of sync, releases are only possible on up-to-date branch"
exit -3 ;
fi ;


echo "Generating changelog"
latest_tag=$(git describe --tags $(git rev-list --tags --max-count=1) 2>/dev/null ) ;

changelog="**Changes for version $new_version ($changes changes):**\n" ;
if [ "$latest_tag" == "" ]; then
changelog+="First release"
else
changelog+=$(git log "$latest_tag..HEAD" --oneline --no-merges) ;
fi ;

echo $changelog >> CHANGELOG.rst


echo "Commiting changelog and creating release tag"
git commit -am "Release $release_version"
git tag "release_$release_version" -m "$release_annotation"
git push origin "release_$release_version"


echo "Building the IDAPLUGIN package"
REMATCH_SETUP_PACKAGE=idaplugin ./setup.py sdist --dist-dir=./dist/idaplugin --formats=zip,gztar bdist_wheel --dist-dir=./dist/idaplugin

echo "Building the SERVER package"
REMATCH_SETUP_PACKAGE=server ./setup.py sdist --dist-dir=./dist/server --formats=zip,gztar bdist_wheel --dist-dir=./dist/server


echo "Uploading packages"
twine upload --repository-url "https://test.pypi.org/legacy/" dist/*

# git-release "$(REPO)" "$(new_version)" "$(branch_name)" "$(changelog)" 'dist/*/*'
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[bdist_wheel]
universal = 1
99 changes: 69 additions & 30 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ def get_requirements(fname):
return (l for l in open(fname).readlines() if not l.startswith('-r '))


def build_setup(package_base, package_name, version_path,
package_data=None, script_args=None):
def build_setup(package_base, package_name, version_path, classifiers=None,
package_data=None, script_args=None, **kwargs):
if package_data is None:
package_data = {}
if classifiers is None:
classifiers = []

# generate install_requires based on requirements.txt
base_path = os.path.abspath(os.path.dirname(__file__))
Expand Down Expand Up @@ -68,16 +70,33 @@ def build_setup(package_base, package_name, version_path,
install_requires=install_requires,
long_description=read(readme_path),
classifiers=[
"Development Status :: 3 - Alpha",
],
"Development Status :: 2 - Pre-Alpha",
"Programming Language :: Python",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)"
] + classifiers,
**kwargs
)


def build_setup_server(script_args=None):
build_setup(package_base='server',
package_name='rematch-server',
version_path='./',
script_args=script_args)
script_args=script_args,
classifiers=["Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.0",
"Programming Language :: Python :: 3.1",
"Programming Language :: Python :: 3.2",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Environment :: Web Environment",
"Framework :: Django"],
zip_safe=True)


def build_setup_idaplugin(script_args=None):
Expand All @@ -86,31 +105,51 @@ def build_setup_idaplugin(script_args=None):
package_name='rematch-idaplugin',
version_path='rematch',
package_data=package_data,
script_args=script_args)
script_args=script_args,
classifiers=["Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7"],
zip_safe=False)


def usage_error(msg):
print(msg)
sys.exit(1)


expected_packages = {'server', 'idaplugin'}
available_packages = set(os.listdir('.')) & expected_packages


def get_requested_package():
if 'REMATCH_SETUP_PACKAGE' in os.environ:
return os.environ['REMATCH_SETUP_PACKAGE']

if len(sys.argv) > 1:
return sys.argv.pop(1)

if len(available_packages) == 1:
return available_packages.pop()

usage_error("Couldn't figure out requested package, please specify one of "
"available packages through either 'REMATCH_SETUP_PACKAGE' "
"environment variable or the first argument. Available packages "
"are: {}".format(available_packages))


def get_package():
requested_package = get_requested_package()

if requested_package not in available_packages:
usage_error("Requested package is currently missing: {}"
"".format(requested_package))

return requested_package


if __name__ == '__main__':
expected_packages = {'server', 'idaplugin'}
packages = set(os.listdir('.')) & expected_packages

if len(sys.argv) < 2 and len(packages) > 1:
print("Usage: {} {{package name}}".format(sys.argv[0]))
print("Available packages are: {}".format(", ".join(packages)))
sys.exit(1)

# If all packages are available, allow a 'release' command that would push
# all packages to pypi
if sys.argv[1] == 'release' and packages == expected_packages:
script_args = ['sdist', '--dist-dir=./dist', '--formats=zip', 'upload']
if not (len(sys.argv) >= 3 and sys.argv[2] == 'official'):
script_args += ['-r', 'pypitest']
build_setup_server(script_args=script_args)
build_setup_idaplugin(script_args=script_args)
else:
package = packages.pop() if len(packages) == 1 else sys.argv[1]
if sys.argv[1] == package:
sys.argv = sys.argv[:1] + sys.argv[2:]
if package == 'server':
build_setup_server()
elif package == 'idaplugin':
build_setup_idaplugin()
package = get_package()

if package == 'server':
build_setup_server()
elif package == 'idaplugin':
build_setup_idaplugin()