Skip to content

Commit ab9ee84

Browse files
Alex HolmbergAlex Holmberg
authored andcommitted
feat: updated small changes for automatic release
1 parent 78f7a77 commit ab9ee84

4 files changed

Lines changed: 84 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
77
## [Unreleased]
88
- Add new features and improvements here.
99

10-
## [0.1.2] - 2024-06-05
10+
## [0.1.3] - 2024-06-05
1111
### Added
1212
- Initial release of `syncable-cli`.
1313
- Analyze code repositories to detect languages, frameworks, and dependencies.

Cargo.lock

Lines changed: 42 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "syncable-cli"
3-
version = "0.1.2"
3+
version = "0.1.3"
44
edition = "2024"
55
authors = ["Syncable Team"]
66
description = "A Rust-based CLI that analyzes code repositories and generates Infrastructure as Code configurations"
@@ -38,6 +38,7 @@ reqwest = { version = "0.11", features = ["json", "blocking"] }
3838
tokio = { version = "1", features = ["rt", "macros", "rt-multi-thread"] }
3939
textwrap = "0.16"
4040
tempfile = "3"
41+
dirs = "5"
4142

4243
[dev-dependencies]
4344
assert_cmd = "2"

src/main.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ use syncable_cli::{
77
};
88
use std::process;
99
use std::collections::HashMap;
10+
use std::fs;
11+
use std::path::PathBuf;
12+
use std::time::{SystemTime, Duration};
13+
use dirs::cache_dir;
14+
use reqwest::blocking::get;
1015

1116
#[tokio::main]
1217
async fn main() {
@@ -17,6 +22,7 @@ async fn main() {
1722
}
1823

1924
async fn run() -> syncable_cli::Result<()> {
25+
check_for_update();
2026
let cli = Cli::parse();
2127

2228
// Initialize logging
@@ -95,6 +101,39 @@ async fn run() -> syncable_cli::Result<()> {
95101
Ok(())
96102
}
97103

104+
fn check_for_update() {
105+
let cache_file = cache_dir()
106+
.unwrap_or_else(|| PathBuf::from("."))
107+
.join("syncable-cli/last_update_check");
108+
let now = SystemTime::now();
109+
110+
// Only check once per day
111+
if let Ok(metadata) = fs::metadata(&cache_file) {
112+
if let Ok(modified) = metadata.modified() {
113+
if now.duration_since(modified).unwrap_or(Duration::ZERO) < Duration::from_secs(60 * 60 * 24) {
114+
return;
115+
}
116+
}
117+
}
118+
119+
// Query crates.io
120+
let resp = get("https://crates.io/api/v1/crates/syncable-cli")
121+
.and_then(|r| r.json::<serde_json::Value>());
122+
if let Ok(json) = resp {
123+
let latest = json["crate"]["max_version"].as_str().unwrap_or("");
124+
let current = env!("CARGO_PKG_VERSION");
125+
if latest != "" && latest != current {
126+
println!(
127+
"\x1b[33m🔔 A new version of sync-ctl is available: {latest} (current: {current})\nRun `cargo install syncable-cli --force` to update.\x1b[0m"
128+
);
129+
}
130+
}
131+
132+
// Update cache file
133+
let _ = fs::create_dir_all(cache_file.parent().unwrap());
134+
let _ = fs::write(&cache_file, "");
135+
}
136+
98137
fn handle_analyze(
99138
path: std::path::PathBuf,
100139
json: bool,

0 commit comments

Comments
 (0)