ghactions_derive/
lib.rs

1//! ghactions-derive is a library that provides derive macros for GitHub Actions in Rust.
2//!
3//! # Example
4//!
5//! ```no_run
6//! use ghactions::prelude::*;
7//!
8//! #[derive(Actions, Debug, Clone)]
9//! #[action(
10//!     path = "./action.yml",
11//!     name = "My Action",
12//!     description = "My Action Description"
13//! )]
14//! pub struct MyAction {
15//!     /// My Input
16//!     #[input(
17//!         description = "My Input",
18//!         default = "false"
19//!     )]
20//!     my_input: bool,
21//!
22//!     #[input(
23//!         name = "custom",
24//!         description = "My Custom Input",
25//!     )]
26//!     my_custom: String,
27//!
28//!     #[input(
29//!         description = "Multi Input",
30//!         split = ",",
31//!     )]
32//!     multi_input: Vec<String>,
33//!
34//!     #[output(description = "Output Value")]
35//!     my_output: String,
36//! }
37//!
38//! fn main() -> Result<(), Box<dyn std::error::Error>> {
39//!     let action = MyAction::init()?;
40//!
41//!     println!("My Input   :: {}", action.my_input);
42//!
43//!     # assert_eq!(action.my_input, false);
44//!     # assert_eq!(action.my_custom, "Custom Value");
45//!     # assert_eq!(action.multi_input, vec!["this".to_string(), "is".to_string(), "a".to_string(), "test".to_string()]);
46//!
47//!     MyAction::set_output("my_output", "My Output Value")?;
48//!
49//!     Ok(())
50//! }
51//! ```
52#![allow(dead_code, unused_imports)]
53#![deny(missing_docs)]
54
55extern crate proc_macro;
56extern crate proc_macro2;
57extern crate quote;
58extern crate syn;
59
60mod attributes;
61mod derives;
62
63use proc_macro::TokenStream;
64use syn::{DeriveInput, parse_macro_input};
65
66/// Derive macro for GitHub Actions
67#[proc_macro_derive(Actions, attributes(action, input, output))]
68pub fn actions(input: TokenStream) -> TokenStream {
69    let ast: DeriveInput = parse_macro_input!(input as DeriveInput);
70
71    match derives::derive_parser(&ast) {
72        Ok(tokens) => tokens.into(),
73        Err(err) => err.to_compile_error().into(),
74    }
75}