1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
//! Logging methods for the output
use ;
use Write;
use ;
use crateEOL;
const LOG_DEBUG_ENV: &str = "LOG_DEBUG";
const LOG_WRITE_ENV: &str = "LOG_DEBUG_WRITE";
/// Struct which contains the parameters used for custom annotations.
///
/// This is used in the [notice_log], [warn_log] and [error_log]
///
/// ## Example use case
/// ```rust
/// # std::env::set_var("LOG_DEBUG", "true");
/// use actions_github::logger::{LogParameters, notice_log};
/// let params = LogParameters {
/// title: String::from("My example"),
/// file: String::from("src/lib.rs"),
/// line: 1,
/// end_line: 3
/// };
///
/// notice_log("There is a problem in the file", Some(params));
/// # assert_eq!(std::env::var("LOG_DEBUG_WRITE").unwrap(),
/// # "::notice file=src/lib.rs,line=1,endLine=3,title=My example::There is a problem in the file");
/// ```
/// Prints a debug message to the log.
///
/// Only visible if [debug logging is enabled](https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/enabling-debug-logging)
///
/// GitHub's documentation: [Setting a debug message](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-a-debug-message)
///
/// ## Example usage
///
/// ```rust
/// # std::env::set_var("LOG_DEBUG", "true");
/// use actions_github::logger;
/// logger::debug_log("Initializing the project");
/// # assert_eq!(std::env::var("LOG_DEBUG_WRITE").unwrap(), "::debug::Initializing the project")
/// ```
/// Logs regular information message
///
/// ## Example usage
///
/// ```rust
/// # std::env::set_var("LOG_DEBUG", "true");
/// use actions_github::logger;
/// logger::info(format!("Finished analyzing {}", "project").as_str());
/// # assert_eq!(std::env::var("LOG_DEBUG_WRITE").unwrap(), "Finished analyzing project")
/// ```
/// Creates a warning message and prints the message to the log.
///
/// This message will create an annotation.
///
/// GitHub's documentation: [Setting a warning message](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-a-warning-message)
///
/// ## Example usage
///
/// ```rust
/// # std::env::set_var("LOG_DEBUG", "true");
/// use actions_github::logger;
/// logger::warn_log("Missing name of project", None);
/// # assert_eq!(std::env::var("LOG_DEBUG_WRITE").unwrap(), "::warning::Missing name of project")
/// ```
///
/// ## Custom annotations
///
/// You can also set custom annotations to mention a specific line in a file.
/// See [LogParameters] for more info.
/// ```rust
/// # std::env::set_var("LOG_DEBUG", "true");
/// use actions_github::logger;
/// logger::warn_log("Missing name of project", Some(logger::LogParameters {
/// title: String::from("Missing name"),
/// file: String::from("src/lib.rs"),
/// line: 1,
/// end_line: 3
/// }));
/// # assert_eq!(std::env::var("LOG_DEBUG_WRITE").unwrap(),
/// # "::warning file=src/lib.rs,line=1,endLine=3,title=Missing name::Missing name of project")
/// ```
/// Creates an error message and prints the message to the log.
///
/// This message will create an annotation.
///
/// GitHub's documentation: [Setting an error message](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-error-message)
///
/// ## Example usage
///
/// ```rust
/// # std::env::set_var("LOG_DEBUG", "true");
/// use actions_github::logger;
/// logger::error_log("Did not find library", None);
/// # assert_eq!(std::env::var("LOG_DEBUG_WRITE").unwrap(), "::error::Did not find library");
/// ```
///
/// ### Custom annotations
///
/// You can also set custom annotations to mention a specific line in a file.
/// See [LogParameters] for more info.
/// ```rust
/// # std::env::set_var("LOG_DEBUG", "true");
/// use actions_github::logger;
/// logger::error_log("Did not find library", Some(logger::LogParameters {
/// title: String::from("Library missing"),
/// file: String::from("Cargo.toml"),
/// line: 4,
/// end_line: 7
/// }));
/// # assert_eq!(std::env::var("LOG_DEBUG_WRITE").unwrap(),
/// # "::error file=Cargo.toml,line=4,endLine=7,title=Library missing::Did not find library")
/// ```
/// Creates a notice message and prints the message to the log.
///
/// This message will create an annotation.
///
/// GitHub's Documentation: [Setting a notice message](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-a-notice-message)
///
/// ## Example usage
///
/// ```rust
/// # std::env::set_var("LOG_DEBUG", "true");
/// use actions_github::logger;
/// logger::notice_log("Step one is finished", None);
/// # assert_eq!(std::env::var("LOG_DEBUG_WRITE").unwrap(), "::notice::Step one is finished")
/// ```
///
/// ## Custom annotations
///
/// You can also set custom annotations to mention a specific line in a file.
/// See [LogParameters] for more info.
/// ```rust
/// # std::env::set_var("LOG_DEBUG", "true");
/// use actions_github::logger;
/// logger::notice_log("Step one is finished", Some(logger::LogParameters {
/// title: String::from("Step completed"),
/// file: String::from(".github/workflows/test.yml"),
/// line: 24,
/// end_line: 27
/// }));
/// # assert_eq!(std::env::var("LOG_DEBUG_WRITE").unwrap(),
/// # "::notice file=.github/workflows/test.yml,line=24,endLine=27,title=Step completed::Step one is finished")
/// ```
/// Returns if it's running on a debug runner.
///
/// If the `RUNNER_DEBUG` variable is not defined, it'll always return true
///
/// ```rust
/// use actions_github::logger::is_debug;
/// assert!(is_debug());
/// std::env::set_var("RUNNER_DEBUG", "0");
/// assert!(!is_debug());
/// ```