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
9// For the `cargo_crate_version!` macro
10#[macro_use]
11extern crate self_update;
12
13fn run() -> Result<(), Box<dyn ::std::error::Error>> {
14    let mut rel_builder = self_update::backends::github::ReleaseList::configure();
15
16    #[cfg(feature = "signatures")]
17    rel_builder.repo_owner("Kijewski");
18    #[cfg(not(feature = "signatures"))]
19    rel_builder.repo_owner("jaemk");
20
21    let releases = rel_builder.repo_name("self_update").build()?.fetch()?;
22    println!("found releases:");
23    println!("{:#?}\n", releases);
24
25    let mut status_builder = self_update::backends::github::Update::configure();
26
27    #[cfg(feature = "signatures")]
28    status_builder
29        .repo_owner("Kijewski")
30        .verifying_keys([*include_bytes!("github-public.key")]);
31    #[cfg(not(feature = "signatures"))]
32    status_builder.repo_owner("jaemk");
33
34    let status = status_builder
35        .repo_name("self_update")
36        .bin_name("github")
37        .show_download_progress(true)
38        //.target_version_tag("v9.9.10")
39        //.show_output(false)
40        //.no_confirm(true)
41        //
42        // For private repos, you will need to provide a GitHub auth token
43        // **Make sure not to bake the token into your app**; it is recommended
44        // you obtain it via another mechanism, such as environment variables
45        // or prompting the user for input
46        //.auth_token(env!("DOWNLOAD_AUTH_TOKEN"))
47        .current_version(cargo_crate_version!())
48        .build()?
49        .update()?;
50    println!("Update status: `{}`!", status.version());
51    Ok(())
52}
53
54pub fn main() {
55    if let Err(e) = run() {
56        println!("[ERROR] {}", e);
57        ::std::process::exit(1);
58    }
59}