Skip to content

Commit

Permalink
Update CI
Browse files Browse the repository at this point in the history
  • Loading branch information
mdellweg committed May 3, 2024
1 parent e14a92b commit d79e58a
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .ci/scripts/collect_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def main():
for change in main_changes:
fp.write(change[1])

repo.git.commit("-m", "Update Changelog", "-m" "[noissue]", CHANGELOG_FILE)
repo.git.commit("-m", "Update Changelog", CHANGELOG_FILE)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion .ci/scripts/create_release_branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ git branch "${NEW_BRANCH}"
# Clean changelog snippets.
find CHANGES/ \( -name "*.feature" -o -name "*.bugfix" -o -name "*.removal" -o -name "*.doc" -o -name "*.translation" -o -name "*.devel" -o -name "*.misc" \) -exec git rm -f \{\} +

bump-my-version bump minor --commit --message $'Bump version to {new_version}\n\n[noissue]' --allow-dirty
bump-my-version bump minor --commit --message $'Bump version to {new_version}' --allow-dirty

git push origin "${NEW_BRANCH}"
57 changes: 57 additions & 0 deletions .ci/scripts/pr_labels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/env python3

# This script is running with elevated privileges from the main branch against pull requests.

import re
import sys
import tomllib
from pathlib import Path

from git import Repo


def main():
assert len(sys.argv) == 3

with open("pyproject.toml", "rb") as fp:
PYPROJECT_TOML = tomllib.load(fp)
BLOCKING_REGEX = re.compile(r"DRAFT|WIP|NO\s*MERGE|DO\s*NOT\s*MERGE|EXPERIMENT")
ISSUE_REGEX = re.compile(r"(?:fixes|closes)[\s:]+#(\d+)")
CHERRY_PICK_REGEX = re.compile(r"^\s*\(cherry picked from commit [0-9a-f]*\)\s*$")
CHANGELOG_EXTS = [
f".{item['directory']}" for item in PYPROJECT_TOML["tool"]["towncrier"]["type"]
]

repo = Repo(".")

base_commit = repo.commit(sys.argv[1])
head_commit = repo.commit(sys.argv[2])

pr_commits = list(repo.iter_commits(f"{base_commit}..{head_commit}"))

labels = {
"multi-commit": len(pr_commits) > 1,
"cherry-pick": False,
"no-issue": False,
"no-changelog": False,
"wip": False,
}
for commit in pr_commits:
labels["wip"] |= BLOCKING_REGEX.search(commit.summary) is not None
no_issue = ISSUE_REGEX.search(commit.message, re.IGNORECASE) is None
labels["no-issue"] |= no_issue
cherry_pick = CHERRY_PICK_REGEX.search(commit.message) is not None
labels["cherry-pick"] |= cherry_pick
changelog_snippets = [
k
for k in commit.stats.files
if k.startswith("CHANGES/") and Path(k).suffix in CHANGELOG_EXTS
]
labels["no-changelog"] |= not changelog_snippets

print("ADD_LABELS=" + ",".join((k for k, v in labels.items() if v)))
print("REMOVE_LABELS=" + ",".join((k for k, v in labels.items() if not v)))


if __name__ == "__main__":
main()
9 changes: 0 additions & 9 deletions .ci/scripts/validate_commit_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
r"DO\s*NOT\s*MERGE",
"EXPERIMENT",
]
NO_ISSUE = "[noissue]"
CHANGELOG_EXTS = [f".{item['directory']}" for item in PYPROJECT_TOML["tool"]["towncrier"]["type"]]

sha = sys.argv[1]
Expand Down Expand Up @@ -61,13 +60,5 @@ def check_changelog(issue):
if not cherry_pick:
check_status(issue)
check_changelog(issue)
else:
if NO_ISSUE in message:
print("Commit {sha} has no issues but is tagged {tag}.".format(sha=sha[0:7], tag=NO_ISSUE))
else:
sys.exit(
"Error: no attached issues found for {sha}. If this was intentional, add "
" '{tag}' to the commit message.".format(sha=sha[0:7], tag=NO_ISSUE)
)

print("Commit message for {sha} passed.".format(sha=sha[0:7]))
7 changes: 0 additions & 7 deletions .flake8

