Skip to content

Commit

Permalink
Update CI files
Browse files Browse the repository at this point in the history
  • Loading branch information
pulpbot committed Nov 20, 2024
1 parent 630fd7e commit 2b6635b
Show file tree
Hide file tree
Showing 18 changed files with 198 additions and 116 deletions.
23 changes: 0 additions & 23 deletions .bumpversion.cfg

This file was deleted.

2 changes: 1 addition & 1 deletion .ci/assets/release_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
bump2version
bump-my-version
gitpython
towncrier
47 changes: 33 additions & 14 deletions .ci/scripts/calc_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
from packaging.version import Version
import yaml

try:
import tomllib
except ImportError:
import tomli as tomllib


CORE_TEMPLATE_URL = "https://raw.githubusercontent.com/pulp/pulpcore/main/template_config.yml"

Expand Down Expand Up @@ -59,11 +64,11 @@ def to_upper_bound(req):
operator = "~="
version = Version(spec.version)
if version.micro != 0:
max_version = f"{version.major}.{version.minor}.{version.micro-1}"
max_version = f"{version.major}.{version.minor}.{version.micro - 1}"
elif version.minor != 0:
max_version = f"{version.major}.{version.minor-1}"
max_version = f"{version.major}.{version.minor - 1}"
elif version.major != 0:
max_version = f"{version.major-1}.0"
max_version = f"{version.major - 1}.0"
else:
return f"# NO BETTER CONSTRAINT: {req}"
return f"{requirement.name}{operator}{max_version}"
Expand Down Expand Up @@ -100,18 +105,32 @@ def main():
parser.add_argument("filename", nargs="*")
args = parser.parse_args()

with fileinput.input(files=args.filename) as req_file:
for line in req_file:
if line.strip().startswith("#"):
# Shortcut comment only lines
print(line.strip())
else:
req, comment = split_comment(line)
if args.upper:
new_req = to_upper_bound(req)
modifier = to_upper_bound if args.upper else to_lower_bound

req_files = [filename for filename in args.filename if not filename.endswith("pyproject.toml")]
pyp_files = [filename for filename in args.filename if filename.endswith("pyproject.toml")]
if req_files:
with fileinput.input(files=req_files) as req_file:
for line in req_file:
if line.strip().startswith("#"):
# Shortcut comment only lines
print(line.strip())
else:
new_req = to_lower_bound(req)
print(new_req + comment)
req, comment = split_comment(line)
new_req = modifier(req)
print(new_req + comment)
for filename in pyp_files:
with open(filename, "rb") as fp:
pyproject = tomllib.load(fp)
for req in pyproject["project"]["dependencies"]:
new_req = modifier(req)
print(new_req)
optional_dependencies = pyproject["project"].get("optional-dependencies")
if optional_dependencies:
for opt in optional_dependencies.values():
for req in opt:
new_req = modifier(req)
print(new_req)


if __name__ == "__main__":
Expand Down
32 changes: 23 additions & 9 deletions .ci/scripts/check_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import argparse
import re
import os
import tomllib
import yaml
from tempfile import TemporaryDirectory
from packaging.version import Version
Expand All @@ -22,6 +23,17 @@
Z_CHANGELOG_EXTS = [".bugfix", ".doc", ".misc"]


def current_version(repo):
try:
pyproject_toml = tomllib.loads(repo.git.show(f"{DEFAULT_BRANCH}:pyproject.toml"))
current_version = pyproject_toml["project"]["version"]
except Exception:
current_version = repo.git.grep(
"current_version", DEFAULT_BRANCH, "--", ".bumpversion.cfg"
).split("=")[-1]
return Version(current_version)


def main():
"""Check which branches need a release."""
parser = argparse.ArgumentParser()
Expand Down Expand Up @@ -86,6 +98,13 @@ def main():
)
if req_txt_diff:
reasons.append("requirements.txt")
pyproject_diff = repo.git.diff(
f"{last_tag}", f"origin/{branch}", "--name-only", "--", "pyproject.toml"
)
if pyproject_diff:
reasons.append(
"pyproject.toml changed (PLEASE check if dependencies are affected."
)

if reasons:
curr_version = Version(last_tag)
Expand All @@ -106,15 +125,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).base_version
print(f"A new Y-release is needed! New Version: {next_version}")
releases.append(next_version)
break

Expand Down
49 changes: 35 additions & 14 deletions .ci/scripts/check_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
#
# For more info visit https://github.com/pulp/plugin_template

import tomllib
import warnings
from pkg_resources import Requirement
from packaging.requirements import Requirement


CHECK_MATRIX = [
("pyproject.toml", True, True, True),
("requirements.txt", True, True, True),
("dev_requirements.txt", False, True, False),
("ci_requirements.txt", False, True, True),
Expand All @@ -20,17 +22,33 @@
("clitest_requirements.txt", False, True, True),
]

errors = []

for filename, check_upperbound, check_prereleases, check_r in CHECK_MATRIX:
try:
def iterate_file(filename):
if filename == "pyproject.toml":
with open(filename, "rb") as fd:
pyproject_toml = tomllib.load(fd)
if "project" in pyproject_toml:
for nr, line in enumerate(pyproject_toml["project"]["dependencies"]):
yield nr, line
else:
with open(filename, "r") as fd:
for nr, line in enumerate(fd.readlines()):
line = line.strip()
if not line or line.startswith("#"):
continue
if "#" in line:
line = line.split("#", maxsplit=1)[0]
yield nr, line.strip()


