From 36811e14540be0f31d2be2f1a66ffa2393ac38b9 Mon Sep 17 00:00:00 2001 From: pulpbot Date: Sun, 24 Nov 2024 03:42:45 +0000 Subject: [PATCH] Update CI files --- .bumpversion.cfg | 21 -------- .ci/scripts/check_release.py | 76 +++++++++++++++++++--------- .ci/scripts/check_requirements.py | 5 +- .github/template_gitref | 2 +- .github/workflows/scripts/install.sh | 2 +- .github/workflows/test.yml | 2 +- .github/workflows/update_ci.yml | 40 +++++++-------- pyproject.toml | 31 ++++++++++++ 8 files changed, 106 insertions(+), 73 deletions(-) delete mode 100644 .bumpversion.cfg diff --git a/.bumpversion.cfg b/.bumpversion.cfg deleted file mode 100644 index 009b416c7..000000000 --- a/.bumpversion.cfg +++ /dev/null @@ -1,21 +0,0 @@ -[bumpversion] -current_version = 2.20.5.dev -commit = False -tag = False -parse = (?P\d+)\.(?P\d+)\.(?P\d+)(\.(?P[a-z]+))? -serialize = - {major}.{minor}.{patch}.{release} - {major}.{minor}.{patch} - -[bumpversion:part:release] -optional_value = prod -first_value = dev -values = - dev - prod - -[bumpversion:file:./pulp_container/app/__init__.py] - -[bumpversion:file:./setup.py] - -[bumpversion:file:./docs/conf.py] diff --git a/.ci/scripts/check_release.py b/.ci/scripts/check_release.py index b26a48654..095dd739b 100755 --- a/.ci/scripts/check_release.py +++ b/.ci/scripts/check_release.py @@ -1,28 +1,21 @@ #!/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_container' to update this file. -# -# For more info visit https://github.com/pulp/plugin_template - import argparse import re import os +import tomllib import yaml +from pathlib import Path from tempfile import TemporaryDirectory from packaging.version import Version from git import Repo -UPSTREAM_REMOTE = "https://github.com/pulp/pulp_container.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(): +def options(): """Check which branches need a release.""" parser = argparse.ArgumentParser() parser.add_argument( @@ -32,17 +25,57 @@ def main(): "'supported'. Defaults to 'supported', see `supported_release_branches` in " "`plugin_template.yml`.", ) - opts = parser.parse_args() + return parser.parse_args() + + +def template_config(): + # Assume this script lies in .ci/scripts + path = Path(__file__).absolute().parent.parent.parent / "template_config.yml" + return yaml.safe_load(path.read_text()) + +def current_version(repo, commitish): + try: + pyproject_toml = tomllib.loads(repo.git.show(f"{commitish}:pyproject.toml")) + current_version = pyproject_toml["project"]["version"] + except Exception: + current_version = repo.git.grep( + "current_version", commitish, "--", ".bumpversion.cfg" + ).split("=")[-1] + return Version(current_version) + + +def check_pyproject_dependencies(repo, from_commit, to_commit): + try: + old_pyproject = tomllib.load(repo.show("{from_commit}:pyproject.toml")) + old_dependencies = set(old_pyproject["project"]["dependencies"]) + new_pyproject = tomllib.load(repo.show("{to_commit}:pyproject.toml")) + new_dependencies = set(new_pyproject["project"]["dependencies"]) + if old_dependencies != new_dependencies: + return ["dependencies"] + else: + return [] + except Exception as e: + print(f"WARNING: Comparing the dependencies in pyproject.toml failed. ({e})") + # Gathering more details failed. + return ["pyproject.toml changed somehow (PLEASE check if dependencies are affected)."] + + +def main(options, template_config): with TemporaryDirectory() as d: # Clone from upstream to ensure we have updated branches & main + GITHUB_ORG = template_config["github_org"] + PLUGIN_NAME = template_config["plugin_name"] + UPSTREAM_REMOTE = f"https://github.com/{GITHUB_ORG}/{PLUGIN_NAME}.git" + DEFAULT_BRANCH = template_config["plugin_default_branch"] + 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 + branches = options.branches if branches == "supported": with open(f"{d}/template_config.yml", mode="r") as f: tc = yaml.safe_load(f) @@ -90,9 +123,7 @@ def main(): f"{last_tag}", f"origin/{branch}", "--name-only", "--", "pyproject.toml" ) if pyproject_diff: - reasons.append( - "pyproject.toml changed (PLEASE check if dependencies are affected." - ) + reasons.extend(check_pyproject_dependencies(repo, last_tag, f"origin/{branch}")) if reasons: curr_version = Version(last_tag) @@ -113,15 +144,10 @@ def main(): 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}" - ) + # We don't put Y release bumps in the commit message, check file instead. + # The 'current_version' is always the dev of the next version to release. + next_version = current_version(repo, DEFAULT_BRANCH).base_version + print(f"A new Y-release is needed! New Version: {next_version}") releases.append(next_version) break @@ -130,4 +156,4 @@ def main(): if __name__ == "__main__": - main() + main(options(), template_config()) diff --git a/.ci/scripts/check_requirements.py b/.ci/scripts/check_requirements.py index c0c883a9d..28bf8e53b 100755 --- a/.ci/scripts/check_requirements.py +++ b/.ci/scripts/check_requirements.py @@ -62,10 +62,7 @@ def main(): 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-container-client" - ): + if req.name != "pulp-container-client": errors.append(f"{filename}:{nr}: Prerelease versions found in {line}.") ops = [spec.operator for spec in req.specifier] if "~=" in ops: diff --git a/.github/template_gitref b/.github/template_gitref index d37a43c86..8156a7ac1 100644 --- a/.github/template_gitref +++ b/.github/template_gitref @@ -1 +1 @@ -2021.08.26-393-g0e700c1 +2021.08.26-399-g78ad960 diff --git a/.github/workflows/scripts/install.sh b/.github/workflows/scripts/install.sh index 8fc7f374c..89f162da3 100755 --- a/.github/workflows/scripts/install.sh +++ b/.github/workflows/scripts/install.sh @@ -15,7 +15,7 @@ set -euv source .github/workflows/scripts/utils.sh -PLUGIN_VERSION="$(sed -n -e 's/^\s*current_version\s*=\s*//p' .bumpversion.cfg | python -c 'from packaging.version import Version; print(Version(input()))')" +PLUGIN_VERSION="$(bump-my-version show current_version | tail -n -1 | python -c 'from packaging.version import Version; print(Version(input()))')" PLUGIN_SOURCE="./pulp_container/dist/pulp_container-${PLUGIN_VERSION}-py3-none-any.whl" export PULP_API_ROOT="/pulp/" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e9c81a01a..b9eceb261 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -71,7 +71,7 @@ jobs: - name: "Install python dependencies" run: | echo ::group::PYDEPS - pip install towncrier twine wheel httpie docker netaddr boto3 'ansible~=10.3.0' mkdocs jq jsonpatch + pip install towncrier twine wheel httpie docker netaddr boto3 'ansible~=10.3.0' mkdocs jq jsonpatch bump-my-version echo "HTTPIE_CONFIG_DIR=$GITHUB_WORKSPACE/pulp_container/.ci/assets/httpie/" >> $GITHUB_ENV echo ::endgroup:: diff --git a/.github/workflows/update_ci.yml b/.github/workflows/update_ci.yml index 0425c426a..e43f9397d 100644 --- a/.github/workflows/update_ci.yml +++ b/.github/workflows/update_ci.yml @@ -69,7 +69,7 @@ jobs: with: fetch-depth: 0 path: "pulp_container" - ref: "2.19" + ref: "2.10" - name: "Run update" working-directory: "pulp_container" @@ -83,15 +83,15 @@ jobs: path: "pulp_container" committer: "pulpbot " author: "pulpbot " - title: "Update CI files for branch 2.19" - branch: "update-ci/2.19" - base: "2.19" + title: "Update CI files for branch 2.10" + branch: "update-ci/2.10" + base: "2.10" delete-branch: true - uses: "actions/checkout@v4" with: fetch-depth: 0 path: "pulp_container" - ref: "2.10" + ref: "2.14" - name: "Run update" working-directory: "pulp_container" @@ -105,15 +105,15 @@ jobs: path: "pulp_container" committer: "pulpbot " author: "pulpbot " - title: "Update CI files for branch 2.10" - branch: "update-ci/2.10" - base: "2.10" + title: "Update CI files for branch 2.14" + branch: "update-ci/2.14" + base: "2.14" delete-branch: true - uses: "actions/checkout@v4" with: fetch-depth: 0 path: "pulp_container" - ref: "2.14" + ref: "2.15" - name: "Run update" working-directory: "pulp_container" @@ -127,15 +127,15 @@ jobs: path: "pulp_container" committer: "pulpbot " author: "pulpbot " - title: "Update CI files for branch 2.14" - branch: "update-ci/2.14" - base: "2.14" + title: "Update CI files for branch 2.15" + branch: "update-ci/2.15" + base: "2.15" delete-branch: true - uses: "actions/checkout@v4" with: fetch-depth: 0 path: "pulp_container" - ref: "2.15" + ref: "2.16" - name: "Run update" working-directory: "pulp_container" @@ -149,15 +149,15 @@ jobs: path: "pulp_container" committer: "pulpbot " author: "pulpbot " - title: "Update CI files for branch 2.15" - branch: "update-ci/2.15" - base: "2.15" + title: "Update CI files for branch 2.16" + branch: "update-ci/2.16" + base: "2.16" delete-branch: true - uses: "actions/checkout@v4" with: fetch-depth: 0 path: "pulp_container" - ref: "2.16" + ref: "2.19" - name: "Run update" working-directory: "pulp_container" @@ -171,8 +171,8 @@ jobs: path: "pulp_container" committer: "pulpbot " author: "pulpbot " - title: "Update CI files for branch 2.16" - branch: "update-ci/2.16" - base: "2.16" + title: "Update CI files for branch 2.19" + branch: "update-ci/2.19" + base: "2.19" delete-branch: true ... diff --git a/pyproject.toml b/pyproject.toml index 5136c57e3..0340af1bd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,3 +51,34 @@ ignore = [ "lint_requirements.txt", ".flake8", ] + +[tool.bumpversion] +# This section is managed by the plugin template. Do not edit manually. + +current_version = "2.20.5.dev" +commit = false +tag = false +parse = "(?P\\d+)\\.(?P\\d+)\\.(?P\\d+)(\\.(?P[a-z]+))?" +serialize = [ + "{major}.{minor}.{patch}.{release}", + "{major}.{minor}.{patch}", +] + +[tool.bumpversion.parts.release] +# This section is managed by the plugin template. Do not edit manually. + +optional_value = "prod" +values = [ + "dev", + "prod", +] + +[[tool.bumpversion.files]] +# This section is managed by the plugin template. Do not edit manually. + +filename = "./pulp_container/app/__init__.py" +search = "version = \"{current_version}\"" +replace = "version = \"{new_version}\"" + +[[tool.bumpversion.files]] +filename = "./setup.py" \ No newline at end of file