Skip to content

Update to use GitHub's environment files #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/Download.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
* LICENSE.txt file in the root directory of this source tree.
*/

import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.file.StandardOpenOption.APPEND;
import static java.nio.file.StandardOpenOption.CREATE;
import static java.nio.file.StandardOpenOption.WRITE;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -218,7 +223,24 @@ Optional<String> findRemoteChecksum(String checksum) throws Exception {
static class GitHub {
/** Sets an action's output parameter. */
static void setOutput(String name, Object value) {
System.out.printf("::set-output name=%s::%s%n", name, value);
if (name.isBlank() || value.toString().isBlank()) { // implicit null checks included
throw new IllegalArgumentException("name or value are blank: " + name + "=" + value);
}
var githubEnv = System.getenv("GITHUB_ENV");
if (githubEnv == null) {
throw new AssertionError("No such environment variable: GITHUB_ENV");
}
try {
var file = Path.of(githubEnv);
if (file.getParent() != null) Files.createDirectories(file.getParent());
var lines = (name + "=" + value).lines().toList();
if (lines.size() != 1) {
throw new UnsupportedOperationException("Multiline strings are no supported");
}
Files.write(file, lines, UTF_8, CREATE, APPEND, WRITE);
} catch (IOException exception) {
throw new UncheckedIOException(exception);
}
}

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