This file was deleted.

4 changes: 0 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ updates:
schedule:
interval: daily
open-pull-requests-limit: 10
commit-message:
prefix: "[noissue]"
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
commit-message:
prefix: "[noissue]"
23 changes: 14 additions & 9 deletions .github/workflows/pr_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,31 @@ concurrency:
jobs:
single_commit:
runs-on: "ubuntu-latest"
name: "Label multiple commit PR"
name: "Label PR"
permissions:
pull-requests: "write"
steps:
- uses: "actions/checkout@v4"
with:
fetch-depth: 0
- name: "Commit Count Check"
- uses: "actions/setup-python@v5"
with:
python-version: "3.12"
- name: "Determine PR labels"
run: |
pip install GitPython==3.1.42
git fetch origin ${{ github.event.pull_request.head.sha }}
echo "COMMIT_COUNT=$(git log --oneline --no-merges origin/${{ github.base_ref }}..${{ github.event.pull_request.head.sha }} | wc -l)" >> "$GITHUB_ENV"
python .ci/scripts/pr_labels.py "origin/${{ github.base_ref }}" "${{ github.event.pull_request.head.sha }}" >> "$GITHUB_ENV"
- uses: "actions/github-script@v7"
name: "Apply PR Labels"
with:
script: |
const labelName = "multi-commit";
const { COMMIT_COUNT } = process.env;
const { ADD_LABELS, REMOVE_LABELS } = process.env;
const addLabels = ADD_LABELS.split(",");
const removeLabels = REMOVE_LABELS.split(",");
if (COMMIT_COUNT == 1)
{
for await (const labelName of removeLabels) {
try {
await github.rest.issues.removeLabel({
issue_number: context.issue.number,
Expand All @@ -44,8 +50,7 @@ jobs:
} catch(err) {
}
}
else
{
for await (const labelName of addLabels) {
await github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
uses: "actions/setup-python@v5"
with:
python-version: "${{ matrix.python }}"
- name: "Install Test Dependencies"
- name: "Install Python Test Dependencies"
run: |
if [ "${{matrix.lower_bounds}}" ]
then
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
__pycache__/
build/
tests/cli.toml
pytest_pulp_cli/GPG-PRIVATE-KEY-fixture-signing
/.ci/settings/certs
site/
dist/
*.po~
4 changes: 2 additions & 2 deletions lint_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Lint requirements
black==24.4.0
black==24.4.2
flake8==7.0.0
flake8-pyproject==1.2.3
isort==5.13.2
mypy==1.9.0
mypy==1.10.0
shellcheck-py==0.10.0.1

# Type annotation stubs
Expand Down
54 changes: 41 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ changelog = "https://github.com/pulp/pulp-cli-gem/blob/main/CHANGES.md"
gem = "pulpcore.cli.gem"

[tool.setuptools.packages.find]
# This section is managed by the cookiecutter templates.
where = ["."]
include = ["pulpcore.cli.*"]
namespaces = true

[tool.setuptools.package-data]
"*" = ["py.typed", "locale/*/LC_MESSAGES/*.mo"]
# This section is managed by the cookiecutter templates.
"*" = ["py.typed"]


[tool.pulp_cli_template]
# This section is co-managed by the cookiecutter templates.
Expand All @@ -50,65 +53,68 @@ glue = true
docs = false
translations = false
main_package = "gem"
binary_dependencies = ""

[tool.towncrier]
# This section is managed by the cookiecutter templates.
filename = "CHANGES.md"
directory = "CHANGES/"
title_format = "## {version} ({project_date})"
title_format = "## {version} ({project_date}) {{: #{version} }}"
template = "CHANGES/.TEMPLATE.md"
issue_format = "[#{issue}](https://github.com/pulp/pulp-cli-gem/issues/{issue})"
start_string = "[//]: # (towncrier release notes start)\n"
underlines = ["", "", ""]

[[tool.towncrier.section]]
# This section is managed by the cookiecutter templates.
path = ""
name = ""

[[tool.towncrier.section]]
# This section is managed by the cookiecutter templates.
path = "pulp-glue-gem"
name = "Pulp-gem GLUE"

[[tool.towncrier.type]]
# This section is managed by the cookiecutter templates.
directory = "feature"
name = "Features"
showcontent = true

[[tool.towncrier.type]]
# This section is managed by the cookiecutter templates.
directory = "bugfix"
name = "Bugfixes"
showcontent = true

[[tool.towncrier.type]]
directory = "doc"
name = "Improved Documentation"
showcontent = true

[[tool.towncrier.type]]
# This section is managed by the cookiecutter templates.
directory = "removal"
name = "Deprecations and Removals"
showcontent = true

[[tool.towncrier.type]]
directory = "translation"
name = "Translations"
showcontent = true

[[tool.towncrier.type]]
# This section is managed by the cookiecutter templates.
directory = "devel"
name = "Developer Notes"
showcontent = true

[[tool.towncrier.type]]
# This section is managed by the cookiecutter templates.
directory = "misc"
name = "Misc"
showcontent = false


[tool.black]
# This section is managed by the cookiecutter templates.
line-length = 100

[tool.isort]
# This section is managed by the cookiecutter templates.
profile = "black"
line_length = 100
skip = ["pulp-glue-gem"]

[tool.pytest.ini_options]
markers = [
Expand All @@ -118,15 +124,20 @@ markers = [
]

[tool.mypy]
# This section is managed by the cookiecutter templates.
strict = true
warn_unused_ignores = false
show_error_codes = true
files = "pulpcore/**/*.py"
files = "pulpcore/**/*.py, tests/*.py"
namespace_packages = true
explicit_package_bases = true

[[tool.mypy.overrides]]
# This section is managed by the cookiecutter templates.
module = [
"click_shell.*",
"gnupg.*",
"IPython.*",
"schema.*",
]
ignore_missing_imports = true
Expand All @@ -143,33 +154,50 @@ serialize = [
]

[tool.bumpversion.parts.release]
# This section is managed by the cookiecutter templates.
optional_value = "prod"
values = [
"dev",
"prod",
]

[[tool.bumpversion.files]]
# This section is managed by the cookiecutter templates.
filename = "./pulp-glue-gem/pulp_glue/gem/__init__.py"
search = "__version__ = \"{current_version}\""
replace = "__version__ = \"{new_version}\""

[[tool.bumpversion.files]]
# This section is managed by the cookiecutter templates.
filename = "./pulpcore/cli/gem/__init__.py"
search = "__version__ = \"{current_version}\""
replace = "__version__ = \"{new_version}\""

[[tool.bumpversion.files]]
# This section is managed by the cookiecutter templates.
filename = "./pulp-glue-gem/pyproject.toml"
search = "version = \"{current_version}\""
replace = "version = \"{new_version}\""

[[tool.bumpversion.files]]
# This section is managed by the cookiecutter templates.
filename = "./pyproject.toml"
search = "version = \"{current_version}\""
replace = "version = \"{new_version}\""

[[tool.bumpversion.files]]
# This section is managed by the cookiecutter templates.
filename = "./pyproject.toml"
search = "\"pulp-glue-gem=={current_version}\""
replace = "\"pulp-glue-gem=={new_version}\""


[tool.flake8]
# This section is managed by the cookiecutter templates.
exclude = ["./docs/*"]
ignore = ["W503", "Q000", "Q003", "D100", "D104", "D106", "D200", "D202", "D205", "D400", "D401", "D402"]
# E203: whitespace before ':'; https://github.com/psf/black/issues/279
# E401: multiple imports on one line
extend-ignore = ["E203", "E401"]
max-line-length = 100

5 changes: 3 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import typing as t
from urllib.parse import urljoin

import pytest
Expand All @@ -6,9 +7,9 @@


@pytest.fixture
def pulp_cli_vars(pulp_cli_vars):
def pulp_cli_vars(pulp_cli_vars: t.MutableMapping[str, str]) -> t.MutableMapping[str, str]:
PULP_FIXTURES_URL = pulp_cli_vars["PULP_FIXTURES_URL"]
result = {}
result: t.MutableMapping[str, str] = {}
result.update(pulp_cli_vars)
result.update(
{
Expand Down

0 comments on commit d79e58a

Please sign in to comment.