Skip to content

Commit

Permalink
Merge pull request #1604 from axodotdev/gh1440
Browse files Browse the repository at this point in the history
Migrate deserialize_yaml() to axoasset.
  • Loading branch information
duckinator authored Dec 5, 2024
2 parents 09ee140 + 546de77 commit 7dd0f7f
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 48 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ axoproject = { version = "=0.26.0-prerelease.3", path = "axoproject", default-fe
axocli = { version = "0.2.0" }
axoupdater = { version = "0.8.1" }
axotag = "0.2.0"
axoasset = { version = "1.0.1", features = ["json-serde", "toml-serde", "toml-edit", "compression", "remote"] }
axoasset = { version = "1.1.0", features = ["json-serde", "toml-serde", "toml-edit", "yaml-serde", "compression", "remote"] }
axoprocess = { version = "0.2.0" }
gazenot = { version = "0.3.3" }

Expand Down Expand Up @@ -63,7 +63,6 @@ pathdiff = { version = "0.2.3", features = ["camino"] }
url = "2.5.4"
parse-changelog = "0.6.10"
schemars = "0.8.21"
serde_yml = "0.0.10"
spdx = "0.10.7"
base64 = "0.22.1"
lazy_static = "1.5.0"
Expand Down
1 change: 0 additions & 1 deletion cargo-dist/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ tokio.workspace = true
temp-dir.workspace = true
sha3.workspace = true
blake2.workspace = true
serde_yml.workspace = true
spdx.workspace = true
base64.workspace = true
lazy_static.workspace = true
Expand Down
24 changes: 3 additions & 21 deletions cargo-dist/src/backend/ci/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -886,8 +886,9 @@ impl GithubJobStepsBuilder {
let path = base_path.as_ref().join(cfg_value.as_ref());
let src = SourceFile::load_local(&path)
.map_err(|e| DistError::GithubBuildSetupNotFound { details: e })?;
let steps =
deserialize_yaml(&src).map_err(|e| DistError::GithubBuildSetupParse { details: e })?;
let steps = src
.deserialize_yaml()
.map_err(|e| DistError::GithubBuildSetupParse { details: e })?;
Ok(Self { steps, path })
}

Expand Down Expand Up @@ -983,25 +984,6 @@ impl GithubJobStepsBuilder {
}
}

/// Try to deserialize the contents of the SourceFile as yaml
///
/// FIXME: upstream to axoasset
fn deserialize_yaml<'a, T: for<'de> serde::Deserialize<'de>>(
src: &'a SourceFile,
) -> Result<T, crate::errors::AxoassetYamlError> {
let yaml = serde_yml::from_str(src.contents()).map_err(|details| {
let span = details
.location()
.and_then(|location| src.span_for_line_col(location.line(), location.column()));
crate::errors::AxoassetYamlError {
source: src.clone(),
span,
details,
}
})?;
Ok(yaml)
}

#[cfg(test)]
mod tests {
use serde_json::Value;
Expand Down
22 changes: 1 addition & 21 deletions cargo-dist/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ pub enum DistError {
#[diagnostic(transparent)]
AxotagError(#[from] axotag::errors::TagError),

/// Failure to deserialize yml
#[error(transparent)]
SerdeYml(#[from] serde_yml::Error),

/// random parseint error
#[error(transparent)]
ParseIntError(#[from] std::num::ParseIntError),
Expand Down Expand Up @@ -479,7 +475,7 @@ pub enum DistError {
GithubBuildSetupParse {
/// Inner parse error with path and spans
#[diagnostic_source]
details: AxoassetYamlError,
details: axoasset::AxoassetError,
},

/// github-build-setup file contents are invalid
Expand Down Expand Up @@ -613,22 +609,6 @@ pub enum DistError {
},
}

/// This error indicates we tried to deserialize some YAML with serde_yml
/// but failed.
#[derive(Debug, Error, Diagnostic)]
#[error("failed to parse YAML")]
pub struct AxoassetYamlError {
/// The SourceFile we were try to parse
#[source_code]
pub source: axoasset::SourceFile,
/// The range the error was found on
#[label]
pub span: Option<miette::SourceSpan>,
/// Details of the error
#[source]
pub details: serde_yml::Error,
}

impl From<minijinja::Error> for DistError {
fn from(details: minijinja::Error) -> Self {
let source: String = details.template_source().unwrap_or_default().to_owned();
Expand Down

0 comments on commit 7dd0f7f

Please sign in to comment.