summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2023-06-27 01:48:16 -0700
committeriximeow <me@iximeow.net>2023-06-27 01:48:16 -0700
commit3b311571c92da4be6908c7b7d32b1b46b7224926 (patch)
tree285617f5ead506a03f067912d875d74ad4d61921 /src
parent55ed9f337ae0cf8e1336448d6b4273b3ee31aca2 (diff)
[driver] basic tools to track steps as reported by runners
Diffstat (limited to 'src')
-rw-r--r--src/ci_runner.rs30
-rw-r--r--src/lua/mod.rs47
2 files changed, 77 insertions, 0 deletions
diff --git a/src/ci_runner.rs b/src/ci_runner.rs
index f78fdbc..a83866d 100644
--- a/src/ci_runner.rs
+++ b/src/ci_runner.rs
@@ -44,6 +44,7 @@ impl RequestedJob {
RunningJob {
job: self,
client,
+ current_step: StepTracker::new(),
}
}
}
@@ -75,6 +76,35 @@ impl JobEnv {
pub struct RunningJob {
job: RequestedJob,
client: RunnerClient,
+ current_step: StepTracker,
+}
+
+pub struct StepTracker {
+ scopes: Vec<String>
+}
+
+impl StepTracker {
+ pub fn new() -> Self {
+ StepTracker {
+ scopes: Vec::new()
+ }
+ }
+
+ pub fn push(&mut self, name: String) {
+ self.scopes.push(name);
+ }
+
+ pub fn pop(&mut self) {
+ self.scopes.pop();
+ }
+
+ pub fn clear(&mut self) {
+ self.scopes.clear();
+ }
+
+ pub fn full_step_path(&self) -> &[String] {
+ self.scopes.as_slice()
+ }
}
impl RunningJob {
diff --git a/src/lua/mod.rs b/src/lua/mod.rs
index 53473cf..c76afa6 100644
--- a/src/lua/mod.rs
+++ b/src/lua/mod.rs
@@ -177,6 +177,31 @@ mod lua_exports {
.map_err(|e| LuaError::RuntimeError(format!("could not stat {:?}", path)))?
.len())
}
+
+ pub mod step {
+ use crate::RunningJob;
+ use std::sync::{Arc, Mutex};
+
+ pub fn start(job_ref: Arc<Mutex<RunningJob>>, name: String) -> Result<(), rlua::Error> {
+ let mut job = job_ref.lock().unwrap();
+ job.current_step.clear();
+ job.current_step.push(name);
+ Ok(())
+ }
+
+ pub fn push(job_ref: Arc<Mutex<RunningJob>>, name: String) -> Result<(), rlua::Error> {
+ let mut job = job_ref.lock().unwrap();
+ job.current_step.push(name);
+ Ok(())
+ }
+
+ pub fn advance(job_ref: Arc<Mutex<RunningJob>>, name: String) -> Result<(), rlua::Error> {
+ let mut job = job_ref.lock().unwrap();
+ job.current_step.pop();
+ job.current_step.push(name);
+ Ok(())
+ }
+ }
}
struct DeclEnv<'lua, 'env> {
@@ -268,6 +293,28 @@ impl BuildEnv {
build_functions.set("environment", build_environment).unwrap();
let globals = lua_ctx.globals();
globals.set("Build", build_functions).unwrap();
+
+
+ let step_start = decl_env.create_function("step_start", move |_, job_ref, name: String| {
+ lua_exports::step::start(job_ref, name)
+ })?;
+
+ let step_push = decl_env.create_function("step_push", move |_, job_ref, name: String| {
+ lua_exports::step::push(job_ref, name)
+ })?;
+
+ let step_advance = decl_env.create_function("step_advance", move |_, job_ref, name: String| {
+ lua_exports::step::advance(job_ref, name)
+ })?;
+
+ let step_functions = lua_ctx.create_table_from(
+ vec![
+ ("start", step_start),
+ ("push", step_push),
+ ("advance", step_advance),
+ ]
+ ).unwrap();
+ globals.set("Step", step_functions).unwrap();
Ok(())
}