From cb35c312c1c3a7487295bf77cb22b08d35e195bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Thu, 12 Oct 2023 15:20:50 +0200 Subject: [PATCH] make topic filter configurable --- buildbot_nix/buildbot_nix.py | 4 +++- examples/default.nix | 4 ++-- nix/checks/master.nix | 4 ++-- nix/master.nix | 17 +++++++++++++---- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/buildbot_nix/buildbot_nix.py b/buildbot_nix/buildbot_nix.py index d68a94d..6924438 100644 --- a/buildbot_nix/buildbot_nix.py +++ b/buildbot_nix/buildbot_nix.py @@ -511,6 +511,7 @@ class GithubConfig: webhook_secret_name: str = "github-webhook-secret" token_secret_name: str = "github-token" project_cache_file: Path = Path("github-project-cache.json") + topic_filter: str | None = "build-with-buildbot" def token(self) -> str: return read_secret_file(self.token_secret_name) @@ -633,7 +634,8 @@ class NixConfigurator(ConfiguratorBase): def configure(self, config: dict[str, Any]) -> None: projects = load_projects(self.github.token(), self.github.project_cache_file) - projects = [p for p in projects if "build-with-buildbot" in p.topics] + if self.github.topic_filter is not None: + projects = [p for p in projects if self.github.topic_filter in p.topics] worker_config = json.loads(read_secret_file(self.nix_workers_secret_name)) worker_names = [] config["workers"] = config.get("workers", []) diff --git a/examples/default.nix b/examples/default.nix index 80ede0c..418efad 100644 --- a/examples/default.nix +++ b/examples/default.nix @@ -29,8 +29,8 @@ in webhookSecretFile = "/var/lib/secrets/buildbot-nix/github-webhook-secret"; oauthSecretFile = "/var/lib/secrets/buildbot-nix/github-oauth-secret"; oauthId = "aaaaaaaaaaaaaaaaaaaa"; - githubUser = "mic92-buildbot"; - githubAdmins = [ "Mic92" ]; + user = "mic92-buildbot"; + admins = [ "Mic92" ]; }; }; services.nginx.virtualHosts."buildbot2.thalheim.io" = { diff --git a/nix/checks/master.nix b/nix/checks/master.nix index dbaab29..1a951aa 100644 --- a/nix/checks/master.nix +++ b/nix/checks/master.nix @@ -15,8 +15,8 @@ webhookSecretFile = "/var/lib/secrets/buildbot-nix/github-webhook-secret"; oauthSecretFile = "/var/lib/secrets/buildbot-nix/github-oauth-secret"; oauthId = "aaaaaaaaaaaaaaaaaaaa"; - githubUser = "mic92-buildbot"; - githubAdmins = [ "Mic92" ]; + user = "mic92-buildbot"; + admins = [ "Mic92" ]; }; }; }; diff --git a/nix/master.nix b/nix/master.nix index 65911fa..67b5a50 100644 --- a/nix/master.nix +++ b/nix/master.nix @@ -39,15 +39,23 @@ in description = "Github oauth id. Used for the login button"; }; # Most likely you want to use the same user as for the buildbot - githubUser = lib.mkOption { + user = lib.mkOption { type = lib.types.str; description = "Github user that is used for the buildbot"; }; - githubAdmins = lib.mkOption { + admins = lib.mkOption { type = lib.types.listOf lib.types.str; default = [ ]; description = "Users that are allowed to login to buildbot, trigger builds and change settings"; }; + topic = lib.mkOption { + type = lib.types.nullOr lib.types.str; + default = "build-with-buildbot"; + description = '' + Projects that have this topic will be built by buildbot. + If null, all projects that the buildbot github user has access to, are built. + ''; + }; }; workersFile = lib.mkOption { type = lib.types.path; @@ -97,8 +105,9 @@ in NixConfigurator( github=GithubConfig( oauth_id=${builtins.toJSON cfg.github.oauthId}, - admins=${builtins.toJSON cfg.github.githubAdmins}, - buildbot_user=${builtins.toJSON cfg.github.githubUser}, + admins=${builtins.toJSON cfg.github.admins}, + buildbot_user=${builtins.toJSON cfg.github.user}, + topic=${builtins.toJSON cfg.github.topic}, ), nix_eval_max_memory_size=${builtins.toJSON cfg.evalMaxMemorySize}, nix_supported_systems=${builtins.toJSON cfg.buildSystems},