ghactions_toolcache/lib.rs
1//! # GitHub Actions Tool Cache
2//!
3//! A Rust library for managing a tool cache similar to the one used in
4//! GitHub Actions.
5//!
6//! This library allows you to find, add, download, and manage tools in a
7//! local cache directory. It supports multiple platforms and architectures.
8//!
9//!
10//! ### Example
11//!
12//! ```no_run
13//! # use anyhow::Result;
14//! use ghactions::ToolCache;
15//!
16//! # #[tokio::main]
17//! # async fn main() -> Result<()> {
18//!
19//! // Create a new ToolCache instance
20//! let tool_cache = ToolCache::new();
21//!
22//! // Find a tool in the cache
23//! let path = tool_cache.find("node", "latest").await
24//! .expect("Failed to find tool in cache");
25//!
26//! // Find a specific version of a tool in the cache
27//! let path = tool_cache.find("node", "20.0.0").await
28//! .expect("Failed to find tool in cache");
29//!
30//! # Ok(())
31//! # }
32//! ```
33#![deny(missing_docs, unsafe_code)]
34
35pub mod arch;
36pub mod archives;
37pub mod builder;
38pub mod cache;
39#[cfg(feature = "download")]
40pub mod downloads;
41pub mod platform;
42pub mod tool;
43
44pub use arch::ToolCacheArch;
45pub use cache::ToolCache;
46pub use platform::ToolPlatform;
47pub use tool::Tool;
48
49/// Tool cache errors
50#[derive(Debug, thiserror::Error)]
51pub enum ToolCacheError {
52 /// Tool not found in cache
53 #[error("Tool not found in cache: {name} {version} {arch:?}")]
54 ToolNotFound {
55 /// Tool name
56 name: String,
57 /// Tool version
58 version: String,
59 /// Tool architecture (if specified)
60 arch: Option<ToolCacheArch>,
61 },
62
63 /// I/O Error
64 #[error("I/O error: {0}")]
65 IoError(#[from] std::io::Error),
66
67 /// HTTP Error
68 #[cfg(feature = "api")]
69 #[error("HTTP error: {0}")]
70 HttpError(#[from] reqwest::Error),
71
72 /// Header Error
73 #[cfg(feature = "api")]
74 #[error("Header error: {0}")]
75 HeaderError(#[from] reqwest::header::InvalidHeaderValue),
76
77 /// GitHub API Error
78 #[cfg(feature = "api")]
79 #[error("GitHub API error: {0}")]
80 ApiError(#[from] octocrab::Error),
81
82 /// Zip Error
83 #[cfg(feature = "zip")]
84 #[error("Zip error: {0}")]
85 ZipError(#[from] zip::result::ZipError),
86
87 /// Download Error
88 #[error("Download error: {0}")]
89 DownloadError(String),
90
91 /// Generic Error
92 #[error("Tool Cache error: {0}")]
93 GenericError(String),
94}