Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ std::string value;
if (lizardbyte::common::get_env("MY_ENV", value)) {
lizardbyte::common::append_env("MY_ENV", "suffix", ";");
}

if (lizardbyte::common::is_github_actions()) {
// Apply GitHub Actions-specific behavior.
}
```

The optional test support target is available when `BUILD_TESTS=ON` or `LIZARDBYTE_COMMON_BUILD_TEST_SUPPORT=ON`.
Expand Down
5 changes: 5 additions & 0 deletions src/common/env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ namespace lizardbyte::common {
}
} // namespace

bool is_github_actions() {
std::string value;
return get_env("GITHUB_ACTIONS", value);
}

bool get_env(const std::string &name, std::string &value) {
if (!is_valid_name(name)) {
return false;
Expand Down
6 changes: 6 additions & 0 deletions src/include/lizardbyte/common/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
#include <string>

namespace lizardbyte::common {
/**
* @brief Check whether the current process is running in GitHub Actions.
* @return true if the ``GITHUB_ACTIONS`` environment variable exists, false otherwise.
*/
[[nodiscard]] bool is_github_actions();

/**
* @brief Get an environment variable.
* @param name The name of the environment variable.
Expand Down
14 changes: 14 additions & 0 deletions tests/cpp/test_env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace {
constexpr auto test_env_name {"LIZARDBYTE_COMMON_TEST_ENV"};
constexpr auto github_actions_env_name {"GITHUB_ACTIONS"};

class EnvGuard {
public:
Expand All @@ -39,6 +40,19 @@ namespace {
};
} // namespace

TEST(EnvTest, GitHubActionsIsFalseWhenEnvironmentVariableIsMissing) {
EnvGuard guard {github_actions_env_name};

EXPECT_FALSE(lizardbyte::common::is_github_actions());
}

TEST(EnvTest, GitHubActionsIsTrueWhenEnvironmentVariableExists) {
EnvGuard guard {github_actions_env_name};

ASSERT_EQ(lizardbyte::common::set_env(github_actions_env_name, "true"), 0);
EXPECT_TRUE(lizardbyte::common::is_github_actions());
}

TEST(EnvTest, GetEnvReturnsFalseForMissingVariable) {
EnvGuard guard {test_env_name};

Expand Down