Skip to content

Commit b867927

Browse files
committed
Update to use GitHub's environment files
Fixes #43
1 parent 683d974 commit b867927

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/Download.java

+23-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
* LICENSE.txt file in the root directory of this source tree.
66
*/
77

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+
813
import java.io.BufferedInputStream;
914
import java.io.FileInputStream;
1015
import java.io.IOException;
@@ -218,7 +223,24 @@ Optional<String> findRemoteChecksum(String checksum) throws Exception {
218223
static class GitHub {
219224
/** Sets an action's output parameter. */
220225
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+
}
222244
}
223245

224246
/** Creates a debug message and prints the message to the log. */

0 commit comments

Comments
 (0)