From 1f49d2cd78faac7ee5c4e4d1622a8f81ac2f54a1 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Mon, 27 Jul 2026 09:26:10 -0400 Subject: [PATCH] feat: add is_github_actions env helper Introduce a new public `is_github_actions()` API that detects GitHub Actions by checking for the `GITHUB_ACTIONS` environment variable. The implementation is added in `env.cpp`, documented in the public header, covered with tests for both present and missing variable cases, and shown in the README usage example. --- README.md | 4 ++++ src/common/env.cpp | 5 +++++ src/include/lizardbyte/common/env.h | 6 ++++++ tests/cpp/test_env.cpp | 14 ++++++++++++++ 4 files changed, 29 insertions(+) diff --git a/README.md b/README.md index 0077ce9..d28b6b5 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/src/common/env.cpp b/src/common/env.cpp index a6fe184..b7eec45 100644 --- a/src/common/env.cpp +++ b/src/common/env.cpp @@ -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; diff --git a/src/include/lizardbyte/common/env.h b/src/include/lizardbyte/common/env.h index d68e5a3..73abf76 100644 --- a/src/include/lizardbyte/common/env.h +++ b/src/include/lizardbyte/common/env.h @@ -8,6 +8,12 @@ #include 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. diff --git a/tests/cpp/test_env.cpp b/tests/cpp/test_env.cpp index bd73faa..f3de107 100644 --- a/tests/cpp/test_env.cpp +++ b/tests/cpp/test_env.cpp @@ -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: @@ -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};