Radish alpha
r
Radicle CI broker
Radicle
Git (anonymous pull)
Log in to clone via SSH
test(ci-broker.md): verify event filter Node
Lars Wirzenius committed 1 year ago
commit 59deeed8c13b8eae054fdeb033266dce7c0775ef
parent 2ea38588ad1090db8a89a11ed8711c66ab2e2640
2 files changed +54 -1
modified ci-broker.md
@@ -788,11 +788,59 @@ dir="$1"
yaml="$2"

rid="$(cd "$dir" && rad .)"
-

sed -i "s/REPOID/$rid/g" "$yaml"
~~~


+
## Filter predicate `Node`
+

+
_Want:_ We can allow an event that originates in a given node.
+

+
_Why:_ We want to constrain CI to a specific developer.
+

+
~~~scenario
+
given a Radicle node, with CI configured with broker.yaml and adapter dummy.sh
+
given a Git repository xyzzy in the Radicle node
+
given a Git repository other in the Radicle node
+

+
given file config.yaml from filter-node.yaml
+
given file update-nodeid.sh
+
when I run bash update-nodeid.sh xyzzy config.yaml
+

+
when I run cibtool --db ci-broker.db trigger --repo xyzzy
+
when I run cibtool --db ci-broker.db trigger --repo other --node z6MkgEMYod7Hxfy9qCvDv5hYHkZ4ciWmLFgfvm3Wn1b2w2FV
+

+
when I run ./env.sh cib --config config.yaml queued
+

+
when I run cibtool --db ci-broker.db run list --json
+
then stdout contains ""repo_name": "xyzzy""
+
then stdout doesn't contain ""repo_name": "other""
+
~~~
+

+
~~~{#filter-node.yaml .file .json}
+
db: ci-broker.db
+
adapters:
+
  default:
+
    command: ./adapter.sh
+
triggers:
+
  - adapter: default
+
    filters:
+
      - !Node "NODEID"
+
~~~
+

+
~~~{#update-nodeid.sh .file .sh}
+
#!/bin/sh
+

+
set -eu
+

+
dir="$1"
+
yaml="$2"
+

+
rid="$(cd "$dir" && rad self --nid)"
+
sed -i "s/NODEID/$rid/g" "$yaml"
+
~~~
+

+

# Acceptance criteria for test tooling

The event synthesizer is a helper to feed the CI broker node events in
modified src/bin/cibtoolcmd/trigger.rs
@@ -3,6 +3,10 @@ use super::*;
/// Trigger a CI run.
#[derive(Parser)]
pub struct TriggerCmd {
+
    /// Set the node where the node originated from.
+
    #[clap(long)]
+
    node: Option<NodeId>,
+

    /// Set the repository the event refers to. Can be a RID, or the
    /// repository name.
    #[clap(long)]
@@ -28,6 +32,7 @@ impl Leaf for TriggerCmd {
    fn run(&self, args: &Args) -> Result<(), CibToolError> {
        let profile = util::load_profile()?;
        let nid = util::lookup_nid(&profile)?;
+
        let nid = self.node.unwrap_or(nid);
        let (rid, _repo_name) = util::lookup_repo(&profile, &self.repo)?;
        let oid = util::oid_from_cli_arg(&profile, rid, &self.commit)?;