Skip to content

Commit

Permalink
wip: error in path absolutsizing
Browse files Browse the repository at this point in the history
  • Loading branch information
Yohe-Am committed Dec 25, 2024
1 parent a9627dc commit a592188
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
16 changes: 12 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
name: test suite
run-name: test suite for ${{ github.event.pull_request.title || github.ref }}
on:
push:
branches:
Expand All @@ -8,6 +10,10 @@ on:
- synchronize
- ready_for_review

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
DENO_VERSION: "2.1.2"
GHJK_LOG: debug
Expand Down Expand Up @@ -67,13 +73,15 @@ jobs:
path: ${{ env.DENO_DIR }}
key: deno-${{ hashFiles('**/deno.lock') }}
- if: "${{ matrix.os == 'ubuntu-latest' || matrix.os == 'custom-arm' }}"
# need coreutils on max for the `timeout` command
# need cmake to build the rust deps
run: |
# we need coreutils on max for the `timeout` command
sudo apt update
sudo apt install -y --no-install-recommends fish zsh
sudo apt install -y --no-install-recommends fish zsh cmake
- if: "${{ matrix.os == 'macos-latest' || matrix.os == 'macos-14' }}"
# we need coreutils on max for the `timeout` command
run: brew install fish zsh coreutils
# need cmake to build the rust deps
# need coreutils on max for the `timeout` command
run: brew install fish zsh coreutils cmake
- run: deno task test

test-action:
Expand Down
19 changes: 10 additions & 9 deletions src/ghjk/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ impl Config {
let xdg_dirs = directories::ProjectDirs::from("", "", "ghjk")
.expect_or_log("unable to resolve home dir");

let ghjkdir_path = match path_from_env(&cwd, "GHJK_DIR").await? {
let ghjkdir_path = match path_from_env(&cwd, "GHJK_DIR")? {
Some(val) => Some(val),
None => crate::utils::find_entry_recursive(&cwd, ".ghjk")
.await
.wrap_err("error trying to locate a .ghjk dir")?,
};

let ghjkfile_path = match path_from_env(&cwd, "GHJKFILE").await? {
let ghjkfile_path = match path_from_env(&cwd, "GHJKFILE")? {
Some(val) => Some(val),
None => {
// NOTE: look for typescript ghjkfile
Expand Down Expand Up @@ -102,7 +102,7 @@ impl Config {
},
};

let global_config_path = match path_from_env(&cwd, "GHJK_CONFIG_DIR").await? {
let global_config_path = match path_from_env(&cwd, "GHJK_CONFIG_DIR")? {
Some(val) => val,
None => xdg_dirs.config_dir().join("config"),
};
Expand Down Expand Up @@ -262,12 +262,12 @@ hash.json",

fn resolve_config_path(path: impl AsRef<Path>, config_path: &Path) -> Res<PathBuf> {
let path = config_path.join(&path);
let path = std::fs::canonicalize(&path)
.wrap_err_with(|| format!("error canonicalizing path at {path:?}"))?;
let path = std::path::absolute(&path)
.wrap_err_with(|| format!("error absolutizing path at {path:?}"))?;
Ok(path)
}

async fn path_from_env(cwd: &Path, env_name: &str) -> Res<Option<PathBuf>> {
fn path_from_env(cwd: &Path, env_name: &str) -> Res<Option<PathBuf>> {
let path = match std::env::var(env_name) {
Ok(path) => Some(PathBuf::from(path)),
Err(std::env::VarError::NotUnicode(os_str)) => Some(PathBuf::from(os_str)),
Expand All @@ -276,9 +276,10 @@ async fn path_from_env(cwd: &Path, env_name: &str) -> Res<Option<PathBuf>> {

if let Some(path) = path {
let path = cwd.join(&path);
Ok(Some(tokio::fs::canonicalize(&path).await.wrap_err_with(
|| format!("error canonicalizing path {path:?} from env ${env_name}"),
)?))

Ok(Some(std::path::absolute(&path).wrap_err_with(|| {
format!("error absolutizing path {path:?} from env ${env_name}")
})?))
} else {
Ok(None)
}
Expand Down

0 comments on commit a592188

Please sign in to comment.