def main():
errors = []

for filename, check_upperbound, check_prereleases, check_r in CHECK_MATRIX:
try:
for nr, line in iterate_file(filename):
try:
req = Requirement.parse(line)
req = Requirement(line)
except ValueError:
if line.startswith("git+"):
# The single exception...
Expand All @@ -49,18 +67,21 @@
and req.name != "pulpcore-client"
):
errors.append(f"{filename}:{nr}: Prerelease versions found in {line}.")
ops = [op for op, ver in req.specs]
spec = str(req.specs)
ops = [spec.operator for spec in req.specifier]
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
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)


if errors:
print("Dependency issues found:")
print("\n".join(errors))
exit(1)
if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion .github/template_gitref
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2021.08.26-389-g444ab6c
2021.08.26-396-gde50fc9
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ jobs:
- name: "Install python dependencies"
run: |
echo ::group::PYDEPS
pip install packaging twine wheel mkdocs jq
pip install build packaging twine wheel mkdocs jq
echo ::endgroup::
- name: "Build package"
run: |
python3 setup.py sdist bdist_wheel --python-tag py3
python3 -m build
twine check dist/*
- name: "Install built packages"
run: |
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ jobs:
GITHUB_CONTEXT: "${{ github.event.pull_request.commits_url }}"
run: |
.github/workflows/scripts/check_commit.sh
- name: "Verify requirements files"
run: |
python .ci/scripts/check_requirements.py
docs:
uses: "./.github/workflows/docs.yml"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/create-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: "Install python dependencies"
run: |
echo ::group::PYDEPS
pip install bump2version packaging -r plugin_template/requirements.txt
pip install bump-my-version packaging -r plugin_template/requirements.txt
echo ::endgroup::
- name: "Setting secrets"
Expand All @@ -54,7 +54,7 @@ jobs:
run: |
# Just to be sure...
git checkout main
NEW_BRANCH="$(bump2version --dry-run --list release | sed -Ene 's/^new_version=([[:digit:]]+\.[[:digit:]]+)\..*$/\1/p')"
NEW_BRANCH="$(bump-my-version show new_version --increment release | sed -Ene 's/^([[:digit:]]+\.[[:digit:]]+)\.[[:digit:]]+$/\1/p')"
if [ -z "$NEW_BRANCH" ]
then
echo Could not determine the new branch name.
Expand All @@ -70,7 +70,7 @@ jobs:
- name: Bump version on main branch
working-directory: pulpcore
run: |
bump2version --no-commit minor
bump-my-version bump --no-commit minor
- name: Remove entries from CHANGES directory
working-directory: pulpcore
Expand Down
36 changes: 24 additions & 12 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ defaults:

jobs:
lint:
runs-on: ubuntu-latest
runs-on: "ubuntu-latest"

steps:
- uses: "actions/checkout@v4"
Expand All @@ -34,26 +34,38 @@ jobs:
pip install -r lint_requirements.txt
echo ::endgroup::
- name: Lint workflow files
- name: "Lint workflow files"
run: |
yamllint -s -d '{extends: relaxed, rules: {line-length: disable}}' .github/workflows
- name: "Verify bump version config"
run: |
bump-my-version bump --dry-run release
bump-my-version show-bump
# run black separately from flake8 to get a diff
- name: Run black
- name: "Run black"
run: |
black --version
black --check --diff .
# Lint code.
- name: Run flake8
run: flake8
- name: "Run flake8"
run: |
flake8
- name: "Run extra lint checks"
run: |
[ ! -x .ci/scripts/extra_linting.sh ] || .ci/scripts/extra_linting.sh
- name: Run extra lint checks
run: "[ ! -x .ci/scripts/extra_linting.sh ] || .ci/scripts/extra_linting.sh"
- name: "Check for any files unintentionally left out of MANIFEST.in"
run: |
check-manifest
# check for any files unintentionally left out of MANIFEST.in
- name: Check manifest
run: check-manifest
- name: "Verify requirements files"
run: |
python .ci/scripts/check_requirements.py
- name: Check for gettext problems
run: sh .ci/scripts/check_gettext.sh
- name: "Check for common gettext problems"
run: |
sh .ci/scripts/check_gettext.sh
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: "Install python dependencies"
run: |
echo ::group::PYDEPS
pip install bump2version towncrier
pip install bump-my-version towncrier
echo ::endgroup::
- name: "Configure Git with pulpbot name and email"
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/scripts/before_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ if [ -f $PRE_BEFORE_INSTALL ]; then
source $PRE_BEFORE_INSTALL
fi

if [[ -n $(echo -e $COMMIT_MSG | grep -P "Required PR:.*") ]]; then
echo "The Required PR mechanism has been removed. Consider adding a scm requirement to requirements.txt."
exit 1
fi

if [ "$GITHUB_EVENT_NAME" = "pull_request" ] || [ "${BRANCH_BUILD}" = "1" -a "${BRANCH}" != "main" ]
then
echo $COMMIT_MSG | sed -n -e 's/.*CI Base Image:\s*\([-_/[:alnum:]]*:[-_[:alnum:]]*\).*/ci_base: "\1"/p' >> .ci/ansible/vars/main.yaml
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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="./pulpcore/dist/pulpcore-${PLUGIN_VERSION}-py3-none-any.whl"

export PULP_API_ROOT="/pulp/"
Expand Down
Loading

0 comments on commit 2b6635b

Please sign in to comment.