diff --git a/tools/codegen/src/lib.rs b/tools/codegen/src/lib.rs index 4211e679..41ced542 100644 --- a/tools/codegen/src/lib.rs +++ b/tools/codegen/src/lib.rs @@ -2,11 +2,89 @@ #![allow(clippy::missing_panics_doc, clippy::too_long_first_doc_paragraph)] -use std::{env, path::Path}; +use std::{collections::BTreeMap, env, path::Path}; pub use install_action_manifest_schema::*; +use serde_derive::Deserialize; #[must_use] pub fn workspace_root() -> &'static Path { Path::new(env!("CARGO_MANIFEST_DIR").strip_suffix("tools/codegen").unwrap()) } + +#[derive(Debug, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct BaseManifest { + /// Link to the GitHub repository. + pub repository: String, + /// Alternative link for the project. Automatically detected if possible. + pub website: Option, + /// Markdown syntax for links to licenses. Automatically detected if possible. + pub license_markdown: Option, + /// Prefix of release tag. + pub tag_prefix: String, + /// Crate name, if this is Rust crate. + pub rust_crate: Option, + pub default_major_version: Option, + /// Asset name patterns. + pub asset_name: Option, + /// Path to binaries in archive. Default to `${tool}${exe}`. + pub bin: Option, + pub signing: Option, + #[serde(default)] + pub broken: Vec, + pub version_range: Option, + /// Use glibc build if host_env is gnu. + #[serde(default)] + pub prefer_linux_gnu: bool, + /// Check that the version is yanked not only when updating the manifest, + /// but also when running the action. + #[serde(default)] + pub immediate_yank_reflection: bool, + pub platform: BTreeMap, +} +impl BaseManifest { + /// Validate the manifest. + pub fn validate(&self) { + for bin in self.bin.iter().chain(self.platform.values().flat_map(|m| &m.bin)) { + assert!(!bin.as_slice().is_empty()); + for bin in bin.as_slice() { + let file_name = Path::new(bin).file_name().unwrap().to_str().unwrap(); + if !self.repository.ends_with("/xbuild") { + assert!( + !(file_name.contains("${version") || file_name.contains("${rust")), + "{bin}" + ); + } + } + } + if self.platform.is_empty() { + panic!("At least one platform must be specified"); + } + } +} + +#[derive(Debug, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct Signing { + pub kind: SigningKind, +} + +#[derive(Debug, Deserialize, PartialEq, Eq)] +#[serde(rename_all = "kebab-case")] +#[serde(deny_unknown_fields)] +pub enum SigningKind { + /// algorithm: minisign + /// public key: package.metadata.binstall.signing.pubkey at Cargo.toml + /// + MinisignBinstall, +} + +#[derive(Debug, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct BaseManifestPlatformInfo { + /// Asset name patterns. Default to the value at `BaseManifest::asset_name`. + pub asset_name: Option, + /// Path to binaries in archive. Default to the value at `BaseManifest::bin`. + pub bin: Option, +} diff --git a/tools/manifest-schema/src/lib.rs b/tools/manifest-schema/src/lib.rs index cfcf2ae1..573680bc 100644 --- a/tools/manifest-schema/src/lib.rs +++ b/tools/manifest-schema/src/lib.rs @@ -41,7 +41,6 @@ use core::{ fmt, slice, str::FromStr, }; -use std::path::Path; use serde::{ de::{self, Deserialize, Deserializer}, @@ -245,83 +244,6 @@ pub struct ManifestTemplateDownloadInfo { pub bin: Option, } -#[derive(Debug, Deserialize)] -#[serde(deny_unknown_fields)] -pub struct BaseManifest { - /// Link to the GitHub repository. - pub repository: String, - /// Alternative link for the project. Automatically detected if possible. - pub website: Option, - /// Markdown syntax for links to licenses. Automatically detected if possible. - pub license_markdown: Option, - /// Prefix of release tag. - pub tag_prefix: String, - /// Crate name, if this is Rust crate. - pub rust_crate: Option, - pub default_major_version: Option, - /// Asset name patterns. - pub asset_name: Option, - /// Path to binaries in archive. Default to `${tool}${exe}`. - pub bin: Option, - pub signing: Option, - #[serde(default)] - pub broken: Vec, - pub version_range: Option, - /// Use glibc build if host_env is gnu. - #[serde(default)] - pub prefer_linux_gnu: bool, - /// Check that the version is yanked not only when updating the manifest, - /// but also when running the action. - #[serde(default)] - pub immediate_yank_reflection: bool, - pub platform: BTreeMap, -} -impl BaseManifest { - /// Validate the manifest. - pub fn validate(&self) { - for bin in self.bin.iter().chain(self.platform.values().flat_map(|m| &m.bin)) { - assert!(!bin.as_slice().is_empty()); - for bin in bin.as_slice() { - let file_name = Path::new(bin).file_name().unwrap().to_str().unwrap(); - if !self.repository.ends_with("/xbuild") { - assert!( - !(file_name.contains("${version") || file_name.contains("${rust")), - "{bin}" - ); - } - } - } - if self.platform.is_empty() { - panic!("At least one platform must be specified"); - } - } -} - -#[derive(Debug, Deserialize)] -#[serde(deny_unknown_fields)] -pub struct Signing { - pub kind: SigningKind, -} - -#[derive(Debug, Deserialize, PartialEq, Eq)] -#[serde(rename_all = "kebab-case")] -#[serde(deny_unknown_fields)] -pub enum SigningKind { - /// algorithm: minisign - /// public key: package.metadata.binstall.signing.pubkey at Cargo.toml - /// - MinisignBinstall, -} - -#[derive(Debug, Deserialize)] -#[serde(deny_unknown_fields)] -pub struct BaseManifestPlatformInfo { - /// Asset name patterns. Default to the value at `BaseManifest::asset_name`. - pub asset_name: Option, - /// Path to binaries in archive. Default to the value at `BaseManifest::bin`. - pub bin: Option, -} - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(untagged)] pub enum StringOrArray {