jaemk / self_update

Self updates for rust executables
MIT License
772 stars 65 forks source link

How to refer to binary within a folder containing version and target triple inside archive? #122

Closed simonsan closed 5 months ago

simonsan commented 7 months ago

Our current setup is like this:

rustic-v0.7.0-x86_64-pc-windows-msvc.tar.gz
├── rustic-v0.7.0-x86_64-pc-windows-msvc
    ├── config
    │   ├── rustic.toml
    ├── rustic.exe
Checking target-arch... x86_64-pc-windows-msvc
Checking current version... v0.6.1
Checking latest released version... v0.7.0
New release found! v0.6.1 --> v0.7.0
New release is *NOT* compatible

rustic.exe release status:
  * Current exe: "C:\\Users\\dailyuse\\.cargo\\bin\\rustic.exe"
  * New exe release: "rustic-v0.7.0-x86_64-pc-windows-msvc.tar.gz"
  * New exe download url: "https://api.github.com/repos/rustic-rs/rustic/releases/assets/149644039"

The new release will be downloaded/extracted and the existing binary will be replaced.
Do you want to continue? [Y/n] Y
Downloading...
[00:00:00] [========================================] 7.42 MiB/7.42 MiB (0s) Done
Extracting archive... error: UpdateError: Could not find the required path in the archive: "rustic.exe"

How can we self-update from that archive? We currently use:

        let release = self_update::backends::github::Update::configure()
            .repo_owner("rustic-rs")
            .repo_name("rustic")
            .bin_name("rustic")
            .show_download_progress(true)
            .current_version(current_version.to_string().as_str())
            .no_confirm(self.force)
            .build()?;

Replacing works, if we set it like this:

            .bin_path_in_archive("rustic-v0.7.0-x86_64-pc-windows-msvc/rustic.exe")
            .bin_name("rustic")

The problem is, that we can't know:

So how would it be best, to tackle this? 🤔 I'm wondering, if it would make sense, to introduce some basic templating for this, so we could write:

            .bin_path_in_archive("{{ bin }}-v{{ version }}-{{ target }}/{{ bin }}.exe")