File tree Expand file tree Collapse file tree
include/lizardbyte/common Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -75,6 +75,10 @@ std::string value;
7575if (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
8084The optional test support target is available when ` BUILD_TESTS=ON ` or ` LIZARDBYTE_COMMON_BUILD_TEST_SUPPORT=ON ` .
Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff line change 88#include < string>
99
1010namespace 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.
Original file line number Diff line number Diff line change 1515
1616namespace {
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+
4256TEST (EnvTest, GetEnvReturnsFalseForMissingVariable) {
4357 EnvGuard guard {test_env_name};
4458
You can’t perform that action at this time.
0 commit comments