Skip to content

Commit

Permalink
Better handle the latest release branch
Browse files Browse the repository at this point in the history
Fixes #831
  • Loading branch information
mdellweg authored and gerrod3 committed Jan 24, 2024
1 parent d58d154 commit 238784d
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 40 deletions.
4 changes: 4 additions & 0 deletions CHANGES/831.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Changed the handling of the latest release branch as a one off supported branch.

The ci_update_branches variable is now replaced by supported_release_branches and will not be touched by automation anymore.
However the latest_release_branch will be set by the create release branch workflow.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ The following settings are stored in `template_config.yml`.
'github'. To switch from Redmine to GitHub use the --migrate-github-issues
option.

ci_update_branches Specify the branches that should receive regular CI updates.
latest_release_branch A pointer to the currently latest release branch (this is automatically
updated).

docs_test Include a CI build for testing the 'make html' command for sphinx docs.

Expand Down Expand Up @@ -164,6 +165,9 @@ The following settings are stored in `template_config.yml`.
The number of days of inactivity before an Issue or Pull Request with the stale
label is closed.

supported_release_branches
Specify the release branches that should receive regular CI updates.

sync_ci Enables a nightly workflow to update the CI files.

test_cli Run the pulp-cli tests as part of the CI tests
Expand Down
59 changes: 31 additions & 28 deletions plugin-template
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ DEFAULT_SETTINGS = {
"cli_repo": "https://github.com/pulp/pulp-cli.git",
"ci_env": {},
"ci_trigger": "{pull_request: {branches: ['*']}}",
"ci_update_branches": [],
"ci_update_docs": False,
"ci_update_release_behavior": None,
"core_import_allowed": [],
"deploy_client_to_pypi": True,
"deploy_client_to_rubygems": True,
Expand All @@ -45,6 +43,7 @@ DEFAULT_SETTINGS = {
"github_org": "pulp",
"issue_tracker": "github",
"kanban": True,
"latest_release_branch": None,
"lint_requirements": True,
"noissue_marker": "[noissue]",
"parallel_test_workers": 8,
Expand Down Expand Up @@ -73,6 +72,7 @@ DEFAULT_SETTINGS = {
"stalebot_days_until_stale": 90,
"stalebot_limit_to_pulls": True,
"stalebot": True,
"supported_release_branches": [],
"sync_ci": True,
"test_azure": False,
"test_cli": False,
Expand Down Expand Up @@ -216,14 +216,12 @@ def main():
),
)
parser.add_argument(
"--add-version-ci-update-branches",
"--latest-release-branch",
metavar="VERSION_BRANCH",
action="store",
help=textwrap.dedent(
"""\
Add specified version to the ci_update_branches before templating.
This new value will replace the previous latest version if
`ci_update_release_behavior` is set to 'replace-previous-version'.
Mark specified version as the latest_release_branch before templating.
"""
),
Expand All @@ -247,6 +245,10 @@ def main():
if key not in config:
config[key] = value
write_new_config = True
# Rename "ci_update_branches" to "supported_release_branches"
if "ci_update_branches" in config:
config["supported_release_branches"] = config.pop("ci_update_branches")
write_new_config = True
# remove deprecated options
for key in set(config.keys()) - set(DEFAULT_SETTINGS.keys()):
config.pop(key)
Expand All @@ -256,10 +258,13 @@ def main():
{"name": config["plugin_name"], "app_label": config["plugin_app_label"]}
]
if not all(
(isinstance(version, str) for version in config["ci_update_branches"])
(
isinstance(version, str)
for version in config["supported_release_branches"]
)
):
config["ci_update_branches"] = [
str(version) for version in config["ci_update_branches"]
config["supported_release_branches"] = [
str(version) for version in config["supported_release_branches"]
]
write_new_config = True
print(
Expand Down Expand Up @@ -292,25 +297,9 @@ def main():
else:
return 2

valid_release_behavior = [None, "append-version", "replace-previous-version"]
if config["ci_update_release_behavior"] not in valid_release_behavior:
valid_release_behavior[0] = "null"
print("ci_update_release_behavior is not of a valid value: ", valid_release_behavior)
return 2

if new_version_branch := args.add_version_ci_update_branches:
if args.latest_release_branch:
write_new_config = True
if config["ci_update_release_behavior"] == "replace-previous-version":
major_v, minor_v = new_version_branch.split(".", maxsplit=1)
minor_v = int(minor_v) - 1
try:
index = config["ci_update_branches"].index(f"{major_v}.{minor_v}")
except ValueError:
config["ci_update_branches"].append(new_version_branch)
else:
config["ci_update_branches"][index] = new_version_branch
else:
config["ci_update_branches"].append(new_version_branch)
config["latest_release_branch"] = str(args.latest_release_branch)

# Config key is used by the template_config.yml.j2 template to dump
# the config. (note: uses .copy() to avoid a self reference)
Expand Down Expand Up @@ -381,6 +370,20 @@ def write_template_section(config, name, plugin_root_dir, verbose=False):
except Exception:
gitref = "unknown"

ci_update_branches = [config["plugin_default_branch"]]
latest_release_branch = config["latest_release_branch"]
if latest_release_branch is not None:
if latest_release_branch not in config["supported_release_branches"]:
ci_update_branches.append(latest_release_branch)
ci_update_branches.extend(config["supported_release_branches"])

template_vars = {
"section": name,
"gitref": gitref,
"ci_update_branches": ci_update_branches,
**config,
}

for relative_path in generate_relative_path_set(section_template_dir):
if not config["stalebot"] and "stale" in relative_path:
continue
Expand All @@ -405,7 +408,7 @@ def write_template_section(config, name, plugin_root_dir, verbose=False):
template,
plugin_root_dir,
destination,
{"section": name, "gitref": gitref, **config},
template_vars,
)
files_templated += 1
if verbose:
Expand Down
13 changes: 8 additions & 5 deletions templates/github/.ci/scripts/check_release.py.j2
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def main():
"--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 "
"'supported'. Defaults to 'supported', see `supported_release_branches` in "
"`plugin_template.yml`.",
)
opts = parser.parse_args()
Expand All @@ -41,12 +41,15 @@ def main():
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)
branches = set(tc["supported_release_branches"])
latest_release_branch = tc["latest_release_branch"]
if latest_release_branch is not None:
branches.add(latest_release_branch)
branches.add(DEFAULT_BRANCH)
else:
branches = branches.split(",")
branches = set(branches.split(","))

