Skip to content

Commit ae89322

Browse files
committed
WIP Experiment with CI cleanup
1 parent 9f37956 commit ae89322

File tree

10 files changed

+130
-89
lines changed

10 files changed

+130
-89
lines changed

.ci/scripts/check_release.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
import argparse
1212
import re
1313
import os
14+
import sys
1415
import tomllib
16+
import typing as t
1517
from pathlib import Path
1618

1719
import yaml
@@ -23,7 +25,7 @@
2325
Z_CHANGELOG_EXTS = [".bugfix", ".misc"]
2426

2527

26-
def options():
28+
def options() -> argparse.Namespace:
2729
"""Check which branches need a release."""
2830
parser = argparse.ArgumentParser()
2931
parser.add_argument(
@@ -42,13 +44,13 @@ def options():
4244
return parser.parse_args()
4345

4446

45-
def template_config():
47+
def template_config() -> dict[str, t.Any]:
4648
# Assume this script lies in .ci/scripts
4749
path = Path(__file__).absolute().parent.parent.parent / "template_config.yml"
4850
return yaml.safe_load(path.read_text())
4951

5052

51-
def current_version(repo, commitish):
53+
def current_version(repo: Repo, commitish: str) -> Version:
5254
try:
5355
pyproject_toml = tomllib.loads(repo.git.show(f"{commitish}:pyproject.toml"))
5456
try:
@@ -62,7 +64,7 @@ def current_version(repo, commitish):
6264
return Version(current_version)
6365

6466

65-
def check_pyproject_dependencies(repo, from_commit, to_commit):
67+
def check_pyproject_dependencies(repo: Repo, from_commit: str, to_commit: str) -> list[str]:
6668
try:
6769
new_pyproject = tomllib.loads(repo.git.show(f"{to_commit}:pyproject.toml"))
6870
try:
@@ -83,8 +85,8 @@ def check_pyproject_dependencies(repo, from_commit, to_commit):
8385
return ["pyproject.toml changed somehow (PLEASE check if dependencies are affected)."]
8486

8587

86-
def main(options, template_config):
87-
DEFAULT_BRANCH = template_config["plugin_default_branch"]
88+
def main(options: argparse.Namespace, template_config: dict[str, t.Any]) -> int:
89+
DEFAULT_BRANCH: str = template_config["plugin_default_branch"]
8890

8991
repo = Repo()
9092

@@ -97,7 +99,7 @@ def main(options, template_config):
9799

98100
# Warning: This will not work if branch names contain "/" but we don't really care here.
99101
heads = [h.split("/")[-1] for h in repo.git.branch("--remote").split("\n")]
100-
available_branches = [h for h in heads if re.search(RELEASE_BRANCH_REGEX, h)]
102+
available_branches = [h for h in heads if re.fullmatch(RELEASE_BRANCH_REGEX, h)]
101103
available_branches.sort(key=lambda ver: Version(ver))
102104
available_branches.append(DEFAULT_BRANCH)
103105

@@ -114,7 +116,10 @@ def main(options, template_config):
114116

115117
if diff := branches - set(available_branches):
116118
print(f"Supplied branches contains non-existent branches! {diff}")
117-
exit(1)
119+
return 1
120+
121+
branches = [branch for branch in available_branches if branch in branches]
122+
branches.reverse()
118123

119124
print(f"Checking for releases on branches: {branches}")
120125

@@ -179,6 +184,8 @@ def main(options, template_config):
179184
if len(releases) == 0:
180185
print("No new releases to perform.")
181186

187+
return 0
188+
182189

183190
if __name__ == "__main__":
184-
main(options(), template_config())
191+
sys.exit(main(options(), template_config()))

.ci/scripts/collect_changes.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
#!/bin/env python3
2+
# /// script
3+
# requires-python = ">=3.13"
4+
# dependencies = [
5+
# "gitpython>=3.1.46,<3.2.0",
6+
# "packaging>=26.0,<26.1",
7+
# ]
8+
# ///
9+
210
# WARNING: DO NOT EDIT!
311
#
412
# This file was generated by plugin_template, and is managed by it. Please use

.github/workflows/nightly.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,20 @@ jobs:
6161

6262
- name: Create Pull Request
6363
uses: peter-evans/create-pull-request@v6
64+
id: "create_pr_changelog"
6465
with:
6566
token: ${{ secrets.RELEASE_TOKEN }}
6667
title: "Update Changelog"
6768
body: ""
6869
branch: "changelog/update"
6970
delete-branch: true
7071
path: "pulp_gem"
72+
- name: "Mark PR automerge"
73+
working-directory: "pulp_gem"
74+
run: |
75+
gh pr merge --rebase --auto "${{ steps.create_pr_changelog.outputs.pull-request-number }}"
76+
if: "steps.create_pr_changelog.outputs.pull-request-number"
77+
env:
78+
GH_TOKEN: "${{ secrets.RELEASE_TOKEN }}"
79+
continue-on-error: true
7180
...

.github/workflows/scripts/before_install.sh

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,57 +7,25 @@
77
#
88
# For more info visit https://github.com/pulp/plugin_template
99

10+
set -euo pipefail
11+
1012
# make sure this script runs at the repo root
1113
cd "$(dirname "$(realpath -e "$0")")"/../../..
1214

13-
set -mveuo pipefail
14-
15-
if [ "${GITHUB_REF##refs/heads/}" = "${GITHUB_REF}" ]
16-
then
17-
BRANCH_BUILD=0
18-
else
19-
BRANCH_BUILD=1
20-
BRANCH="${GITHUB_REF##refs/heads/}"
21-
fi
22-
if [ "${GITHUB_REF##refs/tags/}" = "${GITHUB_REF}" ]
23-
then
24-
TAG_BUILD=0
25-
else
26-
TAG_BUILD=1
27-
BRANCH="${GITHUB_REF##refs/tags/}"
28-
fi
29-
30-
COMMIT_MSG=$(git log --format=%B --no-merges -1)
31-
export COMMIT_MSG
32-
33-
COMPONENT_VERSION=$(python3 -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
34-
35-
mkdir .ci/ansible/vars || true
36-
echo "---" > .ci/ansible/vars/main.yaml
37-
echo "legacy_component_name: pulp_gem" >> .ci/ansible/vars/main.yaml
38-
echo "component_name: gem" >> .ci/ansible/vars/main.yaml
39-
echo "component_version: '${COMPONENT_VERSION}'" >> .ci/ansible/vars/main.yaml
40-
4115
export PRE_BEFORE_INSTALL=$PWD/.github/workflows/scripts/pre_before_install.sh
4216
export POST_BEFORE_INSTALL=$PWD/.github/workflows/scripts/post_before_install.sh
4317

4418
if [ -f $PRE_BEFORE_INSTALL ]; then
4519
source $PRE_BEFORE_INSTALL
4620
fi
4721

48-
if [ "$GITHUB_EVENT_NAME" = "pull_request" ] || [ "${BRANCH_BUILD}" = "1" -a "${BRANCH}" != "main" ]
49-
then
50-
echo $COMMIT_MSG | sed -n -e 's/.*CI Base Image:\s*\([-_/[:alnum:]]*:[-_[:alnum:]]*\).*/ci_base: "\1"/p' >> .ci/ansible/vars/main.yaml
22+
COMPONENT_VERSION="$(bump-my-version show current_version | tail -n -1 | python -c 'from packaging.version import Version; print(Version(input()))')"
23+
COMPONENT_SOURCE="./pulp_gem/dist/pulp_gem-${COMPONENT_VERSION}-py3-none-any.whl"
24+
if [ "$TEST" = "s3" ]; then
25+
COMPONENT_SOURCE="${COMPONENT_SOURCE} pulpcore[s3]"
5126
fi
52-
53-
for i in {1..3}
54-
do
55-
ansible-galaxy collection install "amazon.aws:8.1.0" && s=0 && break || s=$? && sleep 3
56-
done
57-
if [[ $s -gt 0 ]]
58-
then
59-
echo "Failed to install amazon.aws"
60-
exit $s
27+
if [ "$TEST" = "azure" ]; then
28+
COMPONENT_SOURCE="${COMPONENT_SOURCE} pulpcore[azure]"
6129
fi
6230

6331
if [[ "$TEST" = "pulp" ]]; then
@@ -67,6 +35,24 @@ if [[ "$TEST" = "lowerbounds" ]]; then
6735
python3 .ci/scripts/calc_constraints.py pyproject.toml > lowerbounds_constraints.txt
6836
fi
6937

38+
# Compose ansible container definition.
39+
mkdir -p .ci/ansible/vars
40+
41+
cat > .ci/ansible/vars/main.yaml << VARSYAML
42+
---
43+
legacy_component_name: "pulp_gem"
44+
component_name: "gem"
45+
component_version: "${COMPONENT_VERSION}"
46+
image:
47+
name: "pulp"
48+
tag: "ci_build"
49+
plugins:
50+
- name: "pulp_gem"
51+
source: "${COMPONENT_SOURCE}"
52+
VARSYAML
53+
54+
cat .ci/ansible/vars/main.yaml
55+
7056
if [ -f $POST_BEFORE_INSTALL ]; then
7157
source $POST_BEFORE_INSTALL
7258
fi

.github/workflows/scripts/before_script.sh

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#
88
# For more info visit https://github.com/pulp/plugin_template
99

10+
# This script dumps some files to help understand the setup of the test scenario.
11+
1012
# make sure this script runs at the repo root
1113
cd "$(dirname "$(realpath -e "$0")")"/../../..
1214

@@ -22,33 +24,35 @@ if [[ -f $PRE_BEFORE_SCRIPT ]]; then
2224
fi
2325

2426
# Developers should be able to reproduce the containers with this config
25-
echo "CI vars:"
27+
echo "# CI vars:"
2628
tail -v -n +1 .ci/ansible/vars/main.yaml
2729

2830
# Developers often want to know the final pulp config
29-
echo "PULP CONFIG:"
31+
echo
32+
echo "# Pulp config:"
3033
tail -v -n +1 .ci/ansible/settings/settings.* ~/.config/pulp_smash/settings.json
3134

32-
echo "Containerfile:"
35+
echo
36+
echo "# Containerfile:"
3337
tail -v -n +1 .ci/ansible/Containerfile
3438

35-
echo "Constraints Files:"
36-
# The need not even exist.
39+
echo
40+
echo "# Constraints Files:"
41+
# They need not even exist.
3742
tail -v -n +1 ../*/*constraints.txt || true
3843

39-
# Needed for some functional tests
40-
cmd_prefix bash -c "echo '%wheel ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/nopasswd"
41-
cmd_prefix bash -c "usermod -a -G wheel pulp"
44+
echo
45+
echo "# pip list outside the container"
4246

43-
if [[ "${REDIS_DISABLED:-false}" == true ]]; then
44-
cmd_prefix bash -c "s6-rc -d change redis"
45-
echo "The Redis service was disabled for $TEST"
46-
fi
47+
echo
48+
echo "# pip list inside the container"
49+
cmd_prefix bash -c "pip3 list"
50+
51+
echo
52+
echo "# State of the containers"
53+
docker ps -a
4754

4855
if [[ -f $POST_BEFORE_SCRIPT ]]; then
4956
source $POST_BEFORE_SCRIPT
5057
fi
5158

52-
# Lots of plugins try to use this path, and throw warnings if they cannot access it.
53-
cmd_prefix mkdir /.pytest_cache
54-
cmd_prefix chown pulp:pulp /.pytest_cache

.github/workflows/scripts/install.sh

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,44 +7,39 @@
77
#
88
# For more info visit https://github.com/pulp/plugin_template
99

10+
set -euv
11+
1012
# make sure this script runs at the repo root
1113
cd "$(dirname "$(realpath -e "$0")")"/../../..
1214
REPO_ROOT="$PWD"
1315

14-
set -euv
15-
1616
source .github/workflows/scripts/utils.sh
1717

18-
PLUGIN_VERSION="$(bump-my-version show current_version | tail -n -1 | python -c 'from packaging.version import Version; print(Version(input()))')"
19-
PLUGIN_SOURCE="./pulp_gem/dist/pulp_gem-${PLUGIN_VERSION}-py3-none-any.whl"
20-
2118
export PULP_API_ROOT="/pulp/"
2219

2320
PIP_REQUIREMENTS=("pulp-cli-gem")
2421

2522
# This must be the **only** call to "pip install" on the test runner.
2623
pip install ${PIP_REQUIREMENTS[*]}
2724

25+
if [[ "$TEST" = "s3" ]]; then
26+
for i in {1..3}
27+
do
28+
ansible-galaxy collection install "amazon.aws:8.1.0" && s=0 && break || s=$? && sleep 3
29+
done
30+
if [[ $s -gt 0 ]]
31+
then
32+
echo "Failed to install amazon.aws"
33+
exit $s
34+
fi
35+
fi
36+
2837
# Check out the pulp-cli-gem branch matching the installed version.
2938
PULP_CLI_VERSION="$(pip freeze | sed -n -e 's/pulp-cli-gem==//p')"
3039
git clone --depth 1 --branch "$PULP_CLI_VERSION" https://github.com/pulp/pulp-cli-gem.git ../pulp-cli-gem
3140

3241
cd .ci/ansible/
33-
if [ "$TEST" = "s3" ]; then
34-
PLUGIN_SOURCE="${PLUGIN_SOURCE} pulpcore[s3]"
35-
fi
36-
if [ "$TEST" = "azure" ]; then
37-
PLUGIN_SOURCE="${PLUGIN_SOURCE} pulpcore[azure]"
38-
fi
3942

40-
cat >> vars/main.yaml << VARSYAML
41-
image:
42-
name: pulp
43-
tag: "ci_build"
44-
plugins:
45-
- name: pulp_gem
46-
source: "${PLUGIN_SOURCE}"
47-
VARSYAML
4843
if [[ -f ../../ci_requirements.txt ]]; then
4944
cat >> vars/main.yaml << VARSYAML
5045
ci_requirements: true
@@ -155,6 +150,16 @@ if [[ "$TEST" = "azure" ]]; then
155150
az storage container create --name pulp-test --connection-string $AZURE_STORAGE_CONNECTION_STRING
156151
fi
157152

158-
echo ::group::PIP_LIST
159-
cmd_prefix bash -c "pip3 list"
160-
echo ::endgroup::
153+
# Needed for some functional tests
154+
cmd_prefix bash -c "echo '%wheel ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/nopasswd"
155+
cmd_prefix bash -c "usermod -a -G wheel pulp"
156+
157+
# In some scenarios we want to simulate a failed redis cache.
158+
if [[ " s3 " =~ " ${TEST} " ]]; then
159+
cmd_prefix bash -c "s6-rc -d change redis"
160+
echo "The Redis service was disabled for $TEST"
161+
fi
162+
163+
# Lots of plugins try to use this path, and throw warnings if they cannot access it.
164+
cmd_prefix mkdir /.pytest_cache
165+
cmd_prefix chown pulp:pulp /.pytest_cache

.github/workflows/test.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ jobs:
9999
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
100100
GITHUB_CONTEXT: "${{ github.event.pull_request.commits_url }}"
101101

102-
- name: "Before Script"
102+
- name: "Dump CI Metadata"
103103
run: |
104104
.github/workflows/scripts/before_script.sh
105105
shell: "bash"
@@ -108,7 +108,6 @@ jobs:
108108
ANSIBLE_FORCE_COLOR: "1"
109109
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
110110
GITHUB_CONTEXT: "${{ github.event.pull_request.commits_url }}"
111-
REDIS_DISABLED: "${{ contains('', matrix.env.TEST) }}"
112111

113112
- name: "Script"
114113
run: |

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ include test_requirements.txt
99
include unittest_requirements.txt
1010
include pyproject.toml
1111
exclude releasing.md
12+
exclude Makefile

Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# WARNING: DO NOT EDIT!
2+
#
3+
# This file was generated by plugin_template, and is managed by it. Please use
4+
# './plugin-template --ci pulp_gem' to update this file.
5+
#
6+
# For more info visit https://github.com/pulp/plugin_template
7+
8+
.PHONY: format
9+
format:
10+
black .
11+
12+
.PHONY: lint
13+
lint:
14+
yamllint -s -d '{extends: relaxed, rules: {line-length: disable}}' .github/workflows
15+
bump-my-version bump --dry-run release
16+
black --check --diff .
17+
flake8
18+
check-manifest
19+
python .ci/scripts/check_requirements.py
20+
sh .ci/scripts/check_pulpcore_imports.sh
21+
sh .ci/scripts/check_gettext.sh

0 commit comments

Comments
 (0)