Prep for final release
This commit is contained in:
parent
6f04e79965
commit
7257d93884
726
Cargo.lock
generated
726
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -3,7 +3,7 @@ name = "shibe-bot"
|
|||||||
description = "A Discord bot written in Rust, using Poise."
|
description = "A Discord bot written in Rust, using Poise."
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
version = "0.4.2"
|
version = "1.0.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
|
|
||||||
@ -29,3 +29,4 @@ tempfile = "3.15.0"
|
|||||||
self-replace = "1.5.0"
|
self-replace = "1.5.0"
|
||||||
zip = "2.2.2"
|
zip = "2.2.2"
|
||||||
nix = { version = "0.29.0", features = ["process"] }
|
nix = { version = "0.29.0", features = ["process"] }
|
||||||
|
minreq = { version = "2.13.0", features = ["https"] }
|
||||||
|
BIN
artifact.zip
Normal file
BIN
artifact.zip
Normal file
Binary file not shown.
@ -10,6 +10,8 @@ use std::io::Write;
|
|||||||
use self_replace;
|
use self_replace;
|
||||||
use zip;
|
use zip;
|
||||||
|
|
||||||
|
use minreq;
|
||||||
|
|
||||||
/// Print version and build information
|
/// Print version and build information
|
||||||
#[poise::command(slash_command)]
|
#[poise::command(slash_command)]
|
||||||
pub async fn version(ctx: Context<'_>) -> Result<(), Error> {
|
pub async fn version(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
@ -55,7 +57,7 @@ pub async fn update(ctx: Context<'_>) -> Result<(), Error> {
|
|||||||
info!("Update unnecessary: Commit ID of remote is same as compiled commit.");
|
info!("Update unnecessary: Commit ID of remote is same as compiled commit.");
|
||||||
} else {
|
} else {
|
||||||
info!("Update required, latest commit hash: {}", sha);
|
info!("Update required, latest commit hash: {}", sha);
|
||||||
let Err(what) = self_update().await;
|
let Err(what) = self_update();
|
||||||
error!("Update failed: {}", what);
|
error!("Update failed: {}", what);
|
||||||
ctx.say(format!("Error occurred while updating: {}", what))
|
ctx.say(format!("Error occurred while updating: {}", what))
|
||||||
.await?;
|
.await?;
|
||||||
@ -103,29 +105,24 @@ pub async fn say(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn self_update() -> Result<Infallible, Error> {
|
fn self_update() -> Result<Infallible, Error> {
|
||||||
let artifact_url = "https://nightly.link/shibedrill/shibe-bot/workflows/rust/main/artifact.zip";
|
let artifact_url = "https://nightly.link/shibedrill/shibe-bot/workflows/rust/main/artifact.zip";
|
||||||
let tempdir = tempfile::Builder::new().prefix("shibe-bot").tempdir()?;
|
let tempdir = tempfile::Builder::new().prefix("shibe-bot").tempdir()?;
|
||||||
let response = reqwest::get(artifact_url).await?;
|
trace!("Created tempdir successfully: {}", tempdir.path().display());
|
||||||
|
let response = minreq::get(artifact_url).send()?;
|
||||||
|
|
||||||
let mut dest = {
|
let mut dest = std::fs::File::create_new(tempdir.path().join("artifact.zip"))?;
|
||||||
let fname = response
|
let content = response.as_bytes();
|
||||||
.url()
|
|
||||||
.path_segments()
|
|
||||||
.and_then(|segments| segments.last())
|
|
||||||
.and_then(|name| if name.is_empty() { None } else { Some(name) })
|
|
||||||
.unwrap_or("tmp");
|
|
||||||
let fname = tempdir.path().join(fname);
|
|
||||||
std::fs::File::create(fname)?
|
|
||||||
};
|
|
||||||
let content = response.bytes().await?;
|
|
||||||
dest.write_all(&content)?;
|
dest.write_all(&content)?;
|
||||||
trace!("Downloaded latest build artifact successfully");
|
trace!("Downloaded latest build artifact successfully");
|
||||||
|
|
||||||
|
|
||||||
let mut archive = zip::ZipArchive::new(dest)?;
|
let mut archive = zip::ZipArchive::new(dest)?;
|
||||||
|
trace!("Created zip archive reader");
|
||||||
let mut zipped_bin = archive.by_index(0)?;
|
let mut zipped_bin = archive.by_index(0)?;
|
||||||
let new_bin_path = tempdir.path().join("shibe-bot");
|
let new_bin_path = tempdir.path().join("shibe-bot");
|
||||||
let mut new_bin = std::fs::File::create_new(&new_bin_path)?;
|
let mut new_bin = std::fs::File::create_new(&new_bin_path)?;
|
||||||
|
trace!("Created new file for binary");
|
||||||
|
|
||||||
std::io::copy(&mut zipped_bin, &mut new_bin)?;
|
std::io::copy(&mut zipped_bin, &mut new_bin)?;
|
||||||
trace!("Extracted binary successfully");
|
trace!("Extracted binary successfully");
|
||||||
@ -135,6 +132,7 @@ async fn self_update() -> Result<Infallible, Error> {
|
|||||||
|
|
||||||
let new_command_args: Vec<_> = std::env::args_os().skip(1).collect();
|
let new_command_args: Vec<_> = std::env::args_os().skip(1).collect();
|
||||||
let new_command_path = std::env::current_exe()?;
|
let new_command_path = std::env::current_exe()?;
|
||||||
|
trace!("Got current executable path successfully: {}", new_command_path.display());
|
||||||
|
|
||||||
Err(Box::new(
|
Err(Box::new(
|
||||||
std::process::Command::new(new_command_path)
|
std::process::Command::new(new_command_path)
|
||||||
@ -142,3 +140,20 @@ async fn self_update() -> Result<Infallible, Error> {
|
|||||||
.exec(),
|
.exec(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod test {
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
use std::convert::Infallible;
|
||||||
|
#[cfg(test)]
|
||||||
|
use crate::Error;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_self_update() -> Result<Infallible, Error> {
|
||||||
|
use pretty_env_logger;
|
||||||
|
use crate::command::devel::self_update;
|
||||||
|
pretty_env_logger::init();
|
||||||
|
self_update()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user