Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use yaml-rust2 to get line numbers for better errors #248

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading