Skip to content

Commit c01334f

Browse files
feat: add is_github_actions env helper (#40)
1 parent 070f94c commit c01334f

4 files changed

Lines changed: 29 additions & 0 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ std::string value;
7575
if (lizardbyte::common::get_env("MY_ENV", value)) {
7676
lizardbyte::common::append_env("MY_ENV", "suffix", ";");
7777
}
78+
79+
if (lizardbyte::common::is_github_actions()) {
80+
// Apply GitHub Actions-specific behavior.
81+
}
7882
```
7983

8084
The optional test support target is available when `BUILD_TESTS=ON` or `LIZARDBYTE_COMMON_BUILD_TEST_SUPPORT=ON`.

src/common/env.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ namespace lizardbyte::common {
1717
}
1818
} // namespace
1919

20+
bool is_github_actions() {
21+
std::string value;
22+
return get_env("GITHUB_ACTIONS", value);
23+
}
24+
2025
bool get_env(const std::string &name, std::string &value) {
2126
if (!is_valid_name(name)) {
2227
return false;

src/include/lizardbyte/common/env.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
#include <string>
99

1010
namespace lizardbyte::common {
11+
/**
12+
* @brief Check whether the current process is running in GitHub Actions.
13+
* @return true if the ``GITHUB_ACTIONS`` environment variable exists, false otherwise.
14+
*/
15+
[[nodiscard]] bool is_github_actions();
16+
1117
/**
1218
* @brief Get an environment variable.
1319
* @param name The name of the environment variable.

tests/cpp/test_env.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
namespace {
1717
constexpr auto test_env_name {"LIZARDBYTE_COMMON_TEST_ENV"};
18+
constexpr auto github_actions_env_name {"GITHUB_ACTIONS"};
1819

1920
class EnvGuard {
2021
public:
@@ -39,6 +40,19 @@ namespace {
3940
};
4041
} // namespace
4142

43+
TEST(EnvTest, GitHubActionsIsFalseWhenEnvironmentVariableIsMissing) {
44+
EnvGuard guard {github_actions_env_name};
45+
46+
EXPECT_FALSE(lizardbyte::common::is_github_actions());
47+
}
48+
49+
TEST(EnvTest, GitHubActionsIsTrueWhenEnvironmentVariableExists) {
50+
EnvGuard guard {github_actions_env_name};
51+
52+
ASSERT_EQ(lizardbyte::common::set_env(github_actions_env_name, "true"), 0);
53+
EXPECT_TRUE(lizardbyte::common::is_github_actions());
54+
}
55+
4256
TEST(EnvTest, GetEnvReturnsFalseForMissingVariable) {
4357
EnvGuard guard {test_env_name};
4458

0 commit comments

Comments
 (0)