6
6
7
7
use Laminas \AutomaticReleases \Gpg \ImportGpgKeyFromString ;
8
8
use Laminas \AutomaticReleases \Gpg \SecretKeyId ;
9
- use Psl ;
10
- use Psl \Env ;
11
- use Psl \Iter ;
12
- use Psl \Str ;
9
+
10
+ use function Psl \Env \get_var ;
11
+ use function Psl \invariant ;
12
+ use function Psl \Iter \contains ;
13
+ use function Psl \Str \format ;
13
14
14
15
/** @psalm-immutable */
15
16
class EnvironmentVariables implements Variables
@@ -51,8 +52,8 @@ private function __construct(
51
52
private readonly string $ logLevel ,
52
53
) {
53
54
/** @psalm-suppress ImpureFunctionCall the {@see \Psl\Iter\contains()} API is conditionally pure */
54
- Psl \ invariant (
55
- Iter \ contains (self ::LOG_LEVELS , $ logLevel ),
55
+ invariant (
56
+ contains (self ::LOG_LEVELS , $ logLevel ),
56
57
'LOG_LEVEL env MUST be a valid monolog/monolog log level constant name or value; '
57
58
. ' see https://github.com/Seldaek/monolog/blob/master/doc/01-usage.md#log-levels ' ,
58
59
);
@@ -62,25 +63,33 @@ public static function fromEnvironment(ImportGpgKeyFromString $importKey): self
62
63
{
63
64
return new self (
64
65
self ::getenv ('GITHUB_TOKEN ' ),
65
- $ importKey-> __invoke (self ::getenv ('SIGNING_SECRET_KEY ' )),
66
+ ( $ importKey) (self ::getenv ('SIGNING_SECRET_KEY ' )),
66
67
self ::getenv ('GIT_AUTHOR_NAME ' ),
67
68
self ::getenv ('GIT_AUTHOR_EMAIL ' ),
68
69
self ::getenv ('GITHUB_EVENT_PATH ' ),
69
70
self ::getenv ('GITHUB_WORKSPACE ' ),
70
- self ::getenvWithFallback ('LOG_LEVEL ' , 'INFO ' ),
71
+ self ::getenvWithFallback (
72
+ 'LOG_LEVEL ' ,
73
+ self ::isDebugMode () ? 'DEBUG ' : 'INFO ' ,
74
+ ),
71
75
);
72
76
}
73
77
78
+ private static function isDebugMode (): bool
79
+ {
80
+ return get_var ('ACTIONS_RUNNER_DEBUG ' ) !== null ;
81
+ }
82
+
74
83
/**
75
84
* @psalm-param non-empty-string $key
76
85
*
77
86
* @psalm-return non-empty-string
78
87
*/
79
88
private static function getenv (string $ key ): string
80
89
{
81
- $ value = Env \ get_var ($ key );
90
+ $ value = get_var ($ key );
82
91
83
- Psl \ invariant ($ value !== null && $ value !== '' , Str \ format ('Could not find a value for environment variable "%s" ' , $ key ));
92
+ invariant ($ value !== null && $ value !== '' , format ('Could not find a value for environment variable "%s" ' , $ key ));
84
93
85
94
return $ value ;
86
95
}
@@ -93,7 +102,7 @@ private static function getenv(string $key): string
93
102
*/
94
103
private static function getenvWithFallback (string $ key , string $ default ): string
95
104
{
96
- $ value = Env \ get_var ($ key );
105
+ $ value = get_var ($ key );
97
106
98
107
return $ value === null || $ value === '' ? $ default : $ value ;
99
108
}
@@ -120,7 +129,6 @@ public function gitAuthorEmail(): string
120
129
121
130
public function githubEventPath (): string
122
131
{
123
- // @TODO test me
124
132
return $ this ->githubEventPath ;
125
133
}
126
134
0 commit comments