|
5 | 5 | * LICENSE.txt file in the root directory of this source tree.
|
6 | 6 | */
|
7 | 7 |
|
| 8 | +import static java.nio.charset.StandardCharsets.UTF_8; |
| 9 | +import static java.nio.file.StandardOpenOption.APPEND; |
| 10 | +import static java.nio.file.StandardOpenOption.CREATE; |
| 11 | +import static java.nio.file.StandardOpenOption.WRITE; |
| 12 | + |
8 | 13 | import java.io.BufferedInputStream;
|
9 | 14 | import java.io.FileInputStream;
|
10 | 15 | import java.io.IOException;
|
@@ -218,7 +223,24 @@ Optional<String> findRemoteChecksum(String checksum) throws Exception {
|
218 | 223 | static class GitHub {
|
219 | 224 | /** Sets an action's output parameter. */
|
220 | 225 | static void setOutput(String name, Object value) {
|
221 |
| - System.out.printf("::set-output name=%s::%s%n", name, value); |
| 226 | + if (name.isBlank() || value.toString().isBlank()) { // implicit null checks included |
| 227 | + throw new IllegalArgumentException("name or value are blank: " + name + "=" + value); |
| 228 | + } |
| 229 | + var githubEnv = System.getenv("GITHUB_ENV"); |
| 230 | + if (githubEnv == null) { |
| 231 | + throw new AssertionError("No such environment variable: GITHUB_ENV"); |
| 232 | + } |
| 233 | + try { |
| 234 | + var file = Path.of(githubEnv); |
| 235 | + if (file.getParent() != null) Files.createDirectories(file.getParent()); |
| 236 | + var lines = (name + "=" + value).lines().toList(); |
| 237 | + if (lines.size() != 1) { |
| 238 | + throw new UnsupportedOperationException("Multiline strings are no supported"); |
| 239 | + } |
| 240 | + Files.write(file, lines, UTF_8, CREATE, APPEND, WRITE); |
| 241 | + } catch (IOException exception) { |
| 242 | + throw new UncheckedIOException(exception); |
| 243 | + } |
222 | 244 | }
|
223 | 245 |
|
224 | 246 | /** Creates a debug message and prints the message to the log. */
|
|
0 commit comments