Skip to content

Commit

Permalink
Support the new buildpack.toml description, keywords and `license…
Browse files Browse the repository at this point in the history
…s` fields

In order to support Buildpack API 0.6, we need to handle the new `buildpack.toml`
fields `description`, `keywords` and `licenses`:
https://github.com/buildpacks/spec/blob/buildpack/0.6/buildpack.md#buildpacktoml-toml

See:
https://github.com/buildpacks/rfcs/blob/main/text/0070-new-buildpack-toml-keys.md

Closes #100.
GUS-W-10023681.
  • Loading branch information
edmorley committed Oct 28, 2021
1 parent dba0793 commit 54bfde0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [Unreleased]

- Support the new `buildpack.toml` fields `description`, `keywords` and `licenses`
- Set a minumim required Rust version of 1.56 and switch to the 2021 Rust edition
- Stack id in `buildpack.toml` can now be `*` indicating "any" stack
- LayerContentMetadata values (build, cache, launch) are now under a "types" key
Expand Down
47 changes: 41 additions & 6 deletions src/data/buildpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ use thiserror;
/// version = "0.0.1"
/// homepage = "https://www.foo.com/bar"
/// clear-env = false
/// description = "A buildpack for Foo Bar"
/// keywords = ["foo"]
///
/// [[buildpack.licenses]]
/// type = "BSD-3-Clause"
///
/// [[stacks]]
/// id = "io.buildpacks.stacks.bionic"
Expand Down Expand Up @@ -56,6 +61,17 @@ pub struct Buildpack {
#[serde(rename = "clear-env")]
#[serde(default = "defaults::r#false")]
pub clear_env: bool,
pub description: Option<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub keywords: Vec<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub licenses: Vec<License>,
}

#[derive(Deserialize, Debug)]
pub struct License {
pub r#type: Option<String>,
pub uri: Option<String>,
}

#[derive(Deserialize, Debug)]
Expand Down Expand Up @@ -305,7 +321,7 @@ mod tests {
}

#[test]
fn can_serialize_metabuildpack() {
fn can_deserialize_metabuildpack() {
let raw = r#"
api = "0.4"
Expand All @@ -314,7 +330,19 @@ id = "foo/bar"
name = "Bar Buildpack"
version = "0.0.1"
homepage = "https://www.foo.com/bar"
clear-env = false
clear-env = true
description = "A buildpack for Foo Bar"
keywords = ["foo", "bar"]
[[buildpack.licenses]]
type = "BSD-3-Clause"
[[buildpack.licenses]]
type = "Custom license with type and URI"
uri = "https://example.tld/my-license"
[[buildpack.licenses]]
uri = "https://example.tld/my-license"
[[order]]
[[order.group]]
Expand All @@ -331,12 +359,19 @@ checksum = "awesome"
"#;

let result = toml::from_str::<BuildpackToml<toml::value::Table>>(raw);
result.unwrap();
//assert!(result.is_ok());
assert!(result.is_ok());
if let Ok(toml) = result {
assert_eq!(
toml.buildpack.description.unwrap(),
"A buildpack for Foo Bar"
);
assert_eq!(toml.buildpack.keywords.len(), 2);
assert_eq!(toml.buildpack.licenses.len(), 3);
}
}

#[test]
fn can_serialize_minimal_buildpack() {
fn can_deserialize_minimal_buildpack() {
let raw = r#"
api = "0.4"
Expand All @@ -360,7 +395,7 @@ checksum = "awesome"
}

#[test]
fn can_serialize_minimal_metabuildpack() {
fn can_deserialize_minimal_metabuildpack() {
let raw = r#"
api = "0.4"
Expand Down

0 comments on commit 54bfde0

Please sign in to comment.