Skip to content

Commit

Permalink
remove ofborg evaluation from code base
Browse files Browse the repository at this point in the history
We also require a github token to download github action results.
  • Loading branch information
Mic92 committed Jan 2, 2025
1 parent cbc1a05 commit 08f4ec7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 44 deletions.
6 changes: 3 additions & 3 deletions nixpkgs_review/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def pr_flags(
pr_parser = subparsers.add_parser("pr", help="review a pull request on nixpkgs")
pr_parser.add_argument(
"--eval",
default="ofborg",
choices=["ofborg", "local"],
help="Whether to use ofborg's evaluation result",
default="auto",
choices=["auto", "github", "local", "ofborg"], # ofborg is legacy
help="Whether to use github's evaluation result. Defaults to auto. Auto will use github if a github token is provided",
)
checkout_help = (
"What to source checkout when building: "
Expand Down
20 changes: 18 additions & 2 deletions nixpkgs_review/cli/pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,23 @@ def parse_pr_numbers(number_args: list[str]) -> list[int]:

def pr_command(args: argparse.Namespace) -> str:
prs: list[int] = parse_pr_numbers(args.number)
use_ofborg_eval = args.eval == "ofborg"
match args.eval:
case "ofborg":
warn("Warning: `--eval=ofborg` is deprecated. Use `--eval=github` instead.")
args.eval = "github"
case "auto":
if args.token:
args.eval = "github"
else:
warn(
"No GitHub token provided via GITHUB_TOKEN variable. Falling back to local evaluation."
)
args.eval = "local"
case "github":
if not args.token:
warn("No GitHub token provided")
sys.exit(1)
use_github_eval = args.eval == "github"
checkout_option = (
CheckoutOption.MERGE if args.checkout == "merge" else CheckoutOption.COMMIT
)
Expand Down Expand Up @@ -80,7 +96,7 @@ def pr_command(args: argparse.Namespace) -> str:
run=args.run,
remote=args.remote,
api_token=args.token,
use_ofborg_eval=use_ofborg_eval,
use_github_eval=use_github_eval,
only_packages=set(args.package),
package_regexes=args.package_regex,
skip_packages=set(args.skip_package),
Expand Down
31 changes: 0 additions & 31 deletions nixpkgs_review/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import urllib.parse
import urllib.request
import zipfile
from collections import defaultdict
from http.client import HTTPMessage
from pathlib import Path
from typing import IO, Any, override
Expand Down Expand Up @@ -189,33 +188,3 @@ def get_github_action_eval_result(
assert isinstance(path, dict)
return path
return None

def get_borg_eval_gist(self, pr: dict[str, Any]) -> dict[System, set[str]] | None:
packages_per_system: defaultdict[System, set[str]] = defaultdict(set)
statuses = self.get(pr["statuses_url"])
for status in statuses:
if (
status["description"] == "^.^!"
and status["state"] == "success"
and status["context"] == "ofborg-eval"
and status["creator"]["login"] == "ofborg[bot]"
):
url = status.get("target_url", "")
if url == "":
return packages_per_system

url = urllib.parse.urlparse(url)
gist_hash = url.path.split("/")[-1]
raw_gist_url = (
f"https://gist.githubusercontent.com/GrahamcOfBorg/{gist_hash}/raw/"
)

with urllib.request.urlopen(raw_gist_url) as resp: # noqa: S310
for line in resp:
if line == b"":
break
system, attribute = line.decode("utf-8").split()
packages_per_system[system].add(attribute)

return packages_per_system
return None
11 changes: 3 additions & 8 deletions nixpkgs_review/review.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def __init__(
nixpkgs_config: Path,
extra_nixpkgs_config: str,
api_token: str | None = None,
use_ofborg_eval: bool | None = True,
use_github_eval: bool | None = True,
only_packages: set[str] | None = None,
package_regexes: list[Pattern[str]] | None = None,
skip_packages: set[str] | None = None,
Expand All @@ -121,7 +121,7 @@ def __init__(
self.run = run
self.remote = remote
self.github_client = GithubClient(api_token)
self.use_ofborg_eval = use_ofborg_eval
self.use_github_eval = use_github_eval
self.checkout = checkout
self.only_packages = only_packages
self.package_regex = package_regexes
Expand Down Expand Up @@ -294,16 +294,11 @@ def build_pr(self, pr_number: int) -> dict[System, list[Attr]]:
pr = self.github_client.pull_request(pr_number)

packages_per_system: dict[System, set[str]] | None = None
if self.use_ofborg_eval and all(system in PLATFORMS for system in self.systems):
if self.use_github_eval and all(system in PLATFORMS for system in self.systems):
# Attempt to fetch the GitHub actions evaluation result
print("-> Attempting to fetch eval results from GitHub actions")
packages_per_system = self.github_client.get_github_action_eval_result(pr)

# If unsuccessfull, fallback to ofborg
if packages_per_system is None:
print("-> Unsuccessfull: Trying out legacy ofborg")
packages_per_system = self.github_client.get_borg_eval_gist(pr)

if packages_per_system is not None:
print("-> Successfully fetched rebuilds: no local evaluation needed")

Expand Down

0 comments on commit 08f4ec7

Please sign in to comment.