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

Release script #317

Merged
merged 3 commits into from
May 27, 2020
Merged
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
19 changes: 19 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[bumpversion]
current_version = 0.2.0b13.dev
commit = False
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(0b)?(?P<patch>\d+)(\.(?P<release>[a-z]+))?
serialize =
{major}.{minor}.0b{patch}.{release}
Comment on lines +5 to +7
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to adapt including the 0b

{major}.{minor}.{patch}

[bumpversion:part:release]
optional_value = prod
first_value = dev
values =
dev
prod

[bumpversion:file:./pulp_ansible/__init__.py]

[bumpversion:file:./setup.py]
140 changes: 140 additions & 0 deletions .travis/release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import argparse
import os
import textwrap

from git import Repo


REDMINE_QUERY_URL = "https://pulp.plan.io/issues?set_filter=1&status_id=*&issue_id="
release_path = os.path.dirname(os.path.abspath(__file__))
plugin_path = release_path
if ".travis" in release_path:
plugin_path = os.path.dirname(release_path)

version = {}
with open(f"{plugin_path}/pulp_ansible/__init__.py") as fp:
version_line = [line for line in fp.readlines() if "__version__" in line][0]
exec(version_line, version)
release_version = version["__version__"].replace(".dev", "")

to_close = []
for filename in os.listdir(f"{plugin_path}/CHANGES"):
if filename.split(".")[0].isdigit():
to_close.append(filename.split(".")[0])
issues = ",".join(to_close)

helper = textwrap.dedent(
"""\
Start the release process.

Example:
setup.py on plugin before script:
version="2.0.dev"
requirements = ["pulpcore>=3.4"]


$ python .travis/realease.py minor 4.0 4.1

setup.py on plugin after script:
version="2.1.dev"
requirements = ["pulpcore>=4.0,<4.1"]

"""
)
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter, description=helper)

parser.add_argument(
"release_part", type=str, help="Whether the release should be major, minor or patch.",
)

parser.add_argument(
"--lower", type=str, required=False, help="Lower bound of pulpcore requirement.",
)

parser.add_argument(
"--upper", type=str, required=False, help="Upper bound of pulpcore requirement.",
)

args = parser.parse_args()

release_part = args.release_part

if "pulpcore" not in release_path:
lower_pulpcore_version = args.lower
upper_pulpcore_version = args.upper

print("\n\nHave you checked the output of: $towncrier --version x.y.z --draft")
print(f"\n\nRepo path: {plugin_path}")
repo = Repo(plugin_path)
git = repo.git

git.checkout("HEAD", b=f"release_{release_version}")

# First commit: changelog
os.system(f"towncrier --yes --version {release_version}")
git.add("CHANGES.rst")
git.add("CHANGES/*")
git.commit("-m", f"Building changelog for {release_version}\n\n[noissue]")

# Second commit: release version
with open(f"{plugin_path}/requirements.txt", "rt") as setup_file:
setup_lines = setup_file.readlines()

with open(f"{plugin_path}/requirements.txt", "wt") as setup_file:
for line in setup_lines:
if "pulpcore" in line and "pulpcore" not in release_path:
sep = "'" if len(line.split('"')) == 1 else '"'
for word in line.split(sep):
if "pulpcore" in word:
pulpcore_word = word

line = line.replace(
pulpcore_word, f"pulpcore>={lower_pulpcore_version},<{upper_pulpcore_version}"
)

setup_file.write(line)

os.system("bump2version release --allow-dirty")

plugin_name = plugin_path.split("/")[-1]
git.add(f"{plugin_path}/{plugin_name}/__init__.py")
git.add(f"{plugin_path}/setup.py")
git.add(f"{plugin_path}/requirements.txt")
git.add(f"{plugin_path}/.bumpversion.cfg")
git.commit("-m", f"Releasing {release_version}\n\n[noissue]")

sha = repo.head.object.hexsha
short_sha = git.rev_parse(sha, short=7)

# Third commit: bump to .dev
with open(f"{plugin_path}/requirements.txt", "rt") as setup_file:
setup_lines = setup_file.readlines()

with open(f"{plugin_path}/requirements.txt", "wt") as setup_file:
for line in setup_lines:
if "pulpcore" in line and "pulpcore" not in release_path:
sep = "'" if len(line.split('"')) == 1 else '"'
for word in line.split(sep):
if "pulpcore" in word:
pulpcore_word = word

line = line.replace(pulpcore_word, f"pulpcore>={lower_pulpcore_version}")

setup_file.write(line)

os.system(f"bump2version {release_part} --allow-dirty")

major, minor, patch = release_version.split(".")
version_ref = {"major": major, "minor": minor, "patch": patch}
version_ref[release_part] = str(int(version_ref[release_part]) + 1)
new_dev_version = f"{version_ref['major']}.{version_ref['minor']}.{version_ref['patch']}.dev"


git.add(f"{plugin_path}/{plugin_name}/__init__.py")
git.add(f"{plugin_path}/setup.py")
git.add(f"{plugin_path}/requirements.txt")
git.add(f"{plugin_path}/.bumpversion.cfg")
git.commit("-m", f"Bump to {new_dev_version}\n\n[noissue]")

print(f"\n\nRedmine query of issues to close:\n{REDMINE_QUERY_URL}{issues}")
print(f"\nRelease commit == {short_sha}")
1 change: 1 addition & 0 deletions CHANGES/6848.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Move requirements out of setup.py
1 change: 1 addition & 0 deletions CHANGES/6850.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Introduce release script
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
galaxy_importer
packaging
pulpcore>=3.0
PyYAML
semantic_version
9 changes: 2 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@

from setuptools import setup, find_packages

requirements = [
"galaxy_importer",
"packaging",
"pulpcore>=3.0",
"PyYAML",
"semantic_version",
]
with open("requirements.txt") as requirements:
requirements = requirements.readlines()

with open("README.rst") as f:
long_description = f.read()
Expand Down