if diff := set(branches) - set(available_branches):
if diff := branches - set(available_branches):
print(f"Supplied branches contains non-existent branches! {diff}")
exit(1)

Expand Down
6 changes: 3 additions & 3 deletions templates/github/.github/workflows/create-branch.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
working-directory: {{ plugin_name }}
run: |
find CHANGES -type f -regex ".*\.\(bugfix\|doc\|feature\|misc\|deprecation\|removal\)" -exec git rm {} +
{% if ci_update_release_behavior %}

- name: Checkout plugin template
uses: actions/checkout@v3
with:
Expand All @@ -67,9 +67,9 @@ jobs:
- name: Update CI branches in template_config
working-directory: plugin_template
run: |
python3 ./plugin-template {{ plugin_name }} --github --add-version-ci-update-branches "${NEW_BRANCH}"
python3 ./plugin-template {{ plugin_name }} --github --latest-release-branch "${NEW_BRANCH}"
git add -A
{% endif %}

- name: Make a PR with version bump and without CHANGES/*
uses: peter-evans/create-pull-request@v4
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ response = session.get("https://api.github.com/repos/pulp/{{ plugin_name }}/labe
assert response.status_code == 200
old_labels = set([x["name"] for x in response.json() if x["name"].startswith("backport-")])

# get ci_update_branches from template_config.yml
# get list of branches from template_config.yml
with open("./template_config.yml", "r") as f:
plugin_template = yaml.safe_load(f)
new_labels = set(["backport-" + x for x in plugin_template["ci_update_branches"]])
branches = set(plugin_template["supported_release_branches"])
latest_release_branch = plugin_template["latest_release_branch"]
if latest_release_branch is not None:
branches.add(latest_release_branch)
new_labels = {"backport-" + x for x in branches}

# delete old labels that are not in new labels
for label in old_labels.difference(new_labels):
Expand Down
2 changes: 1 addition & 1 deletion templates/github/.github/workflows/update_ci.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:

{{ configure_git() | indent(6) }}

{%- for branch in [plugin_default_branch] + ci_update_branches %}
{%- for branch in ci_update_branches %}
{{ checkout(path=plugin_name, ref=branch, depth=0) | indent(6) }}

- name: "Run update"
Expand Down

0 comments on commit 238784d

Please sign in to comment.