Skip to content

Commit

Permalink
Merge pull request #1238 from fibonacci1729/fix-spin-tomls
Browse files Browse the repository at this point in the history
chore: update examples and templates to spin_manifest_version
  • Loading branch information
fibonacci1729 authored Mar 8, 2023
2 parents 9095fe6 + 164e0a4 commit eaf8653
Show file tree
Hide file tree
Showing 32 changed files with 59 additions and 41 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/templates/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ regex = "1.5.4"
semver = "1.0"
serde = { version = "1.0", features = [ "derive" ] }
sha2 = "0.10.1"
spin-loader = { path = "../loader" }
tempfile = "3.3.0"
tokio = { version = "1.23", features = [ "fs", "process", "rt", "macros" ] }
toml = "0.5"
Expand Down
40 changes: 28 additions & 12 deletions crates/templates/src/app_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,36 @@
// interest to the template system. spin_loader does too
// much processing to fit our needs here.

use std::path::{Path, PathBuf};

use anyhow::Context;
use spin_loader::local::config::FixedStringVersion;
use std::path::{Path, PathBuf};

use crate::store::TemplateLayout;

#[derive(Debug, serde::Deserialize)]
#[serde(tag = "spin_version")]
#[serde(untagged)]
pub(crate) enum AppInfo {
/// A manifest with API version 1.
#[serde(rename = "1")]
V1(AppInfoV1),
V1Old {
#[allow(dead_code)]
spin_version: FixedStringVersion<1>,
#[serde(flatten)]
manifest: AppInfoV1,
},
V1New {
#[allow(dead_code)]
spin_manifest_version: FixedStringVersion<1>,
#[serde(flatten)]
manifest: AppInfoV1,
},
}

impl AppInfo {
pub fn as_v1(&self) -> &AppInfoV1 {
match self {
AppInfo::V1New { manifest, .. } => manifest,
AppInfo::V1Old { manifest, .. } => manifest,
}
}
}

#[derive(Debug, serde::Deserialize)]
Expand All @@ -28,12 +46,12 @@ pub(crate) struct TriggerInfo {
}

impl AppInfo {
pub(crate) fn from_layout(layout: &TemplateLayout) -> Option<anyhow::Result<AppInfo>> {
pub fn from_layout(layout: &TemplateLayout) -> Option<anyhow::Result<AppInfo>> {
Self::layout_manifest_path(layout)
.map(|manifest_path| Self::from_existent_file(&manifest_path))
}

pub(crate) fn from_file(manifest_path: &Path) -> Option<anyhow::Result<AppInfo>> {
pub fn from_file(manifest_path: &Path) -> Option<anyhow::Result<AppInfo>> {
if manifest_path.exists() {
Some(Self::from_existent_file(manifest_path))
} else {
Expand All @@ -56,9 +74,7 @@ impl AppInfo {
toml::from_str(&manifest_text).context("Can't parse manifest file")
}

pub(crate) fn trigger_type(&self) -> &str {
match self {
Self::V1(info) => &info.trigger.trigger_type,
}
pub fn trigger_type(&self) -> &str {
&self.as_v1().trigger.trigger_type
}
}
2 changes: 1 addition & 1 deletion examples/config-rust/spin.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spin_version = "1"
spin_manifest_version = "1"
authors = ["Fermyon Engineering <[email protected]>"]
description = "A Spin Rust application demonstrating the config sdk."
name = "spin-config-rust"
Expand Down
2 changes: 1 addition & 1 deletion examples/config-tinygo/spin.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spin_version = "1"
spin_manifest_version = "1"
authors = ["Fermyon Engineering <[email protected]>"]
description = "A simple Spin application written in (Tiny)Go."
name = "spin-config-tinygo"
Expand Down
2 changes: 1 addition & 1 deletion examples/http-cpp/spin.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spin_version = "1"
spin_manifest_version = "1"
authors = ["Fermyon Engineering <[email protected]>"]
description = "A simple application that returns hello."
name = "spin-hello-world"
Expand Down
2 changes: 1 addition & 1 deletion examples/http-rust-outbound-http/spin.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spin_version = "1"
spin_manifest_version = "1"
authors = ["Fermyon Engineering <[email protected]>"]
description = "A simple application that makes an outbound http call."
name = "spin-outbound-http"
Expand Down
2 changes: 1 addition & 1 deletion examples/http-rust/spin.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spin_version = "1"
spin_manifest_version = "1"
authors = ["Fermyon Engineering <[email protected]>"]
description = "A simple application that returns hello."
name = "spin-hello-world"
Expand Down
2 changes: 1 addition & 1 deletion examples/http-tinygo-outbound-http/spin.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spin_version = "1"
spin_manifest_version = "1"
authors = ["Fermyon Engineering <[email protected]>"]
description = "A simple Spin application written in (Tiny)Go that performs outbound HTTP requests."
name = "spin-tinygo-outbound-http"
Expand Down
2 changes: 1 addition & 1 deletion examples/http-tinygo/spin.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spin_version = "1"
spin_manifest_version = "1"
authors = ["Fermyon Engineering <[email protected]>"]
description = "A simple Spin application written in (Tiny)Go."
name = "spin-hello-tinygo"
Expand Down
2 changes: 1 addition & 1 deletion examples/redis-rust/spin.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spin_version = "1"
spin_manifest_version = "1"
authors = ["Fermyon Engineering <[email protected]>"]
description = "A redis application."
name = "spin-redis"
Expand Down
2 changes: 1 addition & 1 deletion examples/rust-key-value/spin.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spin_version = "1"
spin_manifest_version = "1"
authors = ["Fermyon Engineering <[email protected]>"]
description = "A simple application that exercises key-value storage."
name = "spin-key-value"
Expand Down
2 changes: 1 addition & 1 deletion examples/rust-outbound-mysql/spin.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spin_version = "1"
spin_manifest_version = "1"
authors = ["itowlson <[email protected]>"]
description = "Demo of calling MySQL from a Spin application"
name = "rust-outbound-mysql"
Expand Down
2 changes: 1 addition & 1 deletion examples/rust-outbound-pg/spin.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spin_version = "1"
spin_manifest_version = "1"
authors = ["Fermyon Engineering <[email protected]>"]
name = "rust-outbound-pg-example"
trigger = { type = "http", base = "/" }
Expand Down
2 changes: 1 addition & 1 deletion examples/rust-outbound-redis/spin.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spin_version = "1"
spin_manifest_version = "1"
authors = ["Fermyon Engineering <[email protected]>"]
name = "rust-outbound-redis-example"
trigger = { type = "http", base = "/" }
Expand Down
2 changes: 1 addition & 1 deletion examples/spin-timer/app-example/spin.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spin_version = "1"
spin_manifest_version = "1"
authors = ["itowlson <[email protected]>"]
description = ""
name = "goodbye"
Expand Down
2 changes: 1 addition & 1 deletion examples/spin-wagi-http/spin.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spin_version = "1"
spin_manifest_version = "1"
authors = ["Fermyon Engineering <[email protected]>"]
description = "A hello world application that serves content from a C++ program and a Rust program"
name = "spin-wagi-hello"
Expand Down
2 changes: 1 addition & 1 deletion examples/tinygo-key-value/spin.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spin_version = "1"
spin_manifest_version = "1"
authors = ["Fermyon Engineering <[email protected]>"]
name = "tinygo-key-value-example"
trigger = { type = "http", base = "/" }
Expand Down
2 changes: 1 addition & 1 deletion examples/tinygo-outbound-redis/spin.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spin_version = "1"
spin_manifest_version = "1"
authors = ["Fermyon Engineering <[email protected]>"]
name = "tinygo-outbound-redis-example"
trigger = { type = "http", base = "/" }
Expand Down
2 changes: 1 addition & 1 deletion examples/tinygo-redis/spin.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spin_version = "1"
spin_manifest_version = "1"
authors = ["Fermyon Engineering <[email protected]>"]
description = "A redis application."
name = "spin-redis"
Expand Down
2 changes: 1 addition & 1 deletion examples/wagi-http-rust/spin.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spin_version = "1"
spin_manifest_version = "1"
authors = ["Fermyon Engineering <[email protected]>"]
description = "An application that returns the arguments the program started with, the environment variables set, and current time"
name = "wagi-hello-world"
Expand Down
2 changes: 1 addition & 1 deletion templates/http-c/content/spin.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spin_version = "1"
spin_manifest_version = "1"
authors = ["{{authors}}"]
description = "{{project-description}}"
name = "{{project-name}}"
Expand Down
2 changes: 1 addition & 1 deletion templates/http-empty/content/spin.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spin_version = "1"
spin_manifest_version = "1"
authors = ["{{authors}}"]
description = "{{project-description}}"
name = "{{project-name}}"
Expand Down
2 changes: 1 addition & 1 deletion templates/http-go/content/spin.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spin_version = "1"
spin_manifest_version = "1"
authors = ["{{authors}}"]
description = "{{project-description}}"
name = "{{project-name}}"
Expand Down
2 changes: 1 addition & 1 deletion templates/http-grain/content/spin.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spin_version = "1"
spin_manifest_version = "1"
authors = ["{{authors}}"]
description = "{{project-description}}"
name = "{{project-name}}"
Expand Down
2 changes: 1 addition & 1 deletion templates/http-php/content/spin.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spin_version = "1"
spin_manifest_version = "1"
authors = ["{{authors}}"]
description = "{{project-description}}"
name = "{{project-name}}"
Expand Down
2 changes: 1 addition & 1 deletion templates/http-rust/content/spin.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spin_version = "1"
spin_manifest_version = "1"
authors = ["{{authors}}"]
description = "{{project-description}}"
name = "{{project-name}}"
Expand Down
2 changes: 1 addition & 1 deletion templates/http-swift/content/spin.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spin_version = "1"
spin_manifest_version = "1"
authors = ["{{authors}}"]
description = "{{project-description}}"
name = "{{project-name}}"
Expand Down
2 changes: 1 addition & 1 deletion templates/http-zig/content/spin.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spin_version = "1"
spin_manifest_version = "1"
authors = ["{{authors}}"]
description = "{{project-description}}"
name = "{{project-name}}"
Expand Down
2 changes: 1 addition & 1 deletion templates/redis-go/content/spin.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spin_version = "1"
spin_manifest_version = "1"
authors = ["{{authors}}"]
description = "{{project-description}}"
name = "{{project-name}}"
Expand Down
2 changes: 1 addition & 1 deletion templates/redis-rust/content/spin.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spin_version = "1"
spin_manifest_version = "1"
authors = ["{{authors}}"]
description = "{{project-description}}"
name = "{{project-name}}"
Expand Down
2 changes: 1 addition & 1 deletion templates/static-fileserver/content/spin.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spin_version = "1"
spin_manifest_version = "1"
authors = ["{{authors}}"]
description = "{{project-description}}"
name = "{{project-name}}"
Expand Down

0 comments on commit eaf8653

Please sign in to comment.