Compare commits

..
Author SHA1 Message Date
dzu
98addf4d54 cleanup 2026-02-20 14:58:27 +00:00
dzu
2bc5e3c712 fix: ignore empty provided inputs
apparently, Forgejo provides empty variables for optional
not-specified inputs, for some reason 🤷
2026-02-20 14:54:47 +00:00
dzu
2c1972141b fix(build): correct action runs spec 2026-02-15 07:25:19 +00:00
dzu
0e37f99cd2 fix(macro): do not replace - with _ in inputs 2026-02-15 05:42:01 +00:00
dzu
d9ad91c55d add boolean parser 2026-02-13 14:08:06 +00:00
dzu
44916a91db remeve Forgejo-openapi from the workspace
There is literally to reason to mingle them
2026-02-13 10:17:50 +00:00
dzu
ce4fd8ccc9 add hard-coded paths warning 2026-02-13 10:16:18 +00:00
dzu
640e9507a1 Initial implementation (#1)
initial renerated client

cargo fmt over generated client

minimal forgejo openapi test

also example setup to compile this thing

move out Forgejo OpenAPI definintion

remove openapi test

initial implementation

[Cargo.lock]

Reviewed-on: #1
Co-authored-by: dzu <dzu@dzuchun.ing>
Co-committed-by: dzu <dzu@dzuchun.ing>
2026-02-11 06:36:50 +01:00
7 changed files with 29 additions and 978 deletions

966
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -13,8 +13,6 @@ anode = { path = "./anode" }
anode-macros-input = { path = "./anode-macros-input" } anode-macros-input = { path = "./anode-macros-input" }
anode-macros = { path = "./anode-macros" } anode-macros = { path = "./anode-macros" }
anode-build = { path = "./anode-build" } anode-build = { path = "./anode-build" }
# git
forgejo-openapi = { git = "https://git.dzuchun.ing/dzu/forgejo-openapi.git", default-features = false }
# crates.io # crates.io
syn = { version = "2", default-features = false } syn = { version = "2", default-features = false }
quote = { version = "1", default-features = false } quote = { version = "1", default-features = false }

View file

@ -1,3 +1,4 @@
// WARN: be aware that both source code file path and output path and hard-coded. they might not work for you; if you have any suggestion for heuristics would determine these paths in a universal way, please let me know
use syn::{File, punctuated::Punctuated}; use syn::{File, punctuated::Punctuated};
use anode_macros_input::pretty_span; use anode_macros_input::pretty_span;

View file

@ -1,5 +1,4 @@
runs: using: composite
using: composite steps:
steps: - run: ${{ forgejo.action_path }}/main
- run: ${{ forgejo.action_path }}/main shell: bash
shell: bash

View file

@ -56,7 +56,7 @@ fn try_get(action: &Action) -> ItemFn {
let input_lit = LitStr::new(name, proc_macro2::Span::call_site()); let input_lit = LitStr::new(name, proc_macro2::Span::call_site());
let input_envvar = LitStr::new( let input_envvar = LitStr::new(
&format!("INPUT_{}", name.to_uppercase().replace('-', "_")), &format!("INPUT_{}", name.to_uppercase()),
proc_macro2::Span::call_site(), proc_macro2::Span::call_site(),
); );
let mut envvar: syn::Expr = syn::parse_quote!( ::std::env::var_os(#input_envvar) ); let mut envvar: syn::Expr = syn::parse_quote!( ::std::env::var_os(#input_envvar) );
@ -66,7 +66,7 @@ fn try_get(action: &Action) -> ItemFn {
envvar = syn::parse_quote!( #envvar.or_else(|| Some(::std::ffi::OsString::from(String::from(#def)))) ); envvar = syn::parse_quote!( #envvar.or_else(|| Some(::std::ffi::OsString::from(String::from(#def)))) );
} }
let mut parse_input: syn::ExprIf = syn::parse_quote! { let mut parse_input: syn::ExprIf = syn::parse_quote! {
if let Some(envvar) = #envvar { if let Some(envvar) = #envvar && !envvar.is_empty() {
match #parser(envvar) { match #parser(envvar) {
Ok(ok) => #input_ident = Some(ok), Ok(ok) => #input_ident = Some(ok),
Err(error) => #errors.push((#input_lit, ::anode::InputErrorMessage::Parsing(::std::boxed::Box::new(error)))), Err(error) => #errors.push((#input_lit, ::anode::InputErrorMessage::Parsing(::std::boxed::Box::new(error)))),

View file

@ -6,7 +6,3 @@ edition = "2024"
[dependencies] [dependencies]
anode-macros.workspace = true anode-macros.workspace = true
thiserror.workspace = true thiserror.workspace = true
forgejo-openapi = { workspace = true, optional = true }
[features]
forge-forgejo = [ "dep:forgejo-openapi" ]

View file

@ -70,6 +70,24 @@ pub mod __default_parser {
pub fn PathBuf(input: OsString) -> Result<PathBuf, core::convert::Infallible> { pub fn PathBuf(input: OsString) -> Result<PathBuf, core::convert::Infallible> {
Ok(input.into()) Ok(input.into())
} }
#[derive(Debug, thiserror::Error)]
#[error("Unknown boolean value: {}", _0.display())]
pub struct UnknownBoolean(OsString);
pub fn bool(input: OsString) -> Result<bool, UnknownBoolean> {
const VALID_TRUE: &[&[u8]] = &[b"TRUE", b"True", b"true", b"1"];
const VALID_FALSE: &[&[u8]] = &[b"FALSE", b"False", b"false", b"0"];
if VALID_TRUE.contains(&input.as_bytes()) {
return Ok(true);
}
if VALID_FALSE.contains(&input.as_bytes()) {
return Ok(false);
}
Err(UnknownBoolean(input))
}
} }
pub mod parse { pub mod parse {
@ -89,9 +107,6 @@ pub mod parse {
} }
} }
#[cfg(feature = "forge-forgejo")]
pub use forgejo_openapi as forgejo;
#[derive(Debug)] #[derive(Debug)]
pub struct InputError(#[doc(hidden)] pub Box<[(&'static str, InputErrorMessage)]>); pub struct InputError(#[doc(hidden)] pub Box<[(&'static str, InputErrorMessage)]>);