Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
pnmadelaine committed Sep 29, 2023
1 parent 71cd950 commit 83276f3
Show file tree
Hide file tree
Showing 34 changed files with 649 additions and 710 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
6 changes: 6 additions & 0 deletions nix/jobs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
sources ? import ./sources.nix,
systems ? ["x86_64-linux"],
lib ? sources.nixpkgs.lib,
}:
lib.genAttrs systems (system: import ./checks {inherit sources system;})
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;
}
7 changes: 7 additions & 0 deletions typhon-flake/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
inputs.x.flake = false;
outputs = {x, ...}: {
typhonJobs = if builtins.pathExists "${x}/nix/jobs.nix" then import "${x}/nix/jobs.nix" {} else null;
typhonProject = if builtins.pathExists "${x}/nix/typhon.nix" then import "${x}/nix/typhon.nix" {} else null;
};
}
82 changes: 34 additions & 48 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",
JobPost(_) => "job_post",
JobPre(_) => "job_pre",
}
.into(),
match x {
Evaluation(h) => h.to_string(),
JobBegin(h) => h.to_string(),
JobEnd(h) => h.to_string(),
JobPost(h) => h.to_string(),
JobPre(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 @@ -159,12 +146,18 @@ pub mod requests {
use crate::handles;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct ProjectDecl {
pub flake_url: String,
pub legacy: bool,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum Project {
Delete,
Info,
Refresh,
SetDecl(String),
SetDecl(ProjectDecl),
SetPrivateKey(String),
UpdateJobsets,
}
Expand All @@ -186,15 +179,8 @@ pub mod requests {
pub enum Job {
Cancel,
Info,
LogBegin,
LogEnd,
}

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

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
Expand All @@ -208,7 +194,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 +208,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 All @@ -246,42 +230,47 @@ pub mod responses {
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct ProjectInfo {
pub actions_path: Option<String>,
pub decl: String,
pub decl_locked: String,
pub flake_url: String,
pub flake_url_locked: String,
pub jobsets: Vec<String>,
pub legacy: bool,
pub metadata: ProjectMetadata,
pub public_key: String,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct JobsetInfo {
pub evaluations: Vec<(i32, i64)>,
pub flake: String,
pub flake_url: String,
pub legacy: bool,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct EvaluationInfo {
pub actions_path: Option<String>,
pub flake_locked: String,
pub flake_url_locked: String,
pub jobs: Vec<String>,
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 +283,6 @@ pub mod responses {
JobsetInfo(JobsetInfo),
EvaluationInfo(EvaluationInfo),
JobInfo(JobInfo),
BuildInfo(BuildInfo),
Log(String),
Login { token: String },
}
Expand Down Expand Up @@ -326,6 +314,4 @@ pub enum Event {
EvaluationNew(handles::Evaluation),
EvaluationFinished(handles::Evaluation),
JobUpdated(handles::Job),
BuildNew(handles::Build),
BuildFinished(handles::Build),
}
Loading

0 comments on commit 83276f3

Please sign in to comment.