nix-community / buildbot-nix

A nixos module to make buildbot a proper Nix-CI [maintainer=@Mic92,@MagicRB]
MIT License
114 stars 23 forks source link

automatic way to provide properties to commands in `postBuildSteps` #306

Open steveej opened 1 month ago

steveej commented 1 month ago

currently i have the following hardcoded

            props = lib.attrsets.genAttrs [
              "attr"
              "basename"
              "branch"
              "builddir"
              "builderid"
              "buildername"
              "buildnumber"
              "cacheStatus"
              "codebase"
              "drv_path"
              "event"
              "github.base.sha"
              "github.head.sha"
              "out_path"
              "owners"
              "project"
              "projectid"
              "projectname"
              "pullrequesturl"
              "repository"
              "revision"
              "scheduler"
              "status_name"
              "system"
              "virtual_builder_name"
              "virtual_builder_tags"
              "workername"
            ] (name: self.inputs.buildbot-nix.lib.interpolate "%(prop:${name})s");

this list is just copied and pasted from the properties i saw on the web UI, and surely diverges for other forges and maybe even other projects on github. having a machine-readable way at runtime with all available properties would be nice.

Mic92 commented 1 month ago

Can this not be provided by the writer of postBuildSteps as needed? Maybe documenting known portable ones would be a nice addition to documentation.

Mic92 commented 1 month ago

The variable that you posted, can you explain how this is going to be used in the actual post hook?

steveej commented 1 month ago

in this case i experimented with exposing these values as environment variables

   postBuildSteps = [
      {
        name = "post-build-step-test";
        environment =
          let
            props = lib.attrsets.genAttrs [
              "attr"
              "basename"
              # ...
            ] (name: self.inputs.buildbot-nix.lib.interpolate "%(prop:${name})s");
            props' = lib.attrsets.mapAttrs' (name: value: lib.nameValuePair "PROP_${name}" value) props;
          in
          props';

however, a preferred alternative that could be to write a single structured file (e.g. json or toml) that's discoverable via a single environment variable. this file could also include other namespaced information such as %(secret:..)s, %(kw:...)s, etc..

MagicRB commented 1 month ago

This is more to be done from the python side. As in we can by default expose all properties as environment variables or make it togglable per PBS (postbuildstep)