Skip to content

Commit

Permalink
consider GITHUB_WORKSPACE env var
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitri Rusin committed Nov 14, 2023
1 parent b355c3b commit 28a6064
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions include/ioh/common/file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,7 @@ namespace ioh::common::file
}
}

/**
* @brief Get the absolute path of IOHexperimenter/static
*
* @return fs::path the absolute path of IOHexperimenter/static
*/

inline void print_environment_variables()
{
for (char** env = environ; *env != nullptr; ++env)
Expand All @@ -110,10 +106,13 @@ namespace ioh::common::file
}
}

inline fs::path get_static_root()
/**
* @brief Get the absolute path of IOHexperimenter/static
*
* @return fs::path the absolute path of IOHexperimenter/static
*/
fs::path get_static_root()
{
const char* env_var = std::getenv("IOH_RESOURCES");

// Print the contents of the current, previous, and the one before previous directories
print_directory_contents(fs::current_path());
print_directory_contents(fs::current_path() / "..");
Expand All @@ -122,12 +121,17 @@ namespace ioh::common::file
// Print environment variables to stdout and stderr
print_environment_variables();

if (env_var == nullptr)
const char* github_workspace = std::getenv("GITHUB_WORKSPACE");
if (github_workspace != nullptr)
{
// If GITHUB_WORKSPACE is set, append "static/" and return the canonical path
return fs::canonical(fs::path(github_workspace) / "static");
}
else
{
// If GITHUB_WORKSPACE is not set, return the canonical path of "../../static"
return fs::canonical(fs::current_path() / ".." / ".." / "static");
}

return fs::canonical(env_var);
}

/**
Expand Down

0 comments on commit 28a6064

Please sign in to comment.