Skip to content

Commit

Permalink
(wip) refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
pnmadelaine committed Sep 29, 2023
1 parent 71cd950 commit 32a6582
Show file tree
Hide file tree
Showing 26 changed files with 420 additions and 399 deletions.
10 changes: 5 additions & 5 deletions doc/src/concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ are four actions a project can define.
of your repository. These flakes must expose a `typhonJobs` attribute, that in
turn declares jobs for you project.

- The `begin` and `end` actions are run at the beginning and end of all jobs of
your project. They are typically used to set statuses on your repository, but
can also be used for deployment.
- The `pre` and `post` actions are run before and after all jobs of your
project. They are typically used to set statuses on your repository, but can
also be used for deployment.

- The `webhook` action is triggered by calls to a specific endpoint of the API.
It outputs commands for Typhon to update jobsets or evaluate a jobset. It is
Expand All @@ -51,5 +51,5 @@ is evaluated and the corresponding derivations are built.

## Jobs

Jobs are derivations defined in `typhonJobs`. A job run consists of the `begin`
action, the derivation build, and the `end` action.
Jobs are derivations defined in `typhonJobs`. A job run consists of the `pre`
action, the derivation build, and the `post` action.
88 changes: 87 additions & 1 deletion flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
flake-utils.follows = "flake-utils";
};
};

nix.url = "github:nixos/nix";
};

outputs = inputs: import ./nix/outputs.nix {sources = inputs;};
Expand Down
1 change: 1 addition & 0 deletions nix/devshells.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ in rec {
;
};
DATABASE_URL = "sqlite:typhon.sqlite";
TYPHON_FLAKE = ../typhon-flake;
};

webapp = pkgs.mkShell {
Expand Down
4 changes: 2 additions & 2 deletions nix/lib/github/mkGithubProject.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ in {
meta = {inherit title description homepage;};
actions = {
jobsets = mkGithubJobsets {inherit owner repo;};
begin = mkGithubStatus {inherit owner repo;};
end = mkGithubStatus {inherit owner repo;};
pre = mkGithubStatus {inherit owner repo;};
post = mkGithubStatus {inherit owner repo;};
webhook = githubWebhook;
};
inherit secrets;
Expand Down
4 changes: 2 additions & 2 deletions nix/lib/mkProject.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ in {
mkdir $out
cd $out
${linkAction "jobsets"}
${linkAction "begin"}
${linkAction "end"}
${linkAction "pre"}
${linkAction "post"}
${linkAction "webhook"}
${linkSecrets}
''
Expand Down
5 changes: 4 additions & 1 deletion nix/nixpkgs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
}:
import sources.nixpkgs {
inherit system;
overlays = [(import sources.rust-overlay)];
overlays = [
(import sources.rust-overlay)
sources.nix.overlays.default
];
}
1 change: 1 addition & 0 deletions nix/packages/server.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ in
cargoArtifacts
;
buildInputs = [pkgs.sqlite.dev];
TYPHON_FLAKE = ../../typhon-flake;
}
12 changes: 12 additions & 0 deletions typhon-flake/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
inputs = {
input = {
url = "";
flake = false;
};
};
outputs = {
self,
input,
}: {};
}
65 changes: 22 additions & 43 deletions typhon-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,10 @@ pub mod handles {
pub job: String,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Build {
pub build_hash: String,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum Log {
Evaluation(Evaluation),
JobBegin(Job),
JobEnd(Job),
JobPre(Job),
JobPost(Job),
}

macro_rules! impl_display {
Expand Down Expand Up @@ -75,27 +71,21 @@ pub mod handles {
[x.evaluation.into(), vec![x.job]].concat()
}
}
impl_display!(Build);
impl From<Build> for Vec<String> {
fn from(x: Build) -> Self {
vec![x.build_hash]
}
}
impl_display!(Log);
impl From<Log> for Vec<String> {
fn from(x: Log) -> Self {
use Log::*;
vec![
match x {
Evaluation(_) => "evaluation",
JobBegin(_) => "job_begin",
JobEnd(_) => "job_end",
JobPre(_) => "job_begin",
JobPost(_) => "job_end",
}
.into(),
match x {
Evaluation(h) => h.to_string(),
JobBegin(h) => h.to_string(),
JobEnd(h) => h.to_string(),
JobPre(h) => h.to_string(),
JobPost(h) => h.to_string(),
},
]
}
Expand Down Expand Up @@ -123,9 +113,6 @@ pub mod handles {
job,
}
}
pub fn build(build_hash: String) -> Build {
Build { build_hash }
}

#[macro_export]
macro_rules! pattern {
Expand Down Expand Up @@ -186,15 +173,8 @@ pub mod requests {
pub enum Job {
Cancel,
Info,
LogBegin,
LogEnd,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum Build {
Cancel,
Info,
NixLog,
LogPre,
LogPost,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
Expand All @@ -208,7 +188,6 @@ pub mod requests {
Jobset(handles::Jobset, Jobset),
Evaluation(handles::Evaluation, Evaluation),
Job(handles::Job, Job),
Build(handles::Build, Build),
Login(String),
}

Expand All @@ -223,7 +202,6 @@ pub mod requests {
Request::Jobset(h, req) => write!(f, "{:?} for jobset {}", req, h),
Request::Evaluation(h, req) => write!(f, "{:?} for evaluation {}", req, h),
Request::Job(h, req) => write!(f, "{:?} for job {}", req, h),
Request::Build(h, req) => write!(f, "{:?} for build {}", req, h),
Request::Login(_) => write!(f, "Log in"),
}
}
Expand Down Expand Up @@ -264,24 +242,28 @@ pub mod responses {
pub actions_path: Option<String>,
pub flake_locked: String,
pub jobs: Vec<String>,
pub legacy: bool,
pub status: String,
pub time_created: i64,
pub time_finished: Option<i64>,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct JobInfo {
pub build_handle: super::handles::Build,
pub build_infos: BuildInfo,
pub build_drv: String,
pub build_out: String,
pub build_status: String,
pub build_time_finished: Option<i64>,
pub build_time_started: Option<i64>,
pub dist: bool,
pub status: String,
pub post_status: String,
pub post_time_finished: Option<i64>,
pub post_time_started: Option<i64>,
pub pre_status: String,
pub pre_time_finished: Option<i64>,
pub pre_time_started: Option<i64>,
pub system: String,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct BuildInfo {
pub drv: String,
pub out: String,
pub status: String,
pub time_created: i64,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
Expand All @@ -294,7 +276,6 @@ pub mod responses {
JobsetInfo(JobsetInfo),
EvaluationInfo(EvaluationInfo),
JobInfo(JobInfo),
BuildInfo(BuildInfo),
Log(String),
Login { token: String },
}
Expand Down Expand Up @@ -326,6 +307,4 @@ pub enum Event {
EvaluationNew(handles::Evaluation),
EvaluationFinished(handles::Evaluation),
JobUpdated(handles::Job),
BuildNew(handles::Build),
BuildFinished(handles::Build),
}
10 changes: 6 additions & 4 deletions typhon-webapp/src/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
);
}
Msg::GetInfo(info) => {
if info.status == "waiting" || info.status == "end" || info.status == "success" {
if info.actions_pre_status != "pending" {
orders.send_msg(Msg::FetchLogBegin);
}
if info.status == "success" {
if info.actions_post_status != "pending" {
orders.send_msg(Msg::FetchLogEnd);
}
let drv = info.build_infos.drv.clone();
let drv = info.build_drv.clone();
orders
.proxy(Msg::LogLine)
.stream(fetch_logs_as_stream(drv.into()));
Expand Down Expand Up @@ -215,7 +215,9 @@ fn view_job(model: &Model) -> Node<Msg> {
},
]
],
p![format!("Status: {}", info.status)],
p![format!("Status (pre): {}", info.actions_pre_status)],
p![format!("Status (build): {}", info.build_status)],
p![format!("Status (post): {}", info.actions_post_status)],
if info.dist {
let api_url = SETTINGS.get().unwrap().api_server.url(false);
let job = &model.handle.job;
Expand Down
1 change: 0 additions & 1 deletion typhon/migrations/00000000000000_typhon/down.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ DROP TABLE projects;
DROP TABLE jobsets;
DROP TABLE evaluations;
DROP TABLE jobs;
DROP TABLE builds;
DROP TABLE logs;
Loading

0 comments on commit 32a6582

Please sign in to comment.