diff --git a/CHANGES/831.feature b/CHANGES/831.feature new file mode 100644 index 00000000..c416d0e2 --- /dev/null +++ b/CHANGES/831.feature @@ -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. diff --git a/README.md b/README.md index bf65bbd8..68d0a629 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 diff --git a/plugin-template b/plugin-template index 88e14454..7b253837 100755 --- a/plugin-template +++ b/plugin-template @@ -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, @@ -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, @@ -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, @@ -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. """ ), @@ -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) @@ -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( @@ -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) @@ -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 @@ -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: diff --git a/templates/github/.ci/scripts/check_release.py.j2 b/templates/github/.ci/scripts/check_release.py.j2 old mode 100644 new mode 100755 index 29b6f598..c93bc7cb --- a/templates/github/.ci/scripts/check_release.py.j2 +++ b/templates/github/.ci/scripts/check_release.py.j2 @@ -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() @@ -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) diff --git a/templates/github/.github/workflows/create-branch.yml.j2 b/templates/github/.github/workflows/create-branch.yml.j2 index e163f001..2857c3c2 100644 --- a/templates/github/.github/workflows/create-branch.yml.j2 +++ b/templates/github/.github/workflows/create-branch.yml.j2 @@ -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: @@ -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: diff --git a/templates/github/.github/workflows/scripts/update_backport_labels.py.j2 b/templates/github/.github/workflows/scripts/update_backport_labels.py.j2 index 5901f002..45066988 100644 --- a/templates/github/.github/workflows/scripts/update_backport_labels.py.j2 +++ b/templates/github/.github/workflows/scripts/update_backport_labels.py.j2 @@ -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): diff --git a/templates/github/.github/workflows/update_ci.yml.j2 b/templates/github/.github/workflows/update_ci.yml.j2 index fec8da63..c972ec96 100644 --- a/templates/github/.github/workflows/update_ci.yml.j2 +++ b/templates/github/.github/workflows/update_ci.yml.j2 @@ -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"