Skip to content

Commit

Permalink
Hello Caddy!
Browse files Browse the repository at this point in the history
  • Loading branch information
eirikb committed Jul 13, 2024
1 parent 2fd1dea commit 86a7efb
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/stage4/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use semver::{Version, VersionReq};
use serde::{Deserialize, Serialize};
use which::which_in;
use crate::bloody_indiana_jones::BloodyIndianaJones;

use crate::executors::caddy::Caddy;
use crate::executors::custom_command::CustomCommand;
use crate::executors::deno::Deno;
use crate::executors::go::Go;
Expand Down Expand Up @@ -151,6 +151,7 @@ impl dyn Executor {
"run" => Some(Box::new(CustomCommand { executor_cmd })),
"deno" => Some(Box::new(Deno { executor_cmd })),
"go" => Some(Box::new(Go { executor_cmd })),
"caddy" => Some(Box::new(Caddy { executor_cmd })),
_ => None,
}
}
Expand Down
73 changes: 73 additions & 0 deletions src/stage4/src/executors/caddy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
use std::collections::HashSet;
use std::future::Future;
use std::pin::Pin;

use crate::executor::{AppInput, Download, Executor, ExecutorCmd, GgVersion};
use crate::target::{Arch, Os, Variant};
use crate::target::Os::Windows;

pub struct Caddy {
pub executor_cmd: ExecutorCmd,
}

impl Executor for Caddy {
fn get_executor_cmd(&self) -> &ExecutorCmd {
&self.executor_cmd
}

fn get_download_urls<'a>(&self, _input: &'a AppInput) -> Pin<Box<dyn Future<Output=Vec<Download>> + 'a>> {
Box::pin(async move {
let mut downloads: Vec<Download> = vec!();
let octocrab = octocrab::Octocrab::builder().build().unwrap();
let mut page: u32 = 1;
loop {
let releases = octocrab.repos("caddyserver", "caddy")
.releases().list().page(page).per_page(100).send().await.unwrap();
for release in releases.items {
for asset in release.assets {
let os = if asset.name.contains("windows") {
Some(Windows)
} else if asset.name.contains("linux") {
Some(Os::Linux)
} else if asset.name.contains("apple") {
Some(Os::Mac)
} else {
None
};
let arch = if asset.name.contains("amd64") {
Some(Arch::X86_64)
} else {
None
};
if os.is_some() && arch.is_some() {
downloads.push(Download {
download_url: asset.browser_download_url.to_string(),
version: GgVersion::new(release.tag_name.as_str()),
os,
arch,
tags: HashSet::new(),
variant: Some(Variant::Any),
});
}
}
}
if releases.next == None {
break;
}
page += 1;
}
downloads
})
}

fn get_bins(&self, input: &AppInput) -> Vec<String> {
vec!(match &input.target.os {
Windows => "caddy.exe",
_ => "caddy"
}.to_string())
}

fn get_name(&self) -> &str {
"caddy"
}
}
1 change: 1 addition & 0 deletions src/stage4/src/executors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ pub mod node;
pub mod deno;
pub mod gradle_properties;
pub mod go;
pub mod caddy;

0 comments on commit 86a7efb

Please sign in to comment.