github/github.rs
1/*!
2Example updating an executable to the latest version released via GitHub
3
4`cargo run --example github --features "archive-tar archive-zip compression-flate2 compression-zip-deflate"`.
5
6Include `signatures` in the features list to enable zipsign verification
7*/
8
9use self_update::cargo_crate_version;
10
11fn run() -> Result<(), Box<dyn ::std::error::Error>> {
12 let mut rel_builder = self_update::backends::github::ReleaseList::configure();
13
14 #[cfg(feature = "signatures")]
15 rel_builder.repo_owner("Kijewski");
16 #[cfg(not(feature = "signatures"))]
17 rel_builder.repo_owner("jaemk");
18
19 let releases = rel_builder.repo_name("self_update").build()?.fetch()?;
20 println!("found releases:");
21 println!("{:#?}\n", releases);
22
23 let mut status_builder = self_update::backends::github::Update::configure();
24
25 #[cfg(feature = "signatures")]
26 status_builder
27 .repo_owner("Kijewski")
28 .verifying_keys([*include_bytes!("github-public.key")]);
29 #[cfg(not(feature = "signatures"))]
30 status_builder.repo_owner("jaemk");
31
32 let status = status_builder
33 .repo_name("self_update")
34 .bin_name("github")
35 .show_download_progress(true)
36 //.target_version_tag("v9.9.10")
37 //.show_output(false)
38 //.no_confirm(true)
39 //
40 // For private repos, you will need to provide a GitHub auth token
41 // **Make sure not to bake the token into your app**; it is recommended
42 // you obtain it via another mechanism, such as environment variables
43 // or prompting the user for input
44 //.auth_token(env!("DOWNLOAD_AUTH_TOKEN"))
45 //
46 // an optional `identifier` can be specified to narrow down
47 // an asset match for a target or OS-arch combination.
48 // additionally, if target/OS-arch search fails, then
49 // the identifier alone (if specified) will be used to
50 // find the asset
51 // .identifier("github-bin")
52 .current_version(cargo_crate_version!())
53 .build()?
54 .update()?;
55 println!("Update status: `{}`!", status.version());
56 Ok(())
57}
58
59pub fn main() {
60 if let Err(e) = run() {
61 println!("[ERROR] {}", e);
62 ::std::process::exit(1);
63 }
64}