Skip to content

Commit 2d05144

Browse files
committed
Update CI
1 parent 6491198 commit 2d05144

20 files changed

+236
-150
lines changed

.bumpversion.cfg

-21
This file was deleted.

.ci/run_container.sh

-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
#!/bin/sh
22

3-
# This file is shared between some projects please keep all copies in sync
4-
# Known places:
5-
# - https://github.com/pulp/pulp-cli/blob/main/.ci/run_container.sh
6-
# - https://github.com/pulp/pulp-cli-deb/blob/main/.ci/run_container.sh
7-
# - https://github.com/pulp/pulp-cli-gem/blob/main/.ci/run_container.sh
8-
# - https://github.com/pulp/pulp-cli-maven/blob/main/.ci/run_container.sh
9-
# - https://github.com/pulp/pulp-cli-ostree/blob/main/.ci/run_container.sh
10-
# - https://github.com/pulp/squeezer/blob/develop/tests/run_container.sh
11-
123
set -eu
134

145
BASEPATH="$(dirname "$(readlink -f "$0")")"

.ci/scripts/collect_changes.py

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
#!/bin/env python3
2+
13
import itertools
24
import os
35
import re
6+
import tomllib
47

5-
import toml
68
from git import GitCommandError, Repo
79
from packaging.version import parse as parse_version
810

911
# Read Towncrier settings
10-
tc_settings = toml.load("pyproject.toml")["tool"]["towncrier"]
12+
with open("pyproject.toml", "rb") as fp:
13+
tc_settings = tomllib.load(fp)["tool"]["towncrier"]
1114

1215
CHANGELOG_FILE = tc_settings.get("filename", "NEWS.rst")
1316
START_STRING = tc_settings.get(
@@ -21,23 +24,32 @@
2124
TITLE_FORMAT = tc_settings.get("title_format", "{name} {version} ({project_date})")
2225

2326

27+
# Build a regex to find the header of a changelog section.
28+
# It must have a single capture group to single out the version.
29+
# see help(re.split) for more info.
2430
NAME_REGEX = r".*"
25-
VERSION_REGEX = r"([0-9]+\.[0-9]+\.[0-9][0-9ab]*)"
31+
VERSION_REGEX = r"[0-9]+\.[0-9]+\.[0-9][0-9ab]*"
32+
VERSION_CAPTURE_REGEX = rf"({VERSION_REGEX})"
2633
DATE_REGEX = r"[0-9]{4}-[0-9]{2}-[0-9]{2}"
2734
TITLE_REGEX = (
2835
"("
2936
+ re.escape(
3037
TITLE_FORMAT.format(name="NAME_REGEX", version="VERSION_REGEX", project_date="DATE_REGEX")
3138
)
3239
.replace("NAME_REGEX", NAME_REGEX)
40+
.replace("VERSION_REGEX", VERSION_CAPTURE_REGEX, 1)
3341
.replace("VERSION_REGEX", VERSION_REGEX)
3442
.replace("DATE_REGEX", DATE_REGEX)
3543
+ ")"
3644
)
3745

3846

3947
def get_changelog(repo, branch):
40-
return repo.git.show(f"{branch}:{CHANGELOG_FILE}") + "\n"
48+
branch_tc_settings = tomllib.loads(repo.git.show(f"{branch}:pyproject.toml"))["tool"][
49+
"towncrier"
50+
]
51+
branch_changelog_file = branch_tc_settings.get("filename", "NEWS.rst")
52+
return repo.git.show(f"{branch}:{branch_changelog_file}") + "\n"
4153

4254

4355
def _tokenize_changes(splits):
@@ -89,7 +101,7 @@ def main():
89101
for change in main_changes:
90102
fp.write(change[1])
91103

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

94106

95107
if __name__ == "__main__":

.ci/scripts/create_release_branch.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ then
1010
exit 1
1111
fi
1212

13-
NEW_BRANCH="$(bump2version --dry-run --list release | sed -Ene 's/^new_version=([[:digit:]]+\.[[:digit:]]+)\..*$/\1/p')"
13+
NEW_BRANCH="$(bump-my-version show new_version --increment release | sed -Ene 's/^([[:digit:]]+\.[[:digit:]]+)\.[[:digit:]]+$/\1/p')"
1414

1515
if [[ -z "${NEW_BRANCH}" ]]
1616
then
@@ -23,6 +23,6 @@ git branch "${NEW_BRANCH}"
2323
# Clean changelog snippets.
2424
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 \{\} +
2525

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

2828
git push origin "${NEW_BRANCH}"

.ci/scripts/pr_labels.py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/env python3
2+
3+
# This script is running with elevated privileges from the main branch against pull requests.
4+
5+
import re
6+
import sys
7+
import tomllib
8+
from pathlib import Path
9+
10+
from git import Repo
11+
12+
13+
def main():
14+
assert len(sys.argv) == 3
15+
16+
with open("pyproject.toml", "rb") as fp:
17+
PYPROJECT_TOML = tomllib.load(fp)
18+
BLOCKING_REGEX = re.compile(r"DRAFT|WIP|NO\s*MERGE|DO\s*NOT\s*MERGE|EXPERIMENT")
19+
ISSUE_REGEX = re.compile(r"(?:fixes|closes)[\s:]+#(\d+)")
20+
CHERRY_PICK_REGEX = re.compile(r"^\s*\(cherry picked from commit [0-9a-f]*\)\s*$")
21+
CHANGELOG_EXTS = [
22+
f".{item['directory']}" for item in PYPROJECT_TOML["tool"]["towncrier"]["type"]
23+
]
24+
25+
repo = Repo(".")
26+
27+
base_commit = repo.commit(sys.argv[1])
28+
head_commit = repo.commit(sys.argv[2])
29+
30+
pr_commits = list(repo.iter_commits(f"{base_commit}..{head_commit}"))
31+
32+
labels = {
33+
"multi-commit": len(pr_commits) > 1,
34+
"cherry-pick": False,
35+
"no-issue": False,
36+
"no-changelog": False,
37+
"wip": False,
38+
}
39+
for commit in pr_commits:
40+
labels["wip"] |= BLOCKING_REGEX.search(commit.summary) is not None
41+
no_issue = ISSUE_REGEX.search(commit.message, re.IGNORECASE) is None
42+
labels["no-issue"] |= no_issue
43+
cherry_pick = CHERRY_PICK_REGEX.search(commit.message) is not None
44+
labels["cherry-pick"] |= cherry_pick
45+
changelog_snippets = [
46+
k
47+
for k in commit.stats.files
48+
if k.startswith("CHANGES/") and Path(k).suffix in CHANGELOG_EXTS
49+
]
50+
labels["no-changelog"] |= not changelog_snippets
51+
52+
print("ADD_LABELS=" + ",".join((k for k, v in labels.items() if v)))
53+
print("REMOVE_LABELS=" + ",".join((k for k, v in labels.items() if not v)))
54+
55+
56+
if __name__ == "__main__":
57+
main()

.ci/scripts/release.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ then
1010
exit 1
1111
fi
1212

13-
NEW_VERSION="$(bump2version --dry-run --list release | sed -ne 's/^new_version=//p')"
13+
NEW_VERSION="$(bump-my-version show new_version --increment release)"
1414
echo "Release ${NEW_VERSION}"
1515

1616
if ! [[ "${NEW_VERSION}" == "${BRANCH}"* ]]
@@ -20,7 +20,7 @@ then
2020
fi
2121

2222
towncrier build --yes --version "${NEW_VERSION}"
23-
bump2version release --commit --message "Release {new_version}" --tag --tag-name "{new_version}" --tag-message "Release {new_version}" --allow-dirty
24-
bump2version patch --commit
23+
bump-my-version bump release --commit --message "Release {new_version}" --tag --tag-name "{new_version}" --tag-message "Release {new_version}" --allow-dirty
24+
bump-my-version bump patch --commit
2525

2626
git push origin "${BRANCH}" "${NEW_VERSION}"

.ci/scripts/validate_commit_message.py

+8-13
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
import re
33
import subprocess
44
import sys
5+
import tomllib
56
from pathlib import Path
67

7-
import toml
88
from github import Github
99

10+
with open("pyproject.toml", "rb") as fp:
11+
PYPROJECT_TOML = tomllib.load(fp)
1012
KEYWORDS = ["fixes", "closes"]
1113
BLOCKING_REGEX = [
1214
"DRAFT",
@@ -15,14 +17,15 @@
1517
r"DO\s*NOT\s*MERGE",
1618
"EXPERIMENT",
1719
]
18-
NO_ISSUE = "[noissue]"
19-
CHANGELOG_EXTS = [
20-
f".{item['directory']}" for item in toml.load("pyproject.toml")["tool"]["towncrier"]["type"]
21-
]
20+
CHANGELOG_EXTS = [f".{item['directory']}" for item in PYPROJECT_TOML["tool"]["towncrier"]["type"]]
21+
NOISSUE_MARKER = "[noissue]"
2222

2323
sha = sys.argv[1]
2424
message = subprocess.check_output(["git", "log", "--format=%B", "-n 1", sha]).decode("utf-8")
2525

26+
if NOISSUE_MARKER in message:
27+
sys.exit("Do not add '[noissue]' in the commit message.")
28+
2629
if any((re.match(pattern, message) for pattern in BLOCKING_REGEX)):
2730
sys.exit("This PR is not ready for consumption.")
2831

@@ -61,13 +64,5 @@ def check_changelog(issue):
6164
if not cherry_pick:
6265
check_status(issue)
6366
check_changelog(issue)
64-
else:
65-
if NO_ISSUE in message:
66-
print("Commit {sha} has no issues but is tagged {tag}.".format(sha=sha[0:7], tag=NO_ISSUE))
67-
else:
68-
sys.exit(
69-
"Error: no attached issues found for {sha}. If this was intentional, add "
70-
" '{tag}' to the commit message.".format(sha=sha[0:7], tag=NO_ISSUE)
71-
)
7267

7368
print("Commit message for {sha} passed.".format(sha=sha[0:7]))

.flake8

-7
This file was deleted.

.github/dependabot.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ updates:
44
directory: "/"
55
schedule:
66
interval: daily
7-
open-pull-requests-limit: 10
87
commit-message:
9-
prefix: "[noissue]"
8+
prefix: "[PIP] "
9+
open-pull-requests-limit: 10
1010
- package-ecosystem: github-actions
1111
directory: "/"
1212
schedule:
13-
interval: daily
14-
open-pull-requests-limit: 10
13+
interval: weekly
1514
commit-message:
16-
prefix: "[noissue]"
15+
prefix: "[GHA] "
16+
open-pull-requests-limit: 10

.github/workflows/codeql.yml

-16
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,10 @@ jobs:
1818
steps:
1919
- name: "Checkout repository"
2020
uses: "actions/checkout@v4"
21-
- uses: "actions/cache@v4"
22-
with:
23-
path: "~/.cache/pip"
24-
key: "${{ runner.os }}-pip-${{ hashFiles('**/*requirements.txt', '**/*constraints.lock', '**/setup.py', '**/pyproject.toml') }}"
25-
restore-keys: |
26-
${{ runner.os }}-pip-
27-
28-
- name: "Set up Python"
29-
uses: "actions/setup-python@v5"
30-
with:
31-
python-version: "3.11"
32-
- name: "Manually install from sources"
33-
run: |
34-
python -m pip install -e . -e ./pulp-glue-maven
35-
echo "CODEQL_PYTHON=$(which python)" >> "$GITHUB_ENV"
3621
- name: "Initialize CodeQL"
3722
uses: "github/codeql-action/init@v3"
3823
with:
3924
languages: "python"
40-
setup-python-dependencies: false
4125

4226
- name: "Perform CodeQL Analysis"
4327
uses: "github/codeql-action/analyze@v3"

.github/workflows/collect_changes.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
git config user.email [email protected]
2121
- name: "Collect changes"
2222
run: |
23-
pip install GitPython packaging toml
23+
pip install GitPython packaging
2424
python3 .ci/scripts/collect_changes.py
2525
- name: "Create Pull Request"
2626
uses: "peter-evans/create-pull-request@v6"

.github/workflows/pr_checks.yml

+22-18
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,45 @@ concurrency:
1515
jobs:
1616
single_commit:
1717
runs-on: "ubuntu-latest"
18-
name: "Label multiple commit PR"
18+
name: "Label PR"
1919
permissions:
2020
pull-requests: "write"
2121
steps:
2222
- uses: "actions/checkout@v4"
2323
with:
2424
fetch-depth: 0
25-
- name: "Commit Count Check"
25+
- uses: "actions/setup-python@v5"
26+
with:
27+
python-version: "3.12"
28+
- name: "Determine PR labels"
2629
run: |
30+
pip install GitPython==3.1.42
2731
git fetch origin ${{ github.event.pull_request.head.sha }}
28-
echo "COMMIT_COUNT=$(git log --oneline --no-merges origin/${{ github.base_ref }}..${{ github.event.pull_request.head.sha }} | wc -l)" >> "$GITHUB_ENV"
32+
python .ci/scripts/pr_labels.py "origin/${{ github.base_ref }}" "${{ github.event.pull_request.head.sha }}" >> "$GITHUB_ENV"
2933
- uses: "actions/github-script@v7"
34+
name: "Apply PR Labels"
3035
with:
3136
script: |
32-
const labelName = "multi-commit";
33-
const { COMMIT_COUNT } = process.env;
37+
const { ADD_LABELS, REMOVE_LABELS } = process.env;
3438
35-
if (COMMIT_COUNT == 1)
36-
{
37-
try {
38-
await github.rest.issues.removeLabel({
39-
issue_number: context.issue.number,
40-
owner: context.repo.owner,
41-
repo: context.repo.repo,
42-
name: labelName,
43-
});
44-
} catch(err) {
39+
if (REMOVE_LABELS.length) {
40+
for await (const labelName of REMOVE_LABELS.split(",")) {
41+
try {
42+
await github.rest.issues.removeLabel({
43+
issue_number: context.issue.number,
44+
owner: context.repo.owner,
45+
repo: context.repo.repo,
46+
name: labelName,
47+
});
48+
} catch(err) {
49+
}
4550
}
4651
}
47-
else
48-
{
52+
if (ADD_LABELS.length) {
4953
await github.rest.issues.addLabels({
5054
issue_number: context.issue.number,
5155
owner: context.repo.owner,
5256
repo: context.repo.repo,
53-
labels: [labelName],
57+
labels: ADD_LABELS.split(","),
5458
});
5559
}

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: "Install dependencies"
1919
run: |
2020
python -m pip install --upgrade pip
21-
pip install bump2version towncrier~=23.11.0
21+
pip install bump-my-version~=0.20.0 towncrier~=23.11.0
2222
- name: "Setup git"
2323
run: |
2424
git config user.name pulpbot

.github/workflows/release_branch.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
git config user.email [email protected]
1919
- name: "Install python dependencies"
2020
run: |
21-
pip install bump2version
21+
pip install bump-my-version~=0.20.0
2222
- name: "Create Release Branch"
2323
run: |
2424
.ci/scripts/create_release_branch.sh

0 commit comments

Comments
 (0)