Compare commits
4 Commits
t-staging-
...
t-refactor
| Author | SHA256 | Date | |
|---|---|---|---|
|
|
49ca2d5646 | ||
|
|
d3a8cbd57d | ||
|
|
a66847aa86 | ||
|
|
3aec2deca4 |
@@ -34,9 +34,7 @@ jobs:
|
||||
run: make build
|
||||
working-directory: ./autogits
|
||||
- name: Prepare images
|
||||
run: |
|
||||
make build
|
||||
podman rmi $(podman images -f "dangling=true" -q)
|
||||
run: make build
|
||||
working-directory: ./autogits/integration
|
||||
- name: Make sure the pod is down
|
||||
run: make down
|
||||
@@ -45,16 +43,12 @@ jobs:
|
||||
run: |
|
||||
make up
|
||||
make wait_healthy
|
||||
podman ps
|
||||
sleep 5
|
||||
working-directory: ./autogits/integration
|
||||
- name: Run tests
|
||||
run: make pytest
|
||||
working-directory: ./autogits/integration
|
||||
- name: Make sure the pod is down
|
||||
if: always()
|
||||
run: |
|
||||
podman ps
|
||||
make down
|
||||
run: make down
|
||||
working-directory: ./autogits/integration
|
||||
|
||||
|
||||
8
Makefile
8
Makefile
@@ -1,8 +1,4 @@
|
||||
MODULES := devel-importer utils/hujson utils/maintainer-update gitea-events-rabbitmq-publisher gitea_status_proxy group-review obs-forward-bot obs-staging-bot obs-status-service workflow-direct workflow-pr
|
||||
|
||||
.PHONY: build $(MODULES)
|
||||
|
||||
build: $(MODULES)
|
||||
|
||||
$(MODULES):
|
||||
go build -C $@ -buildmode=pie
|
||||
build:
|
||||
for m in $(MODULES); do go build -C $$m -buildmode=pie || exit 1 ; done
|
||||
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"slices"
|
||||
"strings"
|
||||
@@ -205,16 +204,21 @@ func ReadWorkflowConfig(gitea GiteaFileContentAndRepoFetcher, git_project string
|
||||
|
||||
func ResolveWorkflowConfigs(gitea GiteaFileContentAndRepoFetcher, config *ConfigFile) (AutogitConfigs, error) {
|
||||
configs := make([]*AutogitConfig, 0, len(config.GitProjectNames))
|
||||
var errs []error
|
||||
for _, git_project := range config.GitProjectNames {
|
||||
c, err := ReadWorkflowConfig(gitea, git_project)
|
||||
if err != nil {
|
||||
// can't sync, so ignore for now
|
||||
log.Println(err)
|
||||
errs = append(errs, err)
|
||||
} else {
|
||||
configs = append(configs, c)
|
||||
}
|
||||
}
|
||||
|
||||
if len(errs) > 0 {
|
||||
return configs, errors.Join(errs...)
|
||||
}
|
||||
|
||||
return configs, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -327,6 +327,7 @@ func main() {
|
||||
interval := flag.Int64("interval", 10, "Notification polling interval in minutes (min 1 min)")
|
||||
configFile := flag.String("config", "", "PrjGit listing config file")
|
||||
logging := flag.String("logging", "info", "Logging level: [none, error, info, debug]")
|
||||
exitOnConfigError := flag.Bool("exit-on-config-error", false, "Exit if any repository in configuration cannot be resolved")
|
||||
flag.BoolVar(&common.IsDryRun, "dry", false, "Dry run, no effect. For debugging")
|
||||
flag.Parse()
|
||||
|
||||
@@ -382,8 +383,10 @@ func main() {
|
||||
giteaTransport := common.AllocateGiteaTransport(*giteaUrl)
|
||||
configs, err := common.ResolveWorkflowConfigs(giteaTransport, configData)
|
||||
if err != nil {
|
||||
common.LogError("Cannot parse workflow configs:", err)
|
||||
return
|
||||
common.LogError("Failed to resolve some configuration repositories:", err)
|
||||
if *exitOnConfigError {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
reviewer, err := giteaTransport.GetCurrentUser()
|
||||
|
||||
@@ -70,7 +70,7 @@ wait_healthy:
|
||||
@echo "All services are healthy!"
|
||||
|
||||
pytest:
|
||||
podman-compose exec tester pytest -v tests
|
||||
podman-compose exec tester pytest -v tests/*
|
||||
|
||||
build:
|
||||
podman pull docker.io/library/rabbitmq:3.13.7-management
|
||||
|
||||
@@ -81,11 +81,6 @@ services:
|
||||
init: true
|
||||
networks:
|
||||
- gitea-network
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pgrep workflow-pr && [ $$(awk '{print $22}' /proc/$$(pgrep workflow-pr)/stat) -lt $$(($$(awk '{print $1}' /proc/uptime | cut -d. -f1)*100 - 1000)) ]"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
depends_on:
|
||||
gitea:
|
||||
condition: service_started
|
||||
@@ -101,6 +96,7 @@ services:
|
||||
- ./workflow-pr-repos:/var/lib/workflow-pr/repos:Z
|
||||
command: [
|
||||
"-check-on-start",
|
||||
"-exit-on-config-error",
|
||||
"-debug",
|
||||
"-gitea-url", "http://gitea-test:3000",
|
||||
"-url", "amqps://rabbitmq-test:5671",
|
||||
@@ -134,7 +130,9 @@ services:
|
||||
networks:
|
||||
- gitea-network
|
||||
depends_on:
|
||||
workflow-pr:
|
||||
gitea:
|
||||
condition: service_started
|
||||
tester:
|
||||
condition: service_started
|
||||
environment:
|
||||
- OBS_USER=mock
|
||||
|
||||
@@ -162,10 +162,6 @@ BRANCH_CONFIG_CUSTOM = {
|
||||
"workflow.config": {
|
||||
"MergeMode": "devel"
|
||||
}
|
||||
},
|
||||
"zz-ready-to-start": {
|
||||
"workflow.config": {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,12 +65,6 @@ class GiteaAPIClient:
|
||||
return None
|
||||
raise
|
||||
|
||||
def get_submodule_sha(self, owner: str, repo: str, submodule_path: str, ref: str = "main"):
|
||||
info = self.get_file_info(owner, repo, submodule_path, branch=ref)
|
||||
if info and info.get("type") == "submodule":
|
||||
return info.get("sha")
|
||||
return None
|
||||
|
||||
def create_user(self, username, password, email):
|
||||
vprint(f"--- Creating user: {username} ---")
|
||||
data = {
|
||||
@@ -135,8 +129,7 @@ class GiteaAPIClient:
|
||||
"gitignores": "Go",
|
||||
"license": "MIT",
|
||||
"private": False,
|
||||
"readme": "Default",
|
||||
"object_format_name": "sha256"
|
||||
"readme": "Default"
|
||||
}
|
||||
response, duration = self._request("POST", f"orgs/{org_name}/repos", json=data)
|
||||
vprint(f"[{duration:.3f}s] Repository '{org_name}/{repo_name}' created with a README.")
|
||||
@@ -186,7 +179,7 @@ class GiteaAPIClient:
|
||||
|
||||
diff_content = f"""diff --git a/.gitmodules b/.gitmodules
|
||||
new file mode 100644
|
||||
index 00000000..f1838bd9
|
||||
index 0000000..f1838bd
|
||||
--- /dev/null
|
||||
+++ b/.gitmodules
|
||||
@@ -0,0 +1,6 @@
|
||||
@@ -198,14 +191,14 @@ index 00000000..f1838bd9
|
||||
+ url = ../../mypool/pkgB.git
|
||||
diff --git a/pkgA b/pkgA
|
||||
new file mode 160000
|
||||
index 00000000..{pkg_a_sha}
|
||||
index 0000000..{pkg_a_sha}
|
||||
--- /dev/null
|
||||
+++ b/pkgA
|
||||
@@ -0,0 +1 @@
|
||||
+Subproject commit {pkg_a_sha}
|
||||
diff --git a/pkgB b/pkgB
|
||||
new file mode 160000
|
||||
index 00000000..{pkg_b_sha}
|
||||
index 0000000..{pkg_b_sha}
|
||||
--- /dev/null
|
||||
+++ b/pkgB
|
||||
@@ -0,0 +1 @@
|
||||
@@ -531,14 +524,6 @@ index 00000000..{pkg_b_sha}
|
||||
|
||||
return review
|
||||
|
||||
def request_reviewers(self, repo_full_name: str, pr_number: int, reviewers: list):
|
||||
owner, repo = repo_full_name.split("/")
|
||||
url = f"repos/{owner}/{repo}/pulls/{pr_number}/requested_reviewers"
|
||||
data = {"reviewers": reviewers}
|
||||
vprint(f"--- Requesting reviewers for {repo_full_name} PR #{pr_number}: {reviewers} ---")
|
||||
response, duration = self._request("POST", url, json=data)
|
||||
return response.json()
|
||||
|
||||
def list_reviews(self, repo_full_name: str, pr_number: int):
|
||||
owner, repo = repo_full_name.split("/")
|
||||
url = f"repos/{owner}/{repo}/pulls/{pr_number}/reviews"
|
||||
|
||||
@@ -1,521 +0,0 @@
|
||||
import pytest
|
||||
import time
|
||||
import re
|
||||
from tests.lib.common_test_utils import GiteaAPIClient, vprint
|
||||
|
||||
# Shared methods
|
||||
|
||||
def wait_for_staging_bot_reviewer(gitea_env, prj_pr_number, timeout=30):
|
||||
"""Wait for staging-bot to be added as a reviewer."""
|
||||
for _ in range(timeout):
|
||||
time.sleep(1)
|
||||
pr_details = gitea_env.get_pr_details("myproducts/mySLFO", prj_pr_number)
|
||||
if any(
|
||||
r.get("login") == "autogits_obs_staging_bot"
|
||||
for r in pr_details.get("requested_reviewers", [])
|
||||
):
|
||||
return True
|
||||
return False
|
||||
|
||||
def wait_for_comment(gitea_env, repo_full_name, pr_number, text_to_find, subtext=None, timeout=60):
|
||||
"""Wait for a specific comment in the PR timeline."""
|
||||
vprint(f"Waiting for comment '{text_to_find}'" + (f" with subtext '{subtext}'" if subtext else "") + f" in {repo_full_name} PR #{pr_number}...")
|
||||
for _ in range(timeout):
|
||||
time.sleep(1)
|
||||
try:
|
||||
events = gitea_env.get_timeline_events(repo_full_name, pr_number)
|
||||
except Exception:
|
||||
continue
|
||||
for event in events:
|
||||
body = event.get("body", "")
|
||||
if not body:
|
||||
continue
|
||||
if subtext:
|
||||
if text_to_find in body and subtext in body:
|
||||
return True
|
||||
else:
|
||||
if text_to_find == body.strip():
|
||||
return True
|
||||
return False
|
||||
|
||||
def setup_obs_mock(httpserver, project_name, build_result_handler):
|
||||
"""Setup OBS mock handlers."""
|
||||
def general_project_meta_handler(request):
|
||||
project = request.path.split("/")[2]
|
||||
return f'<project name="{project}"><scmsync>http://gitea-test:3000/myproducts/mySLFO.git</scmsync></project>'
|
||||
|
||||
httpserver.clear()
|
||||
httpserver.expect_request(re.compile(r"/source/[^/]+/_meta$"), method="GET").respond_with_handler(general_project_meta_handler)
|
||||
httpserver.expect_request(re.compile(f"/build/{project_name}/_result"), method="GET").respond_with_handler(build_result_handler)
|
||||
httpserver.expect_request(re.compile(r"/source/[^/]+/_meta$"), method="PUT").respond_with_data("OK")
|
||||
httpserver.expect_request(re.compile(r"/source/[^/]+$"), method="DELETE").respond_with_data("OK")
|
||||
|
||||
def create_build_result_xml(project_name, repo_arch_package_status):
|
||||
"""Create the XML response for OBS build results."""
|
||||
results_xml = ""
|
||||
# Group statuses by (repo, arch)
|
||||
grouped = {}
|
||||
for (repo, arch, package), (repo_code, pkg_code) in repo_arch_package_status.items():
|
||||
if (repo, arch) not in grouped:
|
||||
grouped[(repo, arch)] = {"repo_code": repo_code, "packages": []}
|
||||
grouped[(repo, arch)]["packages"].append((package, pkg_code))
|
||||
|
||||
for (repo, arch), data in grouped.items():
|
||||
repo_code = data["repo_code"]
|
||||
pkg_statuses = "".join([f'\n <status package="{p}" code="{c}"/>' for p, c in data["packages"]])
|
||||
results_xml += f"""
|
||||
<result project="{project_name}" repository="{repo}" arch="{arch}" code="{repo_code}" state="{repo_code}">{pkg_statuses}
|
||||
</result>"""
|
||||
return f'<resultlist state="mock">{results_xml}\n</resultlist>'
|
||||
|
||||
def create_submodule_diff(submodule_name, old_sha, new_sha):
|
||||
"""Create a git diff string for updating a submodule commit ID."""
|
||||
return f"""diff --git a/{submodule_name} b/{submodule_name}
|
||||
index {old_sha[:7]}..{new_sha[:7]} 160000
|
||||
--- a/{submodule_name}
|
||||
+++ b/{submodule_name}
|
||||
@@ -1 +1 @@
|
||||
-Subproject commit {old_sha}
|
||||
+Subproject commit {new_sha}
|
||||
"""
|
||||
|
||||
@pytest.mark.t001
|
||||
def test_001_build_on_all_archs_success(staging_main_env, httpserver):
|
||||
gitea_env, test_full_repo_name, merge_branch_name = staging_main_env
|
||||
|
||||
# 1. Create a package PR.
|
||||
diff = "diff --git a/test_br.txt b/test_br.txt\nnew file mode 100644\nindex 00000000..473a0f4c\n"
|
||||
pr = gitea_env.create_gitea_pr("mypool/pkgA", diff, "Test BR PR", False, base_branch=merge_branch_name)
|
||||
pkg_pr_number = pr["number"]
|
||||
|
||||
# 2. Wait for the workflow-pr bot to create the related project PR.
|
||||
prj_pr_number = gitea_env.wait_for_project_pr("mypool/pkgA", pkg_pr_number)
|
||||
assert prj_pr_number is not None, "Workflow bot did not create a project PR."
|
||||
|
||||
# 3. Wait for staging-bot to be added as a reviewer.
|
||||
assert wait_for_staging_bot_reviewer(gitea_env, prj_pr_number), "Staging bot was not added as a reviewer."
|
||||
|
||||
# 4. Mock the OBS result list.
|
||||
project_name = f"openSUSE:Leap:16.0:PullRequest:{prj_pr_number}"
|
||||
repos = ["repo1", "repo2"]
|
||||
archs = ["x86_64", "aarch64"]
|
||||
repo_arch_package_status = {}
|
||||
for r in repos:
|
||||
for a in archs:
|
||||
repo_arch_package_status[(r, a, "pkgA")] = ("building", "building")
|
||||
|
||||
def build_result_handler(request):
|
||||
return create_build_result_xml(project_name, repo_arch_package_status)
|
||||
|
||||
setup_obs_mock(httpserver, project_name, build_result_handler)
|
||||
|
||||
# Expected Result 1: "Build is started in..."
|
||||
assert wait_for_comment(gitea_env, "myproducts/mySLFO", prj_pr_number, "Build is started in", project_name), "Staging bot did not post 'Build is started' comment."
|
||||
|
||||
# 6. Transition all to success.
|
||||
for r in repos:
|
||||
for a in archs:
|
||||
repo_arch_package_status[(r, a, "pkgA")] = ("published", "succeeded")
|
||||
|
||||
# Expected Result 2: "Build successful" on project PR.
|
||||
assert wait_for_comment(gitea_env, "myproducts/mySLFO", prj_pr_number, "Build successful"), "Staging bot did not post 'Build successful' comment on project PR."
|
||||
|
||||
# Expected Result 3: "Build successful..." on package PR.
|
||||
assert wait_for_comment(gitea_env, "mypool/pkgA", pkg_pr_number, "Build successful, for more information go in", project_name), "Staging bot did not post 'Build successful' comment on package PR."
|
||||
|
||||
@pytest.mark.t002
|
||||
def test_002_build_on_all_archs_mix(staging_main_env, httpserver):
|
||||
gitea_env, test_full_repo_name, merge_branch_name = staging_main_env
|
||||
|
||||
# 1. Create a package PR.
|
||||
diff = "diff --git a/test_br_mix.txt b/test_br_mix.txt\nnew file mode 100644\nindex 00000000..473a0f4c\n"
|
||||
pr = gitea_env.create_gitea_pr("mypool/pkgA", diff, "Test BR Mix PR", False, base_branch=merge_branch_name)
|
||||
pkg_pr_number = pr["number"]
|
||||
|
||||
# 2. Wait for the workflow-pr bot to create the related project PR.
|
||||
prj_pr_number = gitea_env.wait_for_project_pr("mypool/pkgA", pkg_pr_number)
|
||||
assert prj_pr_number is not None, "Workflow bot did not create a project PR."
|
||||
|
||||
# 3. Wait for staging-bot to be added as a reviewer.
|
||||
assert wait_for_staging_bot_reviewer(gitea_env, prj_pr_number), "Staging bot was not added as a reviewer."
|
||||
|
||||
# 4. Mock the OBS result list with 2 repositories and 2 architectures.
|
||||
project_name = f"openSUSE:Leap:16.0:PullRequest:{prj_pr_number}"
|
||||
repos = ["repo1", "repo2"]
|
||||
archs = ["x86_64", "aarch64"]
|
||||
repo_arch_package_status = {}
|
||||
|
||||
# 5. Set all repository, architecture, and package statuses to "in progress" (e.g., code="building").
|
||||
for r in repos:
|
||||
for a in archs:
|
||||
repo_arch_package_status[(r, a, "pkgA")] = ("building", "building")
|
||||
|
||||
def build_result_handler(request):
|
||||
return create_build_result_xml(project_name, repo_arch_package_status)
|
||||
|
||||
setup_obs_mock(httpserver, project_name, build_result_handler)
|
||||
|
||||
# Expected Result 1: "Build is started in..."
|
||||
assert wait_for_comment(gitea_env, "myproducts/mySLFO", prj_pr_number, "Build is started in", project_name), "Staging bot did not post 'Build is started' comment."
|
||||
|
||||
# 6. Transition the first repository (all architectures) to "finished" mode and set its package statuses to "success" (e.g., code="succeeded").
|
||||
for a in archs:
|
||||
repo_arch_package_status[("repo1", a, "pkgA")] = ("published", "succeeded")
|
||||
|
||||
# 7. Transition the second repository (all architectures) to "finished" mode and set its package statuses to "failed" (e.g., code="failed").
|
||||
for a in archs:
|
||||
repo_arch_package_status[("repo2", a, "pkgA")] = ("finished", "failed")
|
||||
|
||||
# Expected Result 2: "Build failed" on project PR.
|
||||
assert wait_for_comment(gitea_env, "myproducts/mySLFO", prj_pr_number, "Build failed"), "Staging bot did not post 'Build failed' comment on project PR."
|
||||
|
||||
# Expected Result 3: "Build failed, for more information go in..." on package PR.
|
||||
assert wait_for_comment(gitea_env, "mypool/pkgA", pkg_pr_number, "Build failed, for more information go in", project_name), "Staging bot did not post 'Build failed' comment on package PR."
|
||||
|
||||
@pytest.mark.t003
|
||||
def test_003_build_on_some_archs_failed(staging_main_env, httpserver):
|
||||
gitea_env, test_full_repo_name, merge_branch_name = staging_main_env
|
||||
|
||||
# 1. Create a package PR.
|
||||
diff = "diff --git a/test_br_some_fail.txt b/test_br_some_fail.txt\nnew file mode 100644\nindex 00000000..473a0f4c\n"
|
||||
pr = gitea_env.create_gitea_pr("mypool/pkgA", diff, "Test BR Some Fail PR", False, base_branch=merge_branch_name)
|
||||
pkg_pr_number = pr["number"]
|
||||
|
||||
# 2. Wait for the workflow-pr bot to create the related project PR.
|
||||
prj_pr_number = gitea_env.wait_for_project_pr("mypool/pkgA", pkg_pr_number)
|
||||
assert prj_pr_number is not None, "Workflow bot did not create a project PR."
|
||||
|
||||
# 3. Wait for staging-bot to be added as a reviewer.
|
||||
assert wait_for_staging_bot_reviewer(gitea_env, prj_pr_number), "Staging bot was not added as a reviewer."
|
||||
|
||||
# 4. Mock the OBS result list with 2 repositories and 2 architectures.
|
||||
project_name = f"openSUSE:Leap:16.0:PullRequest:{prj_pr_number}"
|
||||
repos = ["repo1", "repo2"]
|
||||
archs = ["x86_64", "aarch64"]
|
||||
repo_arch_package_status = {}
|
||||
|
||||
# 5. Set all repository, architecture, and package statuses to "in progress" (e.g., code="building").
|
||||
for r in repos:
|
||||
for a in archs:
|
||||
repo_arch_package_status[(r, a, "pkgA")] = ("building", "building")
|
||||
|
||||
def build_result_handler(request):
|
||||
return create_build_result_xml(project_name, repo_arch_package_status)
|
||||
|
||||
setup_obs_mock(httpserver, project_name, build_result_handler)
|
||||
|
||||
# Expected Result 1: "Build is started in..."
|
||||
assert wait_for_comment(gitea_env, "myproducts/mySLFO", prj_pr_number, "Build is started in", project_name), "Staging bot did not post 'Build is started' comment."
|
||||
|
||||
# 6. Transition the first repository (all architectures) to "finished" mode and set its package statuses to "success" (e.g., code="succeeded").
|
||||
for a in archs:
|
||||
repo_arch_package_status[("repo1", a, "pkgA")] = ("published", "succeeded")
|
||||
|
||||
# 7. Transition the second repository to "finished" mode, setting the first architecture to "failed" (code="failed") and the second architecture to "success" (code="succeeded").
|
||||
repo_arch_package_status[("repo2", archs[0], "pkgA")] = ("finished", "failed")
|
||||
repo_arch_package_status[("repo2", archs[1], "pkgA")] = ("finished", "succeeded")
|
||||
|
||||
# Expected Result 2: "Build failed" on project PR.
|
||||
assert wait_for_comment(gitea_env, "myproducts/mySLFO", prj_pr_number, "Build failed"), "Staging bot did not post 'Build failed' comment on project PR."
|
||||
|
||||
# Expected Result 3: "Build failed, for more information go in..." on package PR.
|
||||
assert wait_for_comment(gitea_env, "mypool/pkgA", pkg_pr_number, "Build failed, for more information go in", project_name), "Staging bot did not post 'Build failed' comment on package PR."
|
||||
|
||||
@pytest.mark.t004
|
||||
def test_004_build_multiple_packages_success(staging_main_env, httpserver):
|
||||
gitea_env, test_full_repo_name, merge_branch_name = staging_main_env
|
||||
|
||||
# 1. Create package PRs.
|
||||
diff = "diff --git a/test_br_multi_pkgA.txt b/test_br_multi_pkgA.txt\nnew file mode 100644\nindex 00000000..473a0f4c\n"
|
||||
pr1 = gitea_env.create_gitea_pr("mypool/pkgA", diff, "Test BR Multi PR A", False, base_branch=merge_branch_name)
|
||||
pkg_pr_number1 = pr1["number"]
|
||||
pkg_head_sha1 = pr1["head"]["sha"]
|
||||
|
||||
diff2 = "diff --git a/test_br_multi_pkgB.txt b/test_br_multi_pkgB.txt\nnew file mode 100644\nindex 00000000..473a0f4c\n"
|
||||
pr2 = gitea_env.create_gitea_pr("mypool/pkgB", diff2, "Test BR Multi PR B", False, base_branch=merge_branch_name)
|
||||
pkg_pr_number2 = pr2["number"]
|
||||
pkg_head_sha2 = pr2["head"]["sha"]
|
||||
|
||||
# 2. Create a project PR mentioning both packages in description and UPDATING SUBMODULES.
|
||||
old_sha1 = gitea_env.get_submodule_sha("myproducts", "mySLFO", "pkgA", ref=merge_branch_name)
|
||||
old_sha2 = gitea_env.get_submodule_sha("myproducts", "mySLFO", "pkgB", ref=merge_branch_name)
|
||||
|
||||
prj_diff = create_submodule_diff("pkgA", old_sha1, pkg_head_sha1)
|
||||
prj_diff += create_submodule_diff("pkgB", old_sha2, pkg_head_sha2)
|
||||
|
||||
body = f"PR: mypool/pkgA!{pkg_pr_number1}\nPR: mypool/pkgB!{pkg_pr_number2}"
|
||||
prj_pr = gitea_env.create_gitea_pr("myproducts/mySLFO", prj_diff, "Test Project PR Multi", False, base_branch=merge_branch_name, body=body)
|
||||
prj_pr_number = prj_pr["number"]
|
||||
|
||||
# 3. Add staging_bot as a reviewer.
|
||||
gitea_env.request_reviewers("myproducts/mySLFO", prj_pr_number, ["autogits_obs_staging_bot"])
|
||||
|
||||
# Wait for staging-bot to be added (verification)
|
||||
assert wait_for_staging_bot_reviewer(gitea_env, prj_pr_number), "Staging bot was not added as a reviewer."
|
||||
|
||||
# 4. Mock the OBS result list with 2 repositories and 2 architectures for each package.
|
||||
project_name = f"openSUSE:Leap:16.0:PullRequest:{prj_pr_number}"
|
||||
repos = ["repo1", "repo2"]
|
||||
archs = ["x86_64", "aarch64"]
|
||||
packages = ["pkgA", "pkgB"]
|
||||
repo_arch_package_status = {}
|
||||
|
||||
# 5. Set all repository, architecture, and package statuses to "in progress" (e.g., code="building").
|
||||
for r in repos:
|
||||
for a in archs:
|
||||
for p in packages:
|
||||
repo_arch_package_status[(r, a, p)] = ("building", "building")
|
||||
|
||||
def build_result_handler(request):
|
||||
return create_build_result_xml(project_name, repo_arch_package_status)
|
||||
|
||||
setup_obs_mock(httpserver, project_name, build_result_handler)
|
||||
|
||||
# Expected Result 1: "Build is started in..."
|
||||
assert wait_for_comment(gitea_env, "myproducts/mySLFO", prj_pr_number, "Build is started in", project_name), "Staging bot did not post 'Build is started' comment."
|
||||
|
||||
# 6. Transition all repositories and architectures for the first package to "finished" mode and set its package statuses to "success" (e.g., code="succeeded").
|
||||
for r in repos:
|
||||
for a in archs:
|
||||
repo_arch_package_status[(r, a, "pkgA")] = ("published", "succeeded")
|
||||
|
||||
# Verify "Build successful" is NOT yet posted
|
||||
time.sleep(5)
|
||||
events = gitea_env.get_timeline_events("myproducts/mySLFO", prj_pr_number)
|
||||
assert not any(e.get("body") == "Build successful" for e in events), "Build successful posted prematurely."
|
||||
|
||||
# 7. Transition all repositories and architectures for the second package to "finished" mode and set its package statuses to "success" (e.g., code="succeeded").
|
||||
for r in repos:
|
||||
for a in archs:
|
||||
repo_arch_package_status[(r, a, "pkgB")] = ("published", "succeeded")
|
||||
|
||||
# Expected Result 2: "Build successful" on project PR.
|
||||
assert wait_for_comment(gitea_env, "myproducts/mySLFO", prj_pr_number, "Build successful"), "Staging bot did not post 'Build successful' comment on project PR."
|
||||
|
||||
# Expected Result 3: "Build successful..." on each package PR.
|
||||
assert wait_for_comment(gitea_env, "mypool/pkgA", pkg_pr_number1, "Build successful, for more information go in", project_name), "Staging bot did not post 'Build successful' comment on package PR A."
|
||||
assert wait_for_comment(gitea_env, "mypool/pkgB", pkg_pr_number2, "Build successful, for more information go in", project_name), "Staging bot did not post 'Build successful' comment on package PR B."
|
||||
|
||||
@pytest.mark.t005
|
||||
def test_005_build_multiple_packages_mix(staging_main_env, httpserver):
|
||||
gitea_env, test_full_repo_name, merge_branch_name = staging_main_env
|
||||
|
||||
# 1. Create package PRs.
|
||||
diff = "diff --git a/test_br_mix_multi_pkgA.txt b/test_br_mix_multi_pkgA.txt\nnew file mode 100644\nindex 00000000..473a0f4c\n"
|
||||
pr1 = gitea_env.create_gitea_pr("mypool/pkgA", diff, "Test BR Mix Multi PR A", False, base_branch=merge_branch_name)
|
||||
pkg_pr_number1 = pr1["number"]
|
||||
pkg_head_sha1 = pr1["head"]["sha"]
|
||||
|
||||
diff2 = "diff --git a/test_br_mix_multi_pkgB.txt b/test_br_mix_multi_pkgB.txt\nnew file mode 100644\nindex 00000000..473a0f4c\n"
|
||||
pr2 = gitea_env.create_gitea_pr("mypool/pkgB", diff2, "Test BR Mix Multi PR B", False, base_branch=merge_branch_name)
|
||||
pkg_pr_number2 = pr2["number"]
|
||||
pkg_head_sha2 = pr2["head"]["sha"]
|
||||
|
||||
# 2. Create a project PR mentioning both packages in description and UPDATING SUBMODULES.
|
||||
old_sha1 = gitea_env.get_submodule_sha("myproducts", "mySLFO", "pkgA", ref=merge_branch_name)
|
||||
old_sha2 = gitea_env.get_submodule_sha("myproducts", "mySLFO", "pkgB", ref=merge_branch_name)
|
||||
|
||||
prj_diff = create_submodule_diff("pkgA", old_sha1, pkg_head_sha1)
|
||||
prj_diff += create_submodule_diff("pkgB", old_sha2, pkg_head_sha2)
|
||||
|
||||
body = f"PR: mypool/pkgA!{pkg_pr_number1}\nPR: mypool/pkgB!{pkg_pr_number2}"
|
||||
prj_pr = gitea_env.create_gitea_pr("myproducts/mySLFO", prj_diff, "Test Project PR Multi Mix", False, base_branch=merge_branch_name, body=body)
|
||||
prj_pr_number = prj_pr["number"]
|
||||
|
||||
# 3. Add staging_bot as a reviewer.
|
||||
gitea_env.request_reviewers("myproducts/mySLFO", prj_pr_number, ["autogits_obs_staging_bot"])
|
||||
|
||||
# Wait for staging-bot to be added (verification)
|
||||
assert wait_for_staging_bot_reviewer(gitea_env, prj_pr_number), "Staging bot was not added as a reviewer."
|
||||
|
||||
# 4. Mock the OBS result list with 2 repositories and 2 architectures for each package.
|
||||
project_name = f"openSUSE:Leap:16.0:PullRequest:{prj_pr_number}"
|
||||
repos = ["repo1", "repo2"]
|
||||
archs = ["x86_64", "aarch64"]
|
||||
packages = ["pkgA", "pkgB"]
|
||||
repo_arch_package_status = {}
|
||||
|
||||
# 5. Set all repository, architecture, and package statuses to "in progress" (e.g., code="building").
|
||||
for r in repos:
|
||||
for a in archs:
|
||||
for p in packages:
|
||||
repo_arch_package_status[(r, a, p)] = ("building", "building")
|
||||
|
||||
def build_result_handler(request):
|
||||
return create_build_result_xml(project_name, repo_arch_package_status)
|
||||
|
||||
setup_obs_mock(httpserver, project_name, build_result_handler)
|
||||
|
||||
# Expected Result 1: "Build is started in..."
|
||||
assert wait_for_comment(gitea_env, "myproducts/mySLFO", prj_pr_number, "Build is started in", project_name), "Staging bot did not post 'Build is started' comment."
|
||||
|
||||
# 6. Transition the first package (all repositories and architectures) to "finished" mode and set its package statuses to "success" (e.g., code="succeeded").
|
||||
for r in repos:
|
||||
for a in archs:
|
||||
repo_arch_package_status[(r, a, "pkgA")] = ("published", "succeeded")
|
||||
|
||||
# 7. Transition the second package (all repositories and architectures) to "finished" mode and set its package statuses to "failed" (e.g., code="failed").
|
||||
for r in repos:
|
||||
for a in archs:
|
||||
repo_arch_package_status[(r, a, "pkgB")] = ("finished", "failed")
|
||||
|
||||
# Expected Result 2: "Build failed" on project PR.
|
||||
assert wait_for_comment(gitea_env, "myproducts/mySLFO", prj_pr_number, "Build failed"), "Staging bot did not post 'Build failed' comment on project PR."
|
||||
|
||||
# Expected Result 3: "Build successful..." on the successful package's PR.
|
||||
assert wait_for_comment(gitea_env, "mypool/pkgA", pkg_pr_number1, "Build successful, for more information go in", project_name), "Staging bot did not post 'Build successful' comment on package PR A."
|
||||
|
||||
# Expected Result 4: "Build failed..." on the failed package's PR.
|
||||
assert wait_for_comment(gitea_env, "mypool/pkgB", pkg_pr_number2, "Build failed, for more information go in", project_name), "Staging bot did not post 'Build failed' comment on package PR B."
|
||||
|
||||
@pytest.mark.t006
|
||||
def test_006_build_multiple_packages_partial_fail(staging_main_env, httpserver):
|
||||
gitea_env, test_full_repo_name, merge_branch_name = staging_main_env
|
||||
|
||||
# 1. Create package PRs.
|
||||
diff = "diff --git a/test_br_partial_multi_pkgA.txt b/test_br_partial_multi_pkgA.txt\nnew file mode 100644\nindex 00000000..473a0f4c\n"
|
||||
pr1 = gitea_env.create_gitea_pr("mypool/pkgA", diff, "Test BR Partial Multi PR A", False, base_branch=merge_branch_name)
|
||||
pkg_pr_number1 = pr1["number"]
|
||||
pkg_head_sha1 = pr1["head"]["sha"]
|
||||
|
||||
diff2 = "diff --git a/test_br_partial_multi_pkgB.txt b/test_br_partial_multi_pkgB.txt\nnew file mode 100644\nindex 00000000..473a0f4c\n"
|
||||
pr2 = gitea_env.create_gitea_pr("mypool/pkgB", diff2, "Test BR Partial Multi PR B", False, base_branch=merge_branch_name)
|
||||
pkg_pr_number2 = pr2["number"]
|
||||
pkg_head_sha2 = pr2["head"]["sha"]
|
||||
|
||||
# 2. Create a project PR mentioning both packages in description and UPDATING SUBMODULES.
|
||||
old_sha1 = gitea_env.get_submodule_sha("myproducts", "mySLFO", "pkgA", ref=merge_branch_name)
|
||||
old_sha2 = gitea_env.get_submodule_sha("myproducts", "mySLFO", "pkgB", ref=merge_branch_name)
|
||||
|
||||
prj_diff = create_submodule_diff("pkgA", old_sha1, pkg_head_sha1)
|
||||
prj_diff += create_submodule_diff("pkgB", old_sha2, pkg_head_sha2)
|
||||
|
||||
body = f"PR: mypool/pkgA!{pkg_pr_number1}\nPR: mypool/pkgB!{pkg_pr_number2}"
|
||||
prj_pr = gitea_env.create_gitea_pr("myproducts/mySLFO", prj_diff, "Test Project PR Multi Partial", False, base_branch=merge_branch_name, body=body)
|
||||
prj_pr_number = prj_pr["number"]
|
||||
|
||||
# 3. Add staging_bot as a reviewer.
|
||||
gitea_env.request_reviewers("myproducts/mySLFO", prj_pr_number, ["autogits_obs_staging_bot"])
|
||||
|
||||
# Wait for staging-bot to be added (verification)
|
||||
assert wait_for_staging_bot_reviewer(gitea_env, prj_pr_number), "Staging bot was not added as a reviewer."
|
||||
|
||||
# 4. Mock the OBS result list with 2 repositories and 2 architectures for each package.
|
||||
project_name = f"openSUSE:Leap:16.0:PullRequest:{prj_pr_number}"
|
||||
repos = ["repo1", "repo2"]
|
||||
archs = ["x86_64", "aarch64"]
|
||||
packages = ["pkgA", "pkgB"]
|
||||
repo_arch_package_status = {}
|
||||
|
||||
# 5. Set all repository, architecture, and package statuses to "in progress" (e.g., code="building").
|
||||
for r in repos:
|
||||
for a in archs:
|
||||
for p in packages:
|
||||
repo_arch_package_status[(r, a, p)] = ("building", "building")
|
||||
|
||||
def build_result_handler(request):
|
||||
return create_build_result_xml(project_name, repo_arch_package_status)
|
||||
|
||||
setup_obs_mock(httpserver, project_name, build_result_handler)
|
||||
|
||||
# Expected Result 1: "Build is started in..."
|
||||
assert wait_for_comment(gitea_env, "myproducts/mySLFO", prj_pr_number, "Build is started in", project_name), "Staging bot did not post 'Build is started' comment."
|
||||
|
||||
# 6. Transition the first package (all repositories and architectures) to "finished" mode and set its package statuses to "success" (e.g., code="succeeded").
|
||||
for r in repos:
|
||||
for a in archs:
|
||||
repo_arch_package_status[(r, a, "pkgA")] = ("published", "succeeded")
|
||||
|
||||
# 7. Transition the second package:
|
||||
# Repository 1 (all architectures) to "finished" mode with "success" (e.g., code="succeeded").
|
||||
for a in archs:
|
||||
repo_arch_package_status[("repo1", a, "pkgB")] = ("published", "succeeded")
|
||||
|
||||
# Repository 2 (all architectures) to "finished" mode with "failed" (e.g., code="failed").
|
||||
for a in archs:
|
||||
repo_arch_package_status[("repo2", a, "pkgB")] = ("finished", "failed")
|
||||
|
||||
# Expected Result 2: "Build failed" on project PR.
|
||||
assert wait_for_comment(gitea_env, "myproducts/mySLFO", prj_pr_number, "Build failed"), "Staging bot did not post 'Build failed' comment on project PR."
|
||||
|
||||
# Expected Result 3: "Build successful..." on the first (successful) package's PR.
|
||||
assert wait_for_comment(gitea_env, "mypool/pkgA", pkg_pr_number1, "Build successful, for more information go in", project_name), "Staging bot did not post 'Build successful' comment on package PR A."
|
||||
|
||||
# Expected Result 4: "Build failed..." on the second (failed) package's PR.
|
||||
assert wait_for_comment(gitea_env, "mypool/pkgB", pkg_pr_number2, "Build failed, for more information go in", project_name), "Staging bot did not post 'Build failed' comment on package PR B."
|
||||
|
||||
@pytest.mark.t007
|
||||
def test_007_build_multiple_packages_arch_fail(staging_main_env, httpserver):
|
||||
gitea_env, test_full_repo_name, merge_branch_name = staging_main_env
|
||||
|
||||
# 1. Create package PRs.
|
||||
diff = "diff --git a/test_br_arch_multi_pkgA.txt b/test_br_arch_multi_pkgA.txt\nnew file mode 100644\nindex 00000000..473a0f4c\n"
|
||||
pr1 = gitea_env.create_gitea_pr("mypool/pkgA", diff, "Test BR Arch Multi PR A", False, base_branch=merge_branch_name)
|
||||
pkg_pr_number1 = pr1["number"]
|
||||
pkg_head_sha1 = pr1["head"]["sha"]
|
||||
|
||||
diff2 = "diff --git a/test_br_arch_multi_pkgB.txt b/test_br_arch_multi_pkgB.txt\nnew file mode 100644\nindex 00000000..473a0f4c\n"
|
||||
pr2 = gitea_env.create_gitea_pr("mypool/pkgB", diff2, "Test BR Arch Multi PR B", False, base_branch=merge_branch_name)
|
||||
pkg_pr_number2 = pr2["number"]
|
||||
pkg_head_sha2 = pr2["head"]["sha"]
|
||||
|
||||
# 2. Create a project PR mentioning both packages in description and UPDATING SUBMODULES.
|
||||
old_sha1 = gitea_env.get_submodule_sha("myproducts", "mySLFO", "pkgA", ref=merge_branch_name)
|
||||
old_sha2 = gitea_env.get_submodule_sha("myproducts", "mySLFO", "pkgB", ref=merge_branch_name)
|
||||
|
||||
prj_diff = create_submodule_diff("pkgA", old_sha1, pkg_head_sha1)
|
||||
prj_diff += create_submodule_diff("pkgB", old_sha2, pkg_head_sha2)
|
||||
|
||||
body = f"PR: mypool/pkgA!{pkg_pr_number1}\nPR: mypool/pkgB!{pkg_pr_number2}"
|
||||
prj_pr = gitea_env.create_gitea_pr("myproducts/mySLFO", prj_diff, "Test Project PR Multi Arch Fail", False, base_branch=merge_branch_name, body=body)
|
||||
prj_pr_number = prj_pr["number"]
|
||||
|
||||
# 3. Add staging_bot as a reviewer.
|
||||
gitea_env.request_reviewers("myproducts/mySLFO", prj_pr_number, ["autogits_obs_staging_bot"])
|
||||
|
||||
# Wait for staging-bot to be added (verification)
|
||||
assert wait_for_staging_bot_reviewer(gitea_env, prj_pr_number), "Staging bot was not added as a reviewer."
|
||||
|
||||
# 4. Mock the OBS result list with 2 repositories and 2 architectures for each package.
|
||||
project_name = f"openSUSE:Leap:16.0:PullRequest:{prj_pr_number}"
|
||||
repos = ["repo1", "repo2"]
|
||||
archs = ["x86_64", "aarch64"]
|
||||
packages = ["pkgA", "pkgB"]
|
||||
repo_arch_package_status = {}
|
||||
|
||||
# 5. Set all repository, architecture, and package statuses to "in progress" (e.g., code="building").
|
||||
for r in repos:
|
||||
for a in archs:
|
||||
for p in packages:
|
||||
repo_arch_package_status[(r, a, p)] = ("building", "building")
|
||||
|
||||
def build_result_handler(request):
|
||||
return create_build_result_xml(project_name, repo_arch_package_status)
|
||||
|
||||
setup_obs_mock(httpserver, project_name, build_result_handler)
|
||||
|
||||
# Expected Result 1: "Build is started in..."
|
||||
assert wait_for_comment(gitea_env, "myproducts/mySLFO", prj_pr_number, "Build is started in", project_name), "Staging bot did not post 'Build is started' comment."
|
||||
|
||||
# 6. Transition the first package (all repositories and architectures) to "finished" mode and set its package statuses to "success" (e.g., code="succeeded").
|
||||
for r in repos:
|
||||
for a in archs:
|
||||
repo_arch_package_status[(r, a, "pkgA")] = ("published", "succeeded")
|
||||
|
||||
# 7. Transition the second package:
|
||||
# Architecture 1 (all repositories) to "finished" mode with "success" (e.g., code="succeeded").
|
||||
for r in repos:
|
||||
repo_arch_package_status[(r, archs[0], "pkgB")] = ("published", "succeeded")
|
||||
|
||||
# Architecture 2 (all repositories) to "finished" mode with "failed" (e.g., code="failed").
|
||||
for r in repos:
|
||||
repo_arch_package_status[(r, archs[1], "pkgB")] = ("finished", "failed")
|
||||
|
||||
# Expected Result 2: "Build failed" on project PR.
|
||||
assert wait_for_comment(gitea_env, "myproducts/mySLFO", prj_pr_number, "Build failed"), "Staging bot did not post 'Build failed' comment on project PR."
|
||||
|
||||
# Expected Result 3: "Build successful..." on the first (successful) package's PR.
|
||||
assert wait_for_comment(gitea_env, "mypool/pkgA", pkg_pr_number1, "Build successful, for more information go in", project_name), "Staging bot did not post 'Build successful' comment on package PR A."
|
||||
|
||||
# Expected Result 4: "Build failed..." on the second (failed) package's PR.
|
||||
assert wait_for_comment(gitea_env, "mypool/pkgB", pkg_pr_number2, "Build failed, for more information go in", project_name), "Staging bot did not post 'Build failed' comment on package PR B."
|
||||
@@ -14,7 +14,7 @@ from tests.lib.common_test_utils import (
|
||||
def test_pr_workflow_succeeded(staging_main_env, mock_build_result):
|
||||
"""End-to-end test for a successful PR workflow."""
|
||||
gitea_env, test_full_repo_name, merge_branch_name = staging_main_env
|
||||
diff = "diff --git a/test.txt b/test.txt\nnew file mode 100644\nindex 00000000..473a0f4c\n"
|
||||
diff = "diff --git a/test.txt b/test.txt\nnew file mode 100644\nindex 0000000..e69de29\n"
|
||||
pr = gitea_env.create_gitea_pr("mypool/pkgA", diff, "Test PR - should succeed", False, base_branch=merge_branch_name)
|
||||
initial_pr_number = pr["number"]
|
||||
|
||||
@@ -59,7 +59,7 @@ def test_pr_workflow_succeeded(staging_main_env, mock_build_result):
|
||||
def test_pr_workflow_failed(staging_main_env, mock_build_result):
|
||||
"""End-to-end test for a failed PR workflow."""
|
||||
gitea_env, test_full_repo_name, merge_branch_name = staging_main_env
|
||||
diff = "diff --git a/another_test.txt b/another_test.txt\nnew file mode 100644\nindex 00000000..473a0f4c\n"
|
||||
diff = "diff --git a/another_test.txt b/another_test.txt\nnew file mode 100644\nindex 0000000..e69de29\n"
|
||||
pr = gitea_env.create_gitea_pr("mypool/pkgA", diff, "Test PR - should fail", False, base_branch=merge_branch_name)
|
||||
initial_pr_number = pr["number"]
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ def test_001_project_pr_labels(label_env, staging_bot_client):
|
||||
# 1. Create a package PR
|
||||
diff = """diff --git a/label_test_fixture.txt b/label_test_fixture.txt
|
||||
new file mode 100644
|
||||
index 00000000..473a0f4c
|
||||
index 0000000..e69de29
|
||||
"""
|
||||
print(f"--- Creating package PR in mypool/pkgA on branch {branch_name} ---")
|
||||
package_pr = gitea_env.create_gitea_pr("mypool/pkgA", diff, "Test Labels Fixture", False, base_branch=branch_name)
|
||||
|
||||
@@ -17,7 +17,7 @@ def test_001_automerge(automerge_env, test_user_client):
|
||||
# 1. Create a package PR
|
||||
diff = """diff --git a/automerge_test.txt b/automerge_test.txt
|
||||
new file mode 100644
|
||||
index 00000000..473a0f4c
|
||||
index 0000000..e69de29
|
||||
"""
|
||||
print(f"--- Creating package PR in mypool/pkgA on branch {merge_branch_name} ---")
|
||||
package_pr = test_user_client.create_gitea_pr("mypool/pkgA", diff, "Test Automerge Fixture", False, base_branch=merge_branch_name)
|
||||
@@ -49,7 +49,7 @@ def test_002_manual_merge(manual_merge_env, test_user_client, usera_client, stag
|
||||
# 1. Create a package PR
|
||||
diff = """diff --git a/manual_merge_test.txt b/manual_merge_test.txt
|
||||
new file mode 100644
|
||||
index 00000000..473a0f4c
|
||||
index 0000000..e69de29
|
||||
"""
|
||||
print(f"--- Creating package PR in mypool/pkgA on branch {merge_branch_name} ---")
|
||||
package_pr = gitea_env.create_gitea_pr("mypool/pkgA", diff, "Test Manual Merge Fixture", False, base_branch=merge_branch_name)
|
||||
@@ -149,7 +149,7 @@ def test_003_refuse_manual_merge(manual_merge_env, test_user_client, ownerB_clie
|
||||
# 1. Create a package PR
|
||||
diff = """diff --git a/manual_merge_test.txt b/manual_merge_test.txt
|
||||
new file mode 100644
|
||||
index 00000000..473a0f4c
|
||||
index 0000000..e69de29
|
||||
"""
|
||||
print(f"--- Creating package PR in mypool/pkgA on branch {merge_branch_name} ---")
|
||||
package_pr = test_user_client.create_gitea_pr("mypool/pkgA", diff, "Test Manual Merge Fixture", False, base_branch=merge_branch_name)
|
||||
@@ -245,7 +245,7 @@ def test_008_merge_mode_ff_only_success(merge_ff_env, test_user_client):
|
||||
# 1. Create a package PR (this will be FF-mergeable by default)
|
||||
diff = """diff --git a/ff_test.txt b/ff_test.txt
|
||||
new file mode 100644
|
||||
index 00000000..473a0f4c
|
||||
index 0000000..e69de29
|
||||
"""
|
||||
package_pr = test_user_client.create_gitea_pr("mypool/pkgA", diff, "Test FF Merge", False, base_branch=merge_branch_name)
|
||||
package_pr_number = package_pr["number"]
|
||||
@@ -269,7 +269,7 @@ def test_009_merge_mode_ff_only_failure(merge_ff_env, ownerA_client):
|
||||
# 1. Create a package PR that adds a file
|
||||
diff = f"""diff --git a/{filename} b/{filename}
|
||||
new file mode 100644
|
||||
index 00000000..473a0f4c
|
||||
index 0000000..e69de29
|
||||
--- /dev/null
|
||||
+++ b/{filename}
|
||||
@@ -0,0 +1 @@
|
||||
@@ -291,7 +291,7 @@ index 00000000..473a0f4c
|
||||
|
||||
print("Pushing another change to PR branch to trigger sync...")
|
||||
gitea_env.modify_gitea_pr("mypool/pkgA", package_pr_number,
|
||||
"diff --git a/sync_test.txt b/sync_test.txt\nnew file mode 100644\nindex 00000000..473a0f4c\n",
|
||||
"diff --git a/sync_test.txt b/sync_test.txt\nnew file mode 100644\nindex 0000000..e69de29\n",
|
||||
"Trigger Sync")
|
||||
|
||||
# The bot should detect it's not FF and NOT merge, and re-request reviews because of the new commit
|
||||
@@ -323,7 +323,7 @@ def test_010_merge_mode_devel_success(merge_devel_env, ownerA_client):
|
||||
# 1. Create a package PR that adds a file
|
||||
diff = f"""diff --git a/{filename} b/{filename}
|
||||
new file mode 100644
|
||||
index 00000000..473a0f4c
|
||||
index 0000000..e69de29
|
||||
--- /dev/null
|
||||
+++ b/{filename}
|
||||
@@ -0,0 +1 @@
|
||||
@@ -365,7 +365,7 @@ def test_011_merge_mode_replace_success(merge_replace_env, ownerA_client):
|
||||
# 1. Create a package PR that adds a file
|
||||
diff = f"""diff --git a/{filename} b/{filename}
|
||||
new file mode 100644
|
||||
index 00000000..473a0f4c
|
||||
index 0000000..e69de29
|
||||
--- /dev/null
|
||||
+++ b/{filename}
|
||||
@@ -0,0 +1 @@
|
||||
@@ -419,7 +419,7 @@ def test_012_merge_mode_devel_ff_success(merge_devel_env, ownerA_client):
|
||||
# 1. Create a package PR (this will be FF-mergeable by default)
|
||||
diff = f"""diff --git a/{filename} b/{filename}
|
||||
new file mode 100644
|
||||
index 00000000..473a0f4c
|
||||
index 0000000..e69de29
|
||||
--- /dev/null
|
||||
+++ b/{filename}
|
||||
@@ -0,0 +1 @@
|
||||
@@ -461,7 +461,7 @@ def test_013_merge_mode_replace_ff_success(merge_replace_env, ownerA_client):
|
||||
# 1. Create a package PR (this will be FF-mergeable by default)
|
||||
diff = f"""diff --git a/{filename} b/{filename}
|
||||
new file mode 100644
|
||||
index 00000000..473a0f4c
|
||||
index 0000000..e69de29
|
||||
--- /dev/null
|
||||
+++ b/{filename}
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -20,7 +20,7 @@ def test_001_review_requests_matching_config(automerge_env, ownerA_client):
|
||||
filename = f"pkgB_test_{ts}.txt"
|
||||
diff = f"""diff --git a/{filename} b/{filename}
|
||||
new file mode 100644
|
||||
index 00000000..473a0f4c
|
||||
index 0000000..e69de29
|
||||
"""
|
||||
print(f"--- Creating package PR in mypool/pkgB on branch {branch_name} as ownerA ---")
|
||||
package_pr = ownerA_client.create_gitea_pr("mypool/pkgB", diff, "Test Review Requests Config", True, base_branch=branch_name)
|
||||
@@ -86,7 +86,7 @@ def test_004_maintainer(maintainer_env, ownerA_client):
|
||||
filename = f"maintainer_test_{ts}.txt"
|
||||
diff = f"""diff --git a/{filename} b/{filename}
|
||||
new file mode 100644
|
||||
index 00000000..473a0f4c
|
||||
index 0000000..e69de29
|
||||
"""
|
||||
print(f"--- Creating package PR in mypool/pkgA on branch {branch_name} as ownerA ---")
|
||||
package_pr = ownerA_client.create_gitea_pr("mypool/pkgA", diff, "Test Maintainer Merge", True, base_branch=branch_name)
|
||||
@@ -155,7 +155,7 @@ def test_005_any_maintainer_approval_sufficient(maintainer_env, ownerA_client, o
|
||||
filename = f"pkgB_test_{ts}.txt"
|
||||
diff = f"""diff --git a/{filename} b/{filename}
|
||||
new file mode 100644
|
||||
index 00000000..473a0f4c
|
||||
index 0000000..e69de29
|
||||
"""
|
||||
print(f"--- Creating package PR in mypool/pkgB on branch {branch_name} as ownerA ---")
|
||||
package_pr = ownerA_client.create_gitea_pr("mypool/pkgB", diff, "Test Single Maintainer Merge", True, base_branch=branch_name)
|
||||
@@ -217,7 +217,7 @@ def test_006_maintainer_rejection_removes_other_requests(maintainer_env, ownerA_
|
||||
filename = f"pkgB_rejection_test_{ts}.txt"
|
||||
diff = f"""diff --git a/{filename} b/{filename}
|
||||
new file mode 100644
|
||||
index 00000000..473a0f4c
|
||||
index 0000000..e69de29
|
||||
"""
|
||||
print(f"--- Creating package PR in mypool/pkgB on branch {branch_name} as ownerA ---")
|
||||
package_pr = ownerA_client.create_gitea_pr("mypool/pkgB", diff, "Test Maintainer Rejection", True, base_branch=branch_name)
|
||||
@@ -277,7 +277,7 @@ def test_007_review_required_needs_all_approvals(review_required_env, ownerA_cli
|
||||
filename = f"pkgB_review_required_test_{ts}.txt"
|
||||
diff = f"""diff --git a/{filename} b/{filename}
|
||||
new file mode 100644
|
||||
index 00000000..473a0f4c
|
||||
index 0000000..e69de29
|
||||
"""
|
||||
print(f"--- Creating package PR in mypool/pkgB on branch {branch_name} as ownerA ---")
|
||||
package_pr = ownerA_client.create_gitea_pr("mypool/pkgB", diff, "Test Review Required", True, base_branch=branch_name)
|
||||
|
||||
@@ -22,7 +22,7 @@ pytest.forwarded_pr_number = None
|
||||
@pytest.mark.dependency()
|
||||
def test_001_project_pr(gitea_env):
|
||||
"""Forwarded PR correct title"""
|
||||
diff = "diff --git a/another_test.txt b/another_test.txt\nnew file mode 100644\nindex 00000000..473a0f4c\n"
|
||||
diff = "diff --git a/another_test.txt b/another_test.txt\nnew file mode 100644\nindex 0000000..e69de29\n"
|
||||
pytest.pr = gitea_env.create_gitea_pr("mypool/pkgA", diff, "Test PR", False)
|
||||
pytest.initial_pr_number = pytest.pr["number"]
|
||||
time.sleep(5) # Give Gitea some time to process the PR and make the timeline available
|
||||
@@ -114,7 +114,7 @@ def test_005_NoProjectGitPR_edits_disabled(no_project_git_pr_env, test_user_clie
|
||||
# 1. Create a Package PR (without "Allow edits from maintainers" enabled)
|
||||
initial_diff = """diff --git a/first_file.txt b/first_file.txt
|
||||
new file mode 100644
|
||||
index 00000000..473a0f4c
|
||||
index 0000000..e69de29
|
||||
--- /dev/null
|
||||
+++ b/first_file.txt
|
||||
@@ -0,0 +1 @@
|
||||
@@ -160,7 +160,7 @@ index {pkgA_main_sha[:7]}..{pkgA_pr_head_sha[:7]} 160000
|
||||
# 4. Trigger an update on the Package PR to prompt the bot to react to the manual Project PR
|
||||
new_diff_content = """diff --git a/trigger_bot.txt b/trigger_bot.txt
|
||||
new file mode 100644
|
||||
index 00000000..473a0f4c
|
||||
index 0000000..e69de29
|
||||
--- /dev/null
|
||||
+++ b/trigger_bot.txt
|
||||
@@ -0,0 +1 @@
|
||||
@@ -200,7 +200,7 @@ def test_006_NoProjectGitPR_edits_enabled(no_project_git_pr_env, test_user_clien
|
||||
# 2. Create a Package PR with "Allow edits from maintainers" enabled
|
||||
diff = """diff --git a/new_feature.txt b/new_feature.txt
|
||||
new file mode 100644
|
||||
index 00000000..473a0f4c
|
||||
index 0000000..e69de29
|
||||
--- /dev/null
|
||||
+++ b/new_feature.txt
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -19,18 +19,22 @@ export GITEA_TOKEN
|
||||
echo "GITEA_TOKEN exported (length: ${#GITEA_TOKEN})"
|
||||
|
||||
# Wait for the dummy data to be created by the gitea setup script
|
||||
echo "Waiting for workflow.config in myproducts/mySLFO (branch zz-ready-to-start)..."
|
||||
API_URL="http://gitea-test:3000/api/v1/repos/myproducts/mySLFO/contents/workflow.config?ref=zz-ready-to-start"
|
||||
echo "Waiting for workflow.config in myproducts/mySLFO..."
|
||||
API_URL="http://gitea-test:3000/api/v1/repos/myproducts/mySLFO/contents/workflow.config"
|
||||
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: token $GITEA_TOKEN" "$API_URL")
|
||||
|
||||
WAITED=false
|
||||
while [ "$HTTP_STATUS" != "200" ]; do
|
||||
echo "workflow.config on zz-ready-to-start not found yet (HTTP Status: $HTTP_STATUS). Retrying in 1s..."
|
||||
sleep 1
|
||||
WAITED=true
|
||||
echo "workflow.config not found yet (HTTP Status: $HTTP_STATUS). Retrying in 5s..."
|
||||
sleep 5
|
||||
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: token $GITEA_TOKEN" "$API_URL")
|
||||
done
|
||||
|
||||
echo "workflow.config found on zz-ready-to-start."
|
||||
if [ "$WAITED" = true ]; then
|
||||
echo "workflow.config found. Sleeping 15s to let other configurations settle..."
|
||||
sleep 15
|
||||
fi
|
||||
|
||||
# Wait for the shared SSH key to be generated by the gitea setup script
|
||||
echo "Waiting for /var/lib/gitea/ssh-keys/id_ed25519..."
|
||||
|
||||
@@ -503,7 +503,10 @@ func updateConfiguration(configFilename string, orgs *[]string) {
|
||||
os.Exit(4)
|
||||
}
|
||||
|
||||
configs, _ := common.ResolveWorkflowConfigs(gitea, configFile)
|
||||
configs, err := common.ResolveWorkflowConfigs(gitea, configFile)
|
||||
if err != nil {
|
||||
common.LogError("Failed to resolve some configuration repositories:", err)
|
||||
}
|
||||
configuredRepos = make(map[string][]*common.AutogitConfig)
|
||||
*orgs = make([]string, 0, 1)
|
||||
for _, c := range configs {
|
||||
|
||||
@@ -58,6 +58,7 @@ func main() {
|
||||
checkOnStart := flag.Bool("check-on-start", common.GetEnvOverrideBool(os.Getenv("AUTOGITS_CHECK_ON_START"), false), "Check all repositories for consistency on start, without delays")
|
||||
checkIntervalHours := flag.Float64("check-interval", 5, "Check interval (+-random delay) for repositories for consitency, in hours")
|
||||
flag.BoolVar(&ListPROnly, "list-prs-only", false, "Only lists PRs without acting on them")
|
||||
exitOnConfigError := flag.Bool("exit-on-config-error", false, "Exit if any repository in configuration cannot be resolved")
|
||||
flag.Int64Var(&PRID, "id", -1, "Process only the specific ID and ignore the rest. Use for debugging")
|
||||
basePath := flag.String("repo-path", common.GetEnvOverrideString(os.Getenv("AUTOGITS_REPO_PATH"), ""), "Repository path. Default is temporary directory")
|
||||
pr := flag.String("only-pr", "", "Only specific PR to process. For debugging")
|
||||
@@ -97,8 +98,10 @@ func main() {
|
||||
|
||||
configs, err := common.ResolveWorkflowConfigs(Gitea, config)
|
||||
if err != nil {
|
||||
common.LogError("Cannot resolve config files:", err)
|
||||
return
|
||||
common.LogError("Failed to resolve some configuration repositories:", err)
|
||||
if *exitOnConfigError {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
for _, c := range configs {
|
||||
|
||||
Reference in New Issue
Block a user