Skip to content

Commit

Permalink
Add support for building only on a single system
Browse files Browse the repository at this point in the history
  • Loading branch information
hesiod committed Apr 12, 2023
1 parent 0f34038 commit 740fe9a
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 2 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ the Nixpkgs checkout (see also "[How does ofborg call
Builds will run on all allowed machines. For more information, see the "[Trusted
Users](#trusted-users)" section.

### build_system

```
@ofborg build_system SYSTEM list of attrs
```

Same as [build](#build), but restricts building to only one platform specification
instead of attempting to build on all allowed and supported systems.
This can be helpful to reduce needless builds and noise when debugging a platform-specific issue.

Only the currently supported Nixpkgs systems can be passed to `build_system`:
`x86_64-linux`, `aarch64-linux`, `x86_64-darwin`, and `aarch64-darwin`.

## Multiple Commands

You can use multiple commands in a variety ways. Here are some valid
Expand Down
38 changes: 37 additions & 1 deletion ofborg/src/commentparser.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::systems::System;
use nom::types::CompleteStr;
use tracing::warn;

Expand All @@ -24,18 +25,35 @@ named!(
|s: CompleteStr| !s.0.eq_ignore_ascii_case("@grahamcofborg")
)
);

named!(
system(CompleteStr) -> System,
alt!(
do_parse!(tag!("x86_64-linux") >> (System::X8664Linux)) |
do_parse!(tag!("aarch64-linux") >> (System::Aarch64Linux)) |
do_parse!(tag!("x86_64-darwin") >> (System::X8664Darwin)) |
do_parse!(tag!("aarch64-darwin") >> (System::Aarch64Darwin))
)
);

named!(
parse_line_impl(CompleteStr) -> Option<Vec<Instruction>>,
alt!(
do_parse!(
res: ws!(many1!(ws!(preceded!(
alt!(tag_no_case!("@grahamcofborg") | tag_no_case!("@ofborg")),
alt!(
ws!(do_parse!(
ws!(do_parse!(
tag!("build") >>
pkgs: ws!(many1!(map!(normal_token, |s| s.0.to_owned()))) >>
(Some(Instruction::Build(Subset::Nixpkgs, pkgs)))
)) |
ws!(do_parse!(
tag!("build_system") >>
system: ws!(map!(system, |s| s)) >>
pkgs: ws!(many1!(map!(normal_token, |s| s.0.to_owned()))) >>
(Some(Instruction::BuildOnSystem(system, Subset::Nixpkgs, pkgs)))
)) |
ws!(do_parse!(
tag!("test") >>
tests: ws!(many1!(map!(normal_token, |s| format!("nixosTests.{}", s.0)))) >>
Expand Down Expand Up @@ -68,6 +86,7 @@ pub fn parse_line(text: &str) -> Option<Vec<Instruction>> {
pub enum Instruction {
Build(Subset, Vec<String>),
Eval,
BuildOnSystem(System, Subset, Vec<String>),
}

#[allow(clippy::upper_case_acronyms)]
Expand Down Expand Up @@ -108,6 +127,23 @@ mod tests {
assert_eq!(None, parse("@grahamcofborg build"));
}

#[test]
fn build_system_comment() {
assert_eq!(
Some(vec![Instruction::BuildOnSystem(
System::X8664Linux,
Subset::Nixpkgs,
vec![String::from("foo")]
),]),
parse("@ofborg build_system x86_64-linux foo")
);
}

#[test]
fn unknown_system_comment() {
assert_eq!(None, parse("@ofborg build_system x86_64-foolinux foo"));
}

#[test]
fn eval_comment() {
assert_eq!(Some(vec![Instruction::Eval]), parse("@grahamcofborg eval"));
Expand Down
2 changes: 1 addition & 1 deletion ofborg/src/systems.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum System {
X8664Linux,
Aarch64Linux,
Expand Down
30 changes: 30 additions & 0 deletions ofborg/src/tasks/githubcommentfilter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,36 @@ impl worker::SimpleWorker for GitHubCommentWorker {
},
));
}
commentparser::Instruction::BuildOnSystem(system, subset, attrs) => {
if !build_destinations.contains(&system) {
continue;
};
if subset == commentparser::Subset::NixOS && !system.can_run_nixos_tests() {
continue;
};

let msg = buildjob::BuildJob::new(
repo_msg.clone(),
pr_msg.clone(),
subset,
attrs,
None,
None,
format!("{}", Uuid::new_v4()),
);

let (exchange, routingkey) = system.as_build_destination();
response.push(worker::publish_serde_action(exchange, routingkey, &msg));

response.push(worker::publish_serde_action(
Some("build-results".to_string()),
None,
&buildjob::QueuedBuildJobs {
job: msg,
architectures: vec![system.to_string()],
},
));
}
commentparser::Instruction::Eval => {
let msg = evaluationjob::EvaluationJob {
repo: repo_msg.clone(),
Expand Down

0 comments on commit 740fe9a

Please sign in to comment.