Skip to content

Commit 5a50847

Browse files
committed
Update CI files
1 parent 92f7f84 commit 5a50847

File tree

10 files changed

+229
-195
lines changed

10 files changed

+229
-195
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()))
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env python3
2+
# This script is running with elevated privileges from the main branch against pull requests.
3+
#
4+
# It cleans the input from artifacts which are used by the pulp documentation internally,
5+
# but clutter for GitHub releases
6+
7+
import sys
8+
9+
NOTE = """
10+
> [!NOTE]
11+
> Official changes are available on [Pulp docs]({docs_url})\
12+
"""
13+
14+
15+
def main():
16+
plugin_name = sys.argv[1]
17+
version_str = sys.argv[2]
18+
docs_url = f"https://pulpproject.org/{plugin_name}/changes/#{version_str}"
19+
note_added = False
20+
for line in sys.stdin:
21+
if line.endswith("\n"):
22+
line = line[:-1]
23+
if line.startswith("#"):
24+
print(line.split(" {: #")[0])
25+
if not note_added and version_str in line:
26+
print(NOTE.format(docs_url=docs_url))
27+
note_added = True
28+
else:
29+
print(line)
30+
31+
32+
if __name__ == "__main__":
33+
main()

.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: "pulpcore"
72+
- name: "Mark PR automerge"
73+
working-directory: "pulpcore"
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/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ jobs:
142142
run: |
143143
# The last commit before the release commit contains the release CHANGES fragments
144144
git checkout "${TAG_NAME}~"
145-
NOTES=$(towncrier build --draft --version $TAG_NAME)
145+
NOTES=$(towncrier build --draft --version $TAG_NAME | .ci/scripts/clean_gh_release_notes.py pulpcore $TAG_NAME)
146146
echo "body<<EOF" >> $GITHUB_OUTPUT
147147
echo "$NOTES" >> $GITHUB_OUTPUT
148148
echo "EOF" >> $GITHUB_OUTPUT

.github/workflows/scripts/before_install.sh

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

10+
# This script prepares the scenario definition in the .ci/ansible/vars/main.yaml file.
11+
#
12+
# It requires the following environment:
13+
# TEST - The name of the scenario to prepare.
14+
#
15+
# It may also dump the {lower,upper}bounds_constraints.txt for the specific scenario.
16+
17+
set -eu -o pipefail
18+
1019
# make sure this script runs at the repo root
1120
cd "$(dirname "$(realpath -e "$0")")"/../../..
1221

13-
set -mveuo pipefail
22+
if [ -f .github/workflows/scripts/pre_before_install.sh ]; then
23+
source .github/workflows/scripts/pre_before_install.sh
24+
fi
1425

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/}"
26+
COMPONENT_VERSION="$(bump-my-version show current_version | tail -n -1 | python -c 'from packaging.version import Version; print(Version(input()))')"
27+
COMPONENT_SOURCE="./pulpcore/dist/pulpcore-${COMPONENT_VERSION}-py3-none-any.whl"
28+
if [ "$TEST" = "s3" ]; then
29+
COMPONENT_SOURCE="${COMPONENT_SOURCE}[s3]"
2130
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/}"
31+
if [ "$TEST" = "azure" ]; then
32+
COMPONENT_SOURCE="${COMPONENT_SOURCE}[azure]"
2833
fi
2934

30-
COMMIT_MSG=$(git log --format=%B --no-merges -1)
31-
export COMMIT_MSG
35+
if [[ "$TEST" = "pulp" ]]; then
36+
python3 .ci/scripts/calc_constraints.py -u requirements.txt > upperbounds_constraints.txt
37+
fi
38+
if [[ "$TEST" = "lowerbounds" ]]; then
39+
python3 .ci/scripts/calc_constraints.py requirements.txt > lowerbounds_constraints.txt
40+
fi
41+
export PULP_API_ROOT=$(test "${TEST}" = "s3" && echo "/rerouted/djnd/" || echo "/pulp/")
3242

33-
COMPONENT_VERSION=$(sed -ne "s/\s*version.*=.*['\"]\(.*\)['\"][\s,]*/\1/p" setup.py)
43+
echo "PULP_API_ROOT=${PULP_API_ROOT}" >> "$GITHUB_ENV"
3444

35-
mkdir .ci/ansible/vars || true
36-
echo "---" > .ci/ansible/vars/main.yaml
37-
echo "legacy_component_name: pulpcore" >> .ci/ansible/vars/main.yaml
38-
echo "component_name: core" >> .ci/ansible/vars/main.yaml
39-
echo "component_version: '${COMPONENT_VERSION}'" >> .ci/ansible/vars/main.yaml
45+
# Compose the scenario definition.
46+
mkdir -p .ci/ansible/vars
4047

41-
export PRE_BEFORE_INSTALL=$PWD/.github/workflows/scripts/pre_before_install.sh
42-
export POST_BEFORE_INSTALL=$PWD/.github/workflows/scripts/post_before_install.sh
48+
cat > .ci/ansible/vars/main.yaml << VARSYAML
49+
---
50+
scenario: "${TEST}"
51+
legacy_component_name: "pulpcore"
52+
component_name: "core"
53+
component_version: "${COMPONENT_VERSION}"
54+
pulp_env: {"PULP_CA_BUNDLE": "/etc/pulp/certs/pulp_webserver.crt"}
55+
pulp_settings: {"allowed_export_paths": ["/tmp"], "allowed_import_paths": ["/tmp"], "content_path_prefix": "/somewhere/else/", "orphan_protection_time": 0, "task_protection_time": 10, "tmpfile_protection_time": 10, "upload_protection_time": 10}
56+
pulp_scheme: "https"
57+
pulp_default_container: "ghcr.io/pulp/pulp-ci-centos9:latest"
58+
api_root: "${PULP_API_ROOT}"
59+
image:
60+
name: "pulp"
61+
tag: "ci_build"
62+
plugins:
63+
- name: "pulpcore"
64+
source: "${COMPONENT_SOURCE}"
65+
ci_requirements: $(test -f ci_requirements.txt && echo -n true || echo -n false)
66+
upperbounds: $(test "${TEST}" = "pulp" && echo -n true || echo -n false)
67+
lowerounds: $(test "${TEST}" = "lowerbounds" && echo -n true || echo -n false)
68+
services:
69+
- name: "pulp"
70+
image: "pulp:ci_build"
71+
volumes:
72+
- "./settings:/etc/pulp"
73+
- "./ssh:/keys/"
74+
- "~/.config:/var/lib/pulp/.config"
75+
- "../../../pulp-openapi-generator:/root/pulp-openapi-generator"
76+
env:
77+
PULP_WORKERS: "4"
78+
PULP_HTTPS: "true"
79+
- name: "pulp-fixtures"
80+
image: "docker.io/pulp/pulp-fixtures:latest"
81+
env:
82+
BASE_URL: "http://pulp-fixtures:8080"
83+
VARSYAML
4384

44-
if [ -f $PRE_BEFORE_INSTALL ]; then
45-
source $PRE_BEFORE_INSTALL
85+
if [ "$TEST" = "s3" ]; then
86+
MINIO_ACCESS_KEY=AKIAIT2Z5TDYPX3ARJBA
87+
MINIO_SECRET_KEY=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
88+
cat >> .ci/ansible/vars/main.yaml << VARSYAML
89+
- name: "minio"
90+
image: "minio/minio"
91+
env:
92+
MINIO_ACCESS_KEY: "${MINIO_ACCESS_KEY}"
93+
MINIO_SECRET_KEY: "${MINIO_SECRET_KEY}"
94+
command: "server /data"
95+
s3_test: true
96+
minio_access_key: "${MINIO_ACCESS_KEY}"
97+
minio_secret_key: "${MINIO_SECRET_KEY}"
98+
pulp_scenario_settings: {"DISABLED_authentication_backends": "@merge django.contrib.auth.backends.RemoteUserBackend", "DISABLED_authentication_json_header": "HTTP_X_RH_IDENTITY", "DISABLED_authentication_json_header_jq_filter": ".identity.user.username", "DISABLED_authentication_json_header_openapi_security_scheme": {"description": "External OAuth integration", "flows": {"clientCredentials": {"scopes": {"api.console": "grant_access_to_pulp"}, "tokenUrl": "https://your-identity-provider/token/issuer"}}, "type": "oauth2"}, "DISABLED_rest_framework__default_authentication_classes": "@merge pulpcore.app.authentication.JSONHeaderRemoteAuthentication", "MEDIA_ROOT": "", "STORAGES": {"default": {"BACKEND": "storages.backends.s3boto3.S3Boto3Storage", "OPTIONS": {"access_key": "AKIAIT2Z5TDYPX3ARJBA", "addressing_style": "path", "bucket_name": "pulp3", "default_acl": "@none", "endpoint_url": "http://minio:9000", "region_name": "eu-central-1", "secret_key": "fqRvjWaPU5o0fCqQuUWbj9Fainj2pVZtBCiDiieS", "signature_version": "s3v4"}}, "staticfiles": {"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage"}}, "domain_enabled": true, "hide_guarded_distributions": true}
99+
pulp_scenario_env: {}
100+
VARSYAML
46101
fi
47102

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
103+
if [ "$TEST" = "azure" ]; then
104+
cat >> .ci/ansible/vars/main.yaml << VARSYAML
105+
- name: "ci-azurite"
106+
image: "mcr.microsoft.com/azure-storage/azurite"
107+
command: "azurite-blob --skipApiVersionCheck --blobHost 0.0.0.0"
108+
azure_test: true
109+
pulp_scenario_settings: {"MEDIA_ROOT": "", "STORAGES": {"default": {"BACKEND": "storages.backends.azure_storage.AzureStorage", "OPTIONS": {"account_key": "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==", "account_name": "devstoreaccount1", "azure_container": "pulp-test", "connection_string": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://ci-azurite:10000/devstoreaccount1;", "expiration_secs": 120, "location": "pulp3", "overwrite_files": true}}, "staticfiles": {"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage"}}, "api_root_rewrite_header": "X-API-Root", "domain_enabled": true}
110+
pulp_scenario_env: {}
111+
VARSYAML
51112
fi
52113

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
114+
if [ "$TEST" = "gcp" ]; then
115+
cat >> .ci/ansible/vars/main.yaml << VARSYAML
116+
- name: "ci-gcp"
117+
image: "fsouza/fake-gcs-server"
118+
volumes:
119+
- "storage_data:/etc/pulp"
120+
command: " -scheme http"
121+
gcp_test: true
122+
pulp_scenario_settings: null
123+
pulp_scenario_env: {}
124+
VARSYAML
61125
fi
62126

63-
if [[ "$TEST" = "pulp" ]]; then
64-
python3 .ci/scripts/calc_constraints.py -u requirements.txt > upperbounds_constraints.txt
65-
fi
66-
if [[ "$TEST" = "lowerbounds" ]]; then
67-
python3 .ci/scripts/calc_constraints.py requirements.txt > lowerbounds_constraints.txt
68-
fi
127+
cat >> .ci/ansible/vars/main.yaml << VARSYAML
128+
...
129+
VARSYAML
130+
cat .ci/ansible/vars/main.yaml
69131

70-
if [ -f $POST_BEFORE_INSTALL ]; then
71-
source $POST_BEFORE_INSTALL
132+
if [ -f .github/workflows/scripts/post_before_install.sh ]; then
133+
source .github/workflows/scripts/post_before_install.sh
72134
fi

0 commit comments

Comments
 (0)