-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[noissue]
- Loading branch information
Showing
25 changed files
with
672 additions
and
510 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
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
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,112 @@ | ||
#!/usr/bin/env python | ||
|
||
# WARNING: DO NOT EDIT! | ||
# | ||
# This file was generated by plugin_template, and is managed by it. Please use | ||
# './plugin-template --github pulp_rpm' to update this file. | ||
# | ||
# For more info visit https://github.com/pulp/plugin_template | ||
|
||
import argparse | ||
import re | ||
import os | ||
import yaml | ||
from tempfile import TemporaryDirectory | ||
from packaging.version import Version | ||
from git import Repo | ||
|
||
UPSTREAM_REMOTE = "https://github.com/pulp/pulp_rpm.git" | ||
DEFAULT_BRANCH = "main" | ||
RELEASE_BRANCH_REGEX = r"^([0-9]+)\.([0-9]+)$" | ||
Y_CHANGELOG_EXTS = [".feature", ".removal", ".deprecation"] | ||
Z_CHANGELOG_EXTS = [".bugfix", ".doc", ".misc"] | ||
|
||
|
||
def main(): | ||
"""Check which branches need a release.""" | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"--branches", | ||
default="supported", | ||
help="A comma separated list of branches to check for releases. Can also use keyword: " | ||
"'supported'. Defaults to 'supported', see `ci_update_branches` in " | ||
"`plugin_template.yml`.", | ||
) | ||
opts = parser.parse_args() | ||
|
||
with TemporaryDirectory() as d: | ||
# Clone from upstream to ensure we have updated branches & main | ||
repo = Repo.clone_from(UPSTREAM_REMOTE, d, filter="blob:none") | ||
heads = [h.split("/")[-1] for h in repo.git.ls_remote("--heads").split("\n")] | ||
available_branches = [h for h in heads if re.search(RELEASE_BRANCH_REGEX, h)] | ||
available_branches.sort(key=lambda ver: Version(ver)) | ||
available_branches.append(DEFAULT_BRANCH) | ||
|
||
branches = opts.branches | ||
if branches == "supported": | ||
with open(f"{d}/template_config.yml", mode="r") as f: | ||
tc = yaml.safe_load(f) | ||
branches = tc["ci_update_branches"] | ||
branches.append(DEFAULT_BRANCH) | ||
else: | ||
branches = branches.split(",") | ||
|
||
if diff := set(branches) - set(available_branches): | ||
print(f"Supplied branches contains non-existent branches! {diff}") | ||
exit(1) | ||
|
||
print(f"Checking for releases on branches: {branches}") | ||
|
||
releases = [] | ||
for branch in branches: | ||
if branch != DEFAULT_BRANCH: | ||
# Check if a Z release is needed | ||
changes = repo.git.ls_tree("-r", "--name-only", f"origin/{branch}", "CHANGES/") | ||
z_release = False | ||
for change in changes.split("\n"): | ||
# Check each changelog file to make sure everything checks out | ||
_, ext = os.path.splitext(change) | ||
if ext in Y_CHANGELOG_EXTS: | ||
print( | ||
f"Warning: A non-backported changelog ({change}) is present in the " | ||
f"{branch} release branch!" | ||
) | ||
elif ext in Z_CHANGELOG_EXTS: | ||
z_release = True | ||
if z_release: | ||
# Blobless clone does not have file contents for Z branches, | ||
# check commit message for last Z bump | ||
git_branch = f"origin/{branch}" | ||
next_version = repo.git.log( | ||
"--oneline", "--grep=Bump to", "-n 1", git_branch, "--", ".bumpversion.cfg" | ||
).split("to")[-1] | ||
next_version = Version(next_version) | ||
print( | ||
f"A Z-release is needed for {branch}, " | ||
f"New Version: {next_version.base_version}" | ||
) | ||
releases.append(next_version) | ||
else: | ||
# Check if a Y release is needed | ||
changes = repo.git.ls_tree("-r", "--name-only", DEFAULT_BRANCH, "CHANGES/") | ||
for change in changes.split("\n"): | ||
_, ext = os.path.splitext(change) | ||
if ext in Y_CHANGELOG_EXTS: | ||
# We don't put Y release bumps in the commit message, check file instead | ||
# The 'current_version' is always the next version to release | ||
next_version = repo.git.grep( | ||
"current_version", DEFAULT_BRANCH, "--", ".bumpversion.cfg" | ||
).split("=")[-1] | ||
next_version = Version(next_version) | ||
print( | ||
f"A new Y-release is needed! New Version: {next_version.base_version}" | ||
) | ||
releases.append(next_version) | ||
break | ||
|
||
if len(releases) == 0: | ||
print("No new releases to perform.") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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,66 @@ | ||
# WARNING: DO NOT EDIT! | ||
# | ||
# This file was generated by plugin_template, and is managed by it. Please use | ||
# './plugin-template --github pulp_rpm' to update this file. | ||
# | ||
# For more info visit https://github.com/pulp/plugin_template | ||
|
||
import warnings | ||
from pkg_resources import Requirement | ||
|
||
|
||
CHECK_MATRIX = [ | ||
("requirements.txt", True, True, True), | ||
("dev_requirements.txt", False, True, False), | ||
("ci_requirements.txt", False, True, True), | ||
("doc_requirements.txt", False, True, False), | ||
("lint_requirements.txt", False, True, True), | ||
("unittest_requirements.txt", False, True, True), | ||
("functest_requirements.txt", False, True, True), | ||
("clitest_requirements.txt", False, True, True), | ||
] | ||
|
||
errors = [] | ||
|
||
for filename, check_upperbound, check_prereleases, check_r in CHECK_MATRIX: | ||
try: | ||
with open(filename, "r") as fd: | ||
for nr, line in enumerate(fd.readlines()): | ||
line = line.strip() | ||
if not line or line.startswith("#"): | ||
continue | ||
try: | ||
req = Requirement.parse(line) | ||
except ValueError: | ||
if line.startswith("git+"): | ||
# The single exception... | ||
if "pulp-smash" not in line: | ||
errors.append(f"{filename}:{nr}: Invalid source requirement: {line}") | ||
elif line.startswith("-r "): | ||
if check_r: | ||
errors.append(f"{filename}:{nr}: Invalid deferred requirement: {line}") | ||
else: | ||
errors.append(f"{filename}:{nr}: Unreadable requirement {line}") | ||
else: | ||
if check_prereleases and req.specifier.prereleases: | ||
# Do not even think about begging for more exceptions! | ||
if ( | ||
not req.name.startswith("opentelemetry") | ||
and req.name != "pulp-rpm-client" | ||
): | ||
errors.append(f"{filename}:{nr}: Prerelease versions found in {line}.") | ||
ops = [op for op, ver in req.specs] | ||
spec = str(req.specs) | ||
if "~=" in ops: | ||
warnings.warn(f"{filename}:{nr}: Please avoid using ~= on {req.name}!") | ||
elif "<" not in ops and "<=" not in ops and "==" not in ops: | ||
if check_upperbound: | ||
errors.append(f"{filename}:{nr}: Upper bound missing in {line}.") | ||
except FileNotFoundError: | ||
# skip this test for plugins that don't use this requirements.txt | ||
pass | ||
|
||
if errors: | ||
print("Dependency issues found:") | ||
print("\n".join(errors)) | ||
exit(1) |
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,101 @@ | ||
# WARNING: DO NOT EDIT! | ||
# | ||
# This file was generated by plugin_template, and is managed by it. Please use | ||
# './plugin-template --github pulp_rpm' to update this file. | ||
# | ||
# For more info visit https://github.com/pulp/plugin_template | ||
|
||
import itertools | ||
import os | ||
import re | ||
|
||
import toml | ||
from git import GitCommandError, Repo | ||
from pkg_resources import parse_version | ||
|
||
# Read Towncrier settings | ||
tc_settings = toml.load("pyproject.toml")["tool"]["towncrier"] | ||
|
||
CHANGELOG_FILE = tc_settings.get("filename", "NEWS.rst") | ||
START_STRING = tc_settings.get( | ||
"start_string", | ||
"<!-- towncrier release notes start -->\n" | ||
if CHANGELOG_FILE.endswith(".md") | ||
else ".. towncrier release notes start\n", | ||
) | ||
TITLE_FORMAT = tc_settings.get("title_format", "{name} {version} ({project_date})") | ||
|
||
|
||
NAME_REGEX = r".*" | ||
VERSION_REGEX = r"([0-9]+\.[0-9]+\.[0-9][0-9ab]*)" | ||
DATE_REGEX = r"[0-9]{4}-[0-9]{2}-[0-9]{2}" | ||
TITLE_REGEX = ( | ||
"(" | ||
+ re.escape( | ||
TITLE_FORMAT.format(name="NAME_REGEX", version="VERSION_REGEX", project_date="DATE_REGEX") | ||
) | ||
.replace("NAME_REGEX", NAME_REGEX) | ||
.replace("VERSION_REGEX", VERSION_REGEX) | ||
.replace("DATE_REGEX", DATE_REGEX) | ||
+ ")" | ||
) | ||
|
||
|
||
def get_changelog(repo, branch): | ||
return repo.git.show(f"{branch}:{CHANGELOG_FILE}") + "\n" | ||
|
||
|
||
def _tokenize_changes(splits): | ||
assert len(splits) % 3 == 0 | ||
for i in range(len(splits) // 3): | ||
title = splits[3 * i] | ||
version = parse_version(splits[3 * i + 1]) | ||
yield [version, title + splits[3 * i + 2]] | ||
|
||
|
||
def split_changelog(changelog): | ||
preamble, rest = changelog.split(START_STRING, maxsplit=1) | ||
split_rest = re.split(TITLE_REGEX, rest) | ||
return preamble + START_STRING + split_rest[0], list(_tokenize_changes(split_rest[1:])) | ||
|
||
|
||
def main(): | ||
repo = Repo(os.getcwd()) | ||
remote = repo.remotes[0] | ||
branches = [ref for ref in remote.refs if re.match(r"^([0-9]+)\.([0-9]+)$", ref.remote_head)] | ||
branches.sort(key=lambda ref: parse_version(ref.remote_head), reverse=True) | ||
branches = [ref.name for ref in branches] | ||
|
||
with open(CHANGELOG_FILE, "r") as f: | ||
main_changelog = f.read() | ||
preamble, main_changes = split_changelog(main_changelog) | ||
old_length = len(main_changes) | ||
|
||
for branch in branches: | ||
print(f"Looking at branch {branch}") | ||
try: | ||
changelog = get_changelog(repo, branch) | ||
except GitCommandError: | ||
print("No changelog found on this branch.") | ||
continue | ||
dummy, changes = split_changelog(changelog) | ||
new_changes = sorted(main_changes + changes, key=lambda x: x[0], reverse=True) | ||
# Now remove duplicates (retain the first one) | ||
main_changes = [new_changes[0]] | ||
for left, right in itertools.pairwise(new_changes): | ||
if left[0] != right[0]: | ||
main_changes.append(right) | ||
|
||
new_length = len(main_changes) | ||
if old_length < new_length: | ||
print(f"{new_length - old_length} new versions have been added.") | ||
with open(CHANGELOG_FILE, "w") as fp: | ||
fp.write(preamble) | ||
for change in main_changes: | ||
fp.write(change[1]) | ||
|
||
repo.git.commit("-m", "Update Changelog", "-m" "[noissue]", CHANGELOG_FILE) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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
Oops, something went wrong.