print app version
This commit is contained in:
@ -62,15 +62,19 @@ local host_volume(name, path) = {
|
||||
"build",
|
||||
depends=["test"],
|
||||
commands=["cargo build" + flags],
|
||||
env={
|
||||
GIT_REVISION: "${DRONE_COMMIT:0:8}",
|
||||
GIT_BRANCH: "${DRONE_COMMIT_BRANCH}",
|
||||
},
|
||||
),
|
||||
step(
|
||||
"deploy",
|
||||
depends=["build"],
|
||||
commands=["sh scripts/deploy.sh"],
|
||||
env={
|
||||
"TARGET_DIR": "/cache/target/" + target_arch + "/release",
|
||||
"SSH_PRIVATE_KEY": {"from_secret": "ssh_pk_base64"},
|
||||
"SSH_USER": {"from_secret": "SSH_USER"},
|
||||
TARGET_DIR: "/cache/target/" + target_arch + "/release",
|
||||
SSH_PRIVATE_KEY: {"from_secret": "ssh_pk_base64"},
|
||||
SSH_USER: {"from_secret": "SSH_USER"},
|
||||
},
|
||||
),
|
||||
],
|
||||
|
||||
@ -47,6 +47,8 @@ steps:
|
||||
environment:
|
||||
APP_NAME: altherego
|
||||
CARGO_TARGET_DIR: /cache/target
|
||||
GIT_BRANCH: ${DRONE_COMMIT_BRANCH}
|
||||
GIT_REVISION: ${DRONE_COMMIT:0:8}
|
||||
volumes:
|
||||
- name: cargo
|
||||
path: /usr/local/cargo
|
||||
@ -91,6 +93,6 @@ volumes:
|
||||
|
||||
---
|
||||
kind: signature
|
||||
hmac: 9636ad34a72c9a41ad90c91729e8b711579563345ae485a4ea2ee40eb3ff46e4
|
||||
hmac: a942d89af2c38916d55ebe377709febf08145ce8e08a2b585dda8a1c251eaca0
|
||||
|
||||
...
|
||||
|
||||
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -11,7 +11,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "altherego"
|
||||
version = "0.1.0"
|
||||
version = "0.9.5"
|
||||
dependencies = [
|
||||
"env_logger",
|
||||
"envconfig",
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "altherego"
|
||||
version = "0.1.0"
|
||||
version = "0.9.5"
|
||||
authors = ["Aleksandr Trushkin <aleksandr.trushkin@rt.ru>"]
|
||||
edition = "2018"
|
||||
|
||||
|
||||
41
build.rs
Normal file
41
build.rs
Normal file
@ -0,0 +1,41 @@
|
||||
use std::env;
|
||||
|
||||
fn main() {
|
||||
let rev = get_value_from_env("GIT_VERSION")
|
||||
.or_else(|| get_value_from_command("git", &["rev-parse", "--short", "HEAD"]))
|
||||
.unwrap_or_else(|| "unknown".to_owned());
|
||||
|
||||
let branch = get_value_from_env("GIT_BRANCH")
|
||||
.or_else(|| get_value_from_command("git", &["rev-parse", "--abbrev-ref", "HEAD"]))
|
||||
.unwrap_or_else(|| "unknown".to_owned());
|
||||
|
||||
println!("cargo:rustc-env=GIT_REVISION={}", rev);
|
||||
println!("cargo:rustc-env=GIT_BRANCH={}", branch);
|
||||
println!("cargo:rerun-if-env-changed=GIT_REVISION");
|
||||
}
|
||||
|
||||
fn get_value_from_env(key: &str) -> Option<String> {
|
||||
env::var(key).map_or_else(|_| None, |v| Some(v))
|
||||
}
|
||||
|
||||
fn get_value_from_command<I: IntoIterator<Item = S>, S: AsRef<std::ffi::OsStr>>(
|
||||
cmd: &str,
|
||||
args: I,
|
||||
) -> Option<String> {
|
||||
std::process::Command::new(cmd)
|
||||
.args(args)
|
||||
.output()
|
||||
.map_or_else(
|
||||
|_| None,
|
||||
|out| {
|
||||
if !out.status.success() {
|
||||
return None;
|
||||
}
|
||||
|
||||
match std::str::from_utf8(&out.stdout) {
|
||||
Ok(value) => Some(value.to_owned()),
|
||||
Err(_) => None,
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
25
src/main.rs
25
src/main.rs
@ -3,6 +3,9 @@ use envconfig::Envconfig;
|
||||
use log::{debug, info, warn};
|
||||
use teloxide::{prelude::*, utils::command::BotCommand};
|
||||
|
||||
const VERSION: &'static str = env!("GIT_REVISION");
|
||||
const BRANCH: &'static str = env!("GIT_BRANCH");
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
debug!("starting the application");
|
||||
@ -32,6 +35,7 @@ async fn run() {
|
||||
env_logger::init();
|
||||
|
||||
let settings = Settings::init_from_env().expect("reading config values");
|
||||
let startup = std::sync::Arc::from(std::time::SystemTime::now());
|
||||
|
||||
let bot = teloxide::Bot::builder()
|
||||
.token(&settings.telegram_token)
|
||||
@ -44,8 +48,10 @@ async fn run() {
|
||||
let cmd: Vec<&str> = cmd.split(" ").collect();
|
||||
let console_cmd = cmd.get(0).expect("getting console command").to_string();
|
||||
let arg: String = cmd.get(1).unwrap_or_else(|| &"").to_string();
|
||||
// let startup = std::sync::Arc::from(*startup);
|
||||
let startup = *startup;
|
||||
|
||||
async move { handler(cx, command, climate, console_cmd, arg).await }
|
||||
async move { handler(cx, command, climate, console_cmd, arg, startup).await }
|
||||
})
|
||||
.await;
|
||||
}
|
||||
@ -62,6 +68,7 @@ async fn handler(
|
||||
dsn: String,
|
||||
console_command: String,
|
||||
console_arg: String,
|
||||
startup: std::time::SystemTime,
|
||||
) -> ResponseResult<()> {
|
||||
let request_id = uuid::Uuid::new_v4();
|
||||
|
||||
@ -73,7 +80,10 @@ async fn handler(
|
||||
match command {
|
||||
Command::Help => cx.answer(Command::descriptions()).send().await?,
|
||||
Command::HostTemperature => {
|
||||
info!("querying command {} with arg {}", console_command, console_arg);
|
||||
info!(
|
||||
"querying command {} with arg {}",
|
||||
console_command, console_arg
|
||||
);
|
||||
|
||||
let cmd = std::process::Command::new(&console_command)
|
||||
.arg(&console_arg)
|
||||
@ -130,6 +140,15 @@ async fn handler(
|
||||
))
|
||||
.await?
|
||||
}
|
||||
Command::VersionRequest => {
|
||||
cx.answer_str(format!(
|
||||
"app version is {}@{}, uptime is {} second(-s)",
|
||||
VERSION,
|
||||
BRANCH,
|
||||
startup.elapsed().unwrap().as_secs()
|
||||
))
|
||||
.await?
|
||||
}
|
||||
};
|
||||
|
||||
Ok(())
|
||||
@ -144,4 +163,6 @@ enum Command {
|
||||
RoomTemperature,
|
||||
#[command(description = "temperature of raspberry.")]
|
||||
HostTemperature,
|
||||
#[command(description = "prints current version.")]
|
||||
VersionRequest,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user