Skip to content

Commit

Permalink
chore: update publish workflow for cargo pkgid.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpfs committed Jun 21, 2024
1 parent 55a6c50 commit 7c44d31
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 47 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
- name: Set environment variables
shell: bash
run: |
VERSION=$(cargo pkgid | cut -f2 -d '@')
VERSION=$(cd crates/sos && cargo pkgid | cut -f2 -d '#')
echo "BUILD_DIR=target/${{ matrix.binary_target }}/release" >> $GITHUB_ENV
echo "ZIP_FILE=${{ matrix.binary_target }}.zip" >> $GITHUB_ENV
echo "SEMVER=$VERSION" >> $GITHUB_ENV
Expand All @@ -80,10 +80,6 @@ jobs:
- name: Check cosign install
run: cosign version

#- name: Prepare Apple certificate
#if: matrix.distro == 'macos'
#run: |

- name: Install musl tools
if: matrix.binary_target == 'x86_64-unknown-linux-musl'
run: sudo apt-get install musl-tools
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::test_utils::{
simulate_device, spawn, sync_pause, teardown, wait_for_cond,
};
use crate::test_utils::{simulate_device, spawn, teardown, wait_for_cond};
use anyhow::Result;
use sos_net::sdk::prelude::*;

Expand Down
80 changes: 41 additions & 39 deletions crates/test_utils/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,6 @@ use std::{
};
use tokio::sync::Mutex;

/// Wait for a condition to be met.
pub async fn wait_for_cond<T>(test: T)
where
T: Fn() -> bool,
{
use std::time::Duration;
let timeout = Duration::from_millis(15000);
let start = SystemTime::now();

loop {
let elapsed = start.elapsed().unwrap();
if elapsed > timeout {
panic!(
"wait condition took too long, timeout {:?} exceeded",
timeout
);
}
let done = test();
if done {
break;
}
tokio::time::sleep(Duration::from_millis(50)).await;
}
}

/// Simulated device information.
pub struct SimulatedDevice {
/// Test identifier for the device.
Expand Down Expand Up @@ -395,16 +370,20 @@ pub async fn wait_for_file(
file.secret_id(),
file.file_name().to_string(),
);
loop {
tokio::time::sleep(Duration::from_millis(50)).await;
if vfs::try_exists(&path).await? {
let contents = vfs::read(&path).await?;
wait_for_cond(move || {
if path.exists() {
let contents = std::fs::read(&path).unwrap();
let checksum = Sha256::digest(&contents);
if checksum.as_slice() == file.file_name().as_ref() {
break;
true
} else {
false
}
} else {
false
}
}
})
.await;
Ok(())
}

Expand All @@ -413,16 +392,39 @@ pub async fn wait_for_file_not_exist(
paths: impl AsRef<Paths>,
file: &ExternalFile,
) -> Result<()> {
let path = paths.as_ref().file_location(
file.vault_id(),
file.secret_id(),
file.file_name().to_string(),
);
wait_for_cond(move || {
let path = paths.as_ref().file_location(
file.vault_id(),
file.secret_id(),
file.file_name().to_string(),
);
!path.exists()
})
.await;
Ok(())
}

/// Wait for a condition to be met.
pub async fn wait_for_cond<T>(test: T)
where
T: Fn() -> bool,
{
use std::time::Duration;
let timeout = Duration::from_millis(15000);
let start = SystemTime::now();

loop {
tokio::time::sleep(Duration::from_millis(50)).await;
if !vfs::try_exists(&path).await? {
let elapsed = start.elapsed().unwrap();
if elapsed > timeout {
panic!(
"wait condition took too long, timeout {:?} exceeded",
timeout
);
}
let done = test();
if done {
break;
}
tokio::time::sleep(Duration::from_millis(50)).await;
}
Ok(())
}

0 comments on commit 7c44d31

Please sign in to comment.