Skip to content

Commit

Permalink
feat: Use yaml-rust2 to get line numbers for better errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gmpinder committed Nov 4, 2024
1 parent 86b7cc5 commit b6dd19d
Show file tree
Hide file tree
Showing 14 changed files with 929 additions and 220 deletions.
63 changes: 60 additions & 3 deletions Cargo.lock

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

11 changes: 10 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ rstest = "0.18"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
serde_yaml = { version = "0.0.12", package = "serde_yml" }
syntect = { version = "5", default-features = false, features = ["default-fancy"] }
tempdir = "0.3"
tokio = { version = "1", features = ["rt", "rt-multi-thread"] }
users = "0.11"
Expand Down Expand Up @@ -71,22 +72,25 @@ jsonschema = { version = "0.26", optional = true }
open = "5"
os_info = "3"
rayon = { version = "1.10.0", optional = true }
regex = { version = "1", optional = true }
requestty = { version = "0.5", features = ["macros", "termion"] }
shadow-rs = { version = "0.26", default-features = false }
urlencoding = "2"
yaml-rust2 = { version = "0.9.0", optional = true }

cached.workspace = true
clap = { workspace = true, features = ["derive", "cargo", "unicode", "env"] }
colored.workspace = true
indexmap.workspace = true
indicatif.workspace = true
log.workspace = true
miette = { workspace = true, features = ["fancy"] }
miette = { workspace = true, features = ["fancy", "syntect-highlighter"] }
oci-distribution.workspace = true
reqwest.workspace = true
serde.workspace = true
serde_json.workspace = true
serde_yaml.workspace = true
syntect = { workspace = true, optional = true }
tempdir.workspace = true
tokio = { workspace = true, optional = true }
bon.workspace = true
Expand All @@ -105,13 +109,18 @@ validate = [
"dep:jsonschema",
"dep:rayon",
"dep:tokio",
"dep:yaml-rust2",
"dep:syntect",
"dep:regex",
"cached/async",
"blue-build-process-management/validate"
]

[dev-dependencies]
rusty-hook = "0.11"

rstest.workspace = true

[build-dependencies]
shadow-rs = { version = "0.26", default-features = false }

Expand Down
4 changes: 2 additions & 2 deletions bacon.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ command = [
]
need_stdout = true
default_watch = false
watch = ["src", "process", "recipe", "template", "utils", "Cargo.toml", "build.rs", "test-files"]
watch = ["src", "process", "recipe", "template", "utils", "Cargo.toml", "build.rs", "test-files", "integration-tests"]

[jobs.test-all]
command = [
Expand All @@ -54,7 +54,7 @@ command = [
]
need_stdout = true
default_watch = false
watch = ["src", "process", "recipe", "template", "utils", "Cargo.toml", "build.rs", "test-files"]
watch = ["src", "process", "recipe", "template", "utils", "Cargo.toml", "build.rs", "test-files", "integration-tests"]

[jobs.doc]
command = ["cargo", "doc", "--color", "always", "--no-deps"]
Expand Down
1 change: 1 addition & 0 deletions integration-tests/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ validate:
RUN --no-cache bluebuild -v validate recipes/recipe-invalid.yml && exit 1 || exit 0
RUN --no-cache bluebuild -v validate recipes/recipe-invalid-module.yml && exit 1 || exit 0
RUN --no-cache bluebuild -v validate recipes/recipe-invalid-stage.yml && exit 1 || exit 0
RUN --no-cache bluebuild -v validate recipes/recipe-invalid-from-file.yml && exit 1 || exit 0

legacy-base:
FROM ../+blue-build-cli-alpine --RELEASE=false
Expand Down
7 changes: 7 additions & 0 deletions integration-tests/test-repo/recipes/invalid-module.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
# yaml-language-server: $schema=https://schema.blue-build.org/module-list-v1.json
modules:
# Tests installing rpms from a combo image stage
- type: akmods
install: openrazer

37 changes: 37 additions & 0 deletions integration-tests/test-repo/recipes/invalid-stages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
# yaml-language-server: $schema=https://schema.blue-build.org/module-stage-list-v1.json
stages:
- name: ubuntu-test
from:
- ubuntu
modules: {}
- name: debian-test
from: debian
modules:
- from-file: stages.yml
- name: fedora-test
from: fedora
modules:
- from-file: stages.yml
- name: alpine-test
from: alpine
modules:
- from-file: stages.yml
modules:
- type: files
files:
- usr: /usr
- type: script
scripts:
- example.sh
snippets:
- echo "test" > /test.txt
- type: test-module
source: local
- type: containerfile
containerfiles:
- labels
snippets:
- RUN echo "This is a snippet"
- type: rpm-ostree
install: micro
58 changes: 58 additions & 0 deletions integration-tests/test-repo/recipes/recipe-invalid-from-file.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
# yaml-language-server: $schema=https://schema.blue-build.org/recipe-v1.json
name: cli/test
description: This is my personal OS image.
base-image: ghcr.io/ublue-os/silverblue-main
image-version: 40
stages:
- from-file: invalid-stages.yml
modules:
- from-file: invalid-module.yml
- from-file: flatpaks.yml

- type: files
files:
- source: usr
destination: /usr

- type: script
scripts:
- example.sh

- type: rpm-ostree
repos:
- https://copr.fedorainfracloud.org/coprs/atim/starship/repo/fedora-%OS_VERSION%/atim-starship-fedora-%OS_VERSION%.repo
install:
- micro
- starship
remove:
- firefox
- firefox-langpacks

- type: signing

- type: test-module
source: local

- type: containerfile
containerfiles:
- labels
snippets:
- RUN echo "This is a snippet" && ostree container commit

- type: copy
from: alpine-test
src: /test.txt
dest: /
- type: copy
from: ubuntu-test
src: /test.txt
dest: /
- type: copy
from: debian-test
src: /test.txt
dest: /
- type: copy
from: fedora-test
src: /test.txt
dest: /
4 changes: 4 additions & 0 deletions recipe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ pub trait FromFileList {
const LIST_KEY: &str;

fn get_from_file_paths(&self) -> Vec<PathBuf>;

fn get_module_from_file_paths(&self) -> Vec<PathBuf> {
Vec::new()
}
}

pub(crate) fn base_recipe_path() -> &'static Path {
Expand Down
12 changes: 12 additions & 0 deletions recipe/src/stages_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ impl FromFileList for StagesExt<'_> {
.filter_map(Stage::get_from_file_path)
.collect()
}

fn get_module_from_file_paths(&self) -> Vec<PathBuf> {
self.stages
.iter()
.flat_map(|stage| {
stage
.required_fields
.as_ref()
.map_or_else(Vec::new, |rf| rf.modules_ext.get_from_file_paths())
})
.collect()
}
}

impl TryFrom<&PathBuf> for StagesExt<'_> {
Expand Down
Loading

0 comments on commit b6dd19d

Please sign in to comment.