Skip to content

Commit

Permalink
Add Windows CI test for self-update
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancisMurillo committed May 20, 2023
1 parent 6b86066 commit 7070db9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,24 @@ jobs:
throw 'error on rg.exe'
}
- if: matrix.os == 'windows-latest'
name: "Integration test: [windows] [sync-self]"
env:
SYNC_DIR: "sync-self"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mkdir sync-self
copy "target\debug\tool.exe" "sync-self\tool.exe"
sync-self\tool.exe --config="tests\sync-self-downgrade.toml" sync
$old_version = sync-self\tool.exe --version
if ($old_version -notmatch 'tool-sync 0.2.0') {
throw 'self-update is not the same'
}
- if: matrix.os != 'windows-latest'
name: "Integration test: [unix] [sync-full]"
env:
Expand Down
12 changes: 10 additions & 2 deletions src/sync/install.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use indicatif::ProgressBar;
use self_replace;
use std::env;
use std::error::Error;
use std::fs;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -53,6 +52,8 @@ impl<'a> Installer<'a> {
true
}
Err(e) => {
eprintln!("ee {}", &e);

self.sync_progress
.failure(pb_msg, tool_name, tag, format!("[error] {}", e));
false
Expand All @@ -65,6 +66,9 @@ impl<'a> Installer<'a> {
tool_asset: &ToolAsset,
pb_msg: &ProgressBar,
) -> Result<(), Box<dyn Error>> {
#[cfg(target_family = "windows")]
eprintln!("Q-{}", std::env::current_exe().unwrap().display());

let downloader = Downloader {
asset: &tool_asset.asset,
client: &tool_asset.client,
Expand Down Expand Up @@ -99,13 +103,17 @@ impl<'a> Installer<'a> {
}

fn copy_file(tool_path: PathBuf, store_directory: &Path, exe_name: &str) -> std::io::Result<()> {
#[cfg(target_family = "windows")]
eprintln!("A {}", exe_name);
let is_self_update = exe_name == "tool";

let exe_name = mk_exe_name(exe_name);

let mut install_path = PathBuf::new();
install_path.push(store_directory);
install_path.push(exe_name);

if &install_path == &env::current_exe()? {
if is_self_update {
// May have issues with a symbolic links. The assumption is that
// the store directory is in the PATH and the executable itself
// where this issue should not apply but may be an edge case.
Expand Down
4 changes: 4 additions & 0 deletions tests/sync-self-downgrade.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
store_directory = "sync-self"

[tool-sync]
tag = "v0.2.0"

0 comments on commit 7070db9

Please sign in to comment.