summaryrefslogtreecommitdiff
path: root/ci-runner/src
diff options
context:
space:
mode:
Diffstat (limited to 'ci-runner/src')
-rw-r--r--ci-runner/src/lua/mod.rs35
-rw-r--r--ci-runner/src/main.rs55
2 files changed, 44 insertions, 46 deletions
diff --git a/ci-runner/src/lua/mod.rs b/ci-runner/src/lua/mod.rs
index d05ad7d..2c1423b 100644
--- a/ci-runner/src/lua/mod.rs
+++ b/ci-runner/src/lua/mod.rs
@@ -1,10 +1,8 @@
-use crate::Runner;
use crate::RunningJob;
use rlua::prelude::*;
use std::sync::{Arc, Mutex};
-use std::path::PathBuf;
pub const DEFAULT_RUST_GOODFILE: &'static [u8] = include_bytes!("../../../config/goodfiles/rust.lua");
@@ -15,8 +13,8 @@ pub struct BuildEnv {
#[derive(Debug)]
pub struct RunParams {
- step: Option<String>,
- name: Option<String>,
+ _step: Option<String>,
+ _name: Option<String>,
cwd: Option<String>,
}
@@ -27,9 +25,8 @@ pub struct CommandOutput {
}
mod lua_exports {
- use crate::Runner;
use crate::RunningJob;
- use crate::lua::{CommandOutput, RunParams};
+ use crate::lua::RunParams;
use std::sync::{Arc, Mutex};
use std::path::PathBuf;
@@ -69,7 +66,7 @@ mod lua_exports {
LuaValue::Nil => {
None
},
- other => {
+ _other => {
return Err(LuaError::RuntimeError(format!("params[\"step\"] must be a string")));
}
};
@@ -80,7 +77,7 @@ mod lua_exports {
LuaValue::Nil => {
None
},
- other => {
+ _other => {
return Err(LuaError::RuntimeError(format!("params[\"name\"] must be a string")));
}
};
@@ -91,21 +88,21 @@ mod lua_exports {
LuaValue::Nil => {
None
},
- other => {
+ _other => {
return Err(LuaError::RuntimeError(format!("params[\"cwd\"] must be a string")));
}
};
RunParams {
- step,
- name,
+ _step: step,
+ _name: name,
cwd,
}
},
LuaValue::Nil => {
RunParams {
- step: None,
- name: None,
+ _step: None,
+ _name: None,
cwd: None,
}
}
@@ -227,7 +224,7 @@ mod lua_exports {
pub fn file_size(path: &str) -> Result<u64, rlua::Error> {
Ok(std::fs::metadata(&format!("tmpdir/{}", path))
- .map_err(|e| LuaError::RuntimeError(format!("could not stat {:?}", path)))?
+ .map_err(|_e| LuaError::RuntimeError(format!("could not stat {:?}", path)))?
.len())
}
@@ -300,7 +297,7 @@ impl BuildEnv {
Ok(())
})?;
- let check_dependencies = decl_env.create_function("dependencies", move |_, job_ref, commands: Vec<String>| {
+ let check_dependencies = decl_env.create_function("dependencies", move |_, _job_ref, commands: Vec<String>| {
lua_exports::check_dependencies(commands)
})?;
@@ -316,21 +313,21 @@ impl BuildEnv {
lua_exports::metric(name, value, job_ref)
})?;
- let now_ms = decl_env.create_function("now_ms", move |_, job_ref, ()| Ok(ci_lib_core::now_ms()))?;
+ let now_ms = decl_env.create_function("now_ms", move |_, _job_ref, ()| Ok(ci_lib_core::now_ms()))?;
let artifact = decl_env.create_function("artifact", move |_, job_ref, (path, name): (String, Option<String>)| {
lua_exports::artifact(path, name, job_ref)
})?;
- let error = decl_env.create_function("error", move |_, job_ref, msg: String| {
+ let error = decl_env.create_function("error", move |_, _job_ref, msg: String| {
Err::<(), LuaError>(LuaError::RuntimeError(format!("explicit error: {}", msg)))
})?;
- let path_has_cmd = decl_env.create_function("path_has_cmd", move |_, job_ref, name: String| {
+ let path_has_cmd = decl_env.create_function("path_has_cmd", move |_, _job_ref, name: String| {
lua_exports::has_cmd(&name)
})?;
- let size_of_file = decl_env.create_function("size_of_file", move |_, job_ref, name: String| {
+ let size_of_file = decl_env.create_function("size_of_file", move |_, _job_ref, name: String| {
lua_exports::file_size(&name)
})?;
diff --git a/ci-runner/src/main.rs b/ci-runner/src/main.rs
index f5941fa..6ed6538 100644
--- a/ci-runner/src/main.rs
+++ b/ci-runner/src/main.rs
@@ -6,14 +6,10 @@ use reqwest::{StatusCode, Response};
use tokio::process::Command;
use std::process::Stdio;
use std::process::ExitStatus;
-use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
-use serde_json::json;
+use tokio::io::AsyncWrite;
use serde::{Deserialize, de::DeserializeOwned, Serialize};
-use std::task::{Context, Poll};
-use std::pin::Pin;
use std::marker::Unpin;
-use std::future::Future;
-use std::path::{Path, PathBuf};
+use std::path::PathBuf;
use ci_lib_native::io;
use ci_lib_native::io::{ArtifactStream, VecSink};
@@ -23,6 +19,7 @@ mod lua;
use crate::lua::CommandOutput;
+#[allow(dead_code)]
#[derive(Debug)]
enum WorkAcquireError {
Reqwest(reqwest::Error),
@@ -43,6 +40,7 @@ trait Runner: Send + Sync + 'static {
async fn create_artifact(&self, name: &str, desc: &str, build_token: &str) -> Result<ArtifactStream, String>;
}
+#[allow(dead_code)]
struct LocalRunner {
working_dir: PathBuf,
current_job: Option<RequestedJob>,
@@ -68,7 +66,7 @@ impl Runner for LocalRunner {
println!("metric reported: {} = {}", name, value);
Ok(())
}
- async fn create_artifact(&self, name: &str, desc: &str, build_token: &str) -> Result<ArtifactStream, String> {
+ async fn create_artifact(&self, _name: &str, _desc: &str, _build_token: &str) -> Result<ArtifactStream, String> {
Err("can't create artifacts yet".to_string())
}
}
@@ -77,9 +75,11 @@ impl Runner for LocalRunner {
/// a task", including reporting metrics and statuses back to the CI server.
struct RemoteServerRunner {
http: reqwest::Client,
+ #[allow(dead_code)]
host: String,
tx: hyper::body::Sender,
rx: Response,
+ #[allow(dead_code)]
current_job: Option<RequestedJob>,
}
@@ -103,7 +103,7 @@ impl Runner for RemoteServerRunner {
.map_err(|e| format!("failed to send metric {}: {:?})", name, e))
}
async fn create_artifact(&self, name: &str, desc: &str, build_token: &str) -> Result<ArtifactStream, String> {
- let (mut sender, body) = hyper::Body::channel();
+ let (sender, body) = hyper::Body::channel();
let resp = self.http.post("https://ci.butactuallyin.space:9876/api/artifact")
.header("user-agent", "ci-butactuallyin-space-runner")
.header("x-task-token", build_token)
@@ -147,6 +147,7 @@ impl RunningJob {
struct JobEnv {
lua: lua::BuildEnv,
+ #[allow(dead_code)]
job: Arc<Mutex<Box<RunningJob>>>,
}
@@ -175,6 +176,7 @@ pub struct RunningJob {
current_step: StepTracker,
}
+#[allow(dead_code)]
enum RepoError {
CloneFailedIdk { exit_code: ExitStatus },
CheckoutFailedIdk { exit_code: ExitStatus },
@@ -259,7 +261,7 @@ impl RunningJob {
Ok(())
}
- async fn execute_command_and_report(&self, mut command: Command, name: &str, desc: &str) -> Result<ExitStatus, String> {
+ async fn execute_command_and_report(&self, command: Command, name: &str, desc: &str) -> Result<ExitStatus, String> {
let stdout_artifact = self.create_artifact(
&format!("{} (stdout)", name),
&format!("{} (stdout)", desc)
@@ -274,7 +276,7 @@ impl RunningJob {
Ok(exit_status)
}
- async fn execute_command_capture_output(&self, mut command: Command, name: &str, desc: &str) -> Result<crate::lua::CommandOutput, String> {
+ async fn execute_command_capture_output(&self, command: Command, name: &str, desc: &str) -> Result<crate::lua::CommandOutput, String> {
let stdout_collector = VecSink::new();
let stderr_collector = VecSink::new();
@@ -287,7 +289,7 @@ impl RunningJob {
})
}
- async fn execute_command(&self, mut command: Command, name: &str, desc: &str, mut stdout_reporter: impl AsyncWrite + Unpin + Send + 'static, mut stderr_reporter: impl AsyncWrite + Unpin + Send + 'static) -> Result<ExitStatus, String> {
+ async fn execute_command(&self, mut command: Command, name: &str, _desc: &str, mut stdout_reporter: impl AsyncWrite + Unpin + Send + 'static, mut stderr_reporter: impl AsyncWrite + Unpin + Send + 'static) -> Result<ExitStatus, String> {
eprintln!("[.] running {}", name);
let mut child = command
@@ -327,7 +329,7 @@ impl RunningJob {
let checkout_res = ctx.lock().unwrap().clone_remote().await;
- if let Err(e) = checkout_res {
+ if let Err(_e) = checkout_res {
let status = "bad_ref";
let status = TaskInfo::finished(status);
eprintln!("checkout failed, reporting status: {:?}", status);
@@ -444,7 +446,7 @@ impl RunningJob {
}
impl RemoteServerRunner {
- async fn new(host: &str, mut sender: hyper::body::Sender, mut res: Response) -> Result<Self, String> {
+ async fn new(host: &str, sender: hyper::body::Sender, mut res: Response) -> Result<Self, String> {
if res.status() != StatusCode::OK {
return Err(format!("server returned a bad response: {:?}, response itself: {:?}", res.status(), res));
}
@@ -467,11 +469,18 @@ impl RemoteServerRunner {
})
}
- async fn wait_for_work(&mut self, accepted_pushers: Option<&[String]>) -> Result<Option<RequestedJob>, WorkAcquireError> {
+ async fn wait_for_work(&mut self, _accepted_pushers: Option<&[String]>) -> Result<Option<RequestedJob>, WorkAcquireError> {
loop {
let message = self.recv_typed::<ClientProto>().await;
match message {
Ok(Some(ClientProto::NewTask(new_task))) => {
+ // TODO: verify that `new_task` is for a commit authored by someone we're
+ // willing to run work for.
+ //
+ // we're also trusting the server to only tell us about work we would be
+ // interested in running, so if this rejects a task it's a server bug that we
+ // got the task in the first place or a client bug that the list of accepted
+ // pushers varied.
return Ok(Some(new_task));
},
Ok(Some(ClientProto::Ping)) => {
@@ -491,10 +500,6 @@ impl RemoteServerRunner {
}
}
- async fn recv(&mut self) -> Result<Option<serde_json::Value>, String> {
- self.recv_typed().await
- }
-
async fn recv_typed<T: DeserializeOwned>(&mut self) -> Result<Option<T>, String> {
match self.rx.chunk().await {
Ok(Some(chunk)) => {
@@ -511,10 +516,6 @@ impl RemoteServerRunner {
}
}
- async fn send(&mut self, value: serde_json::Value) -> Result<(), String> {
- self.send_typed(&value).await
- }
-
async fn send_typed<T: Serialize>(&mut self, t: &T) -> Result<(), String> {
self.tx.send_data(
serde_json::to_vec(t)
@@ -546,13 +547,13 @@ async fn main() {
}
}
-async fn run_local(config_path: String) {
+async fn run_local(_config_path: String) {
let job = RequestedJob {
commit: "current commit?".to_string(),
remote_url: "cwd?".to_string(),
build_token: "n/a".to_string(),
};
- let mut job = RunningJob::local_from_job(job);
+ let job = RunningJob::local_from_job(job);
job.run().await;
}
@@ -583,7 +584,7 @@ async fn run_remote(config_path: String) {
.await;
match poll {
- Ok(mut res) => {
+ Ok(res) => {
let mut client = match RemoteServerRunner::new("ci.butactuallyin.space:9876", sender, res).await {
Ok(client) => client,
Err(e) => {
@@ -609,7 +610,7 @@ async fn run_remote(config_path: String) {
eprintln!("doing {:?}", job);
- let mut job = RunningJob::remote_from_job(job, client);
+ let job = RunningJob::remote_from_job(job, client);
job.run().await;
std::thread::sleep(Duration::from_millis(10000));
},
@@ -657,7 +658,7 @@ mod host_info {
let cpu_mhzes: Vec<&String> = cpu_lines.iter().filter(|line| line.starts_with("cpu MHz")).collect();
match cpu_mhzes.get(cpu as usize) {
Some(mhz) => {
- let mut line_parts = cpu_mhzes[cpu as usize].split(":");
+ let mut line_parts = mhz.split(":");
let _ = line_parts.next();
let mhz = line_parts.next().unwrap().trim();
let mhz: f64 = mhz.parse().unwrap();