-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set published-version github output after 'publish' task
- Loading branch information
1 parent
099f892
commit e2f1d1d
Showing
5 changed files
with
200 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/pl/allegro/tech/build/axion/release/infrastructure/github/GithubFacade.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package pl.allegro.tech.build.axion.release.infrastructure.github; | ||
|
||
import org.gradle.api.logging.Logger; | ||
import org.gradle.api.logging.Logging; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.nio.file.StandardOpenOption; | ||
|
||
public class GithubFacade { | ||
|
||
private static final Logger logger = Logging.getLogger(GithubFacade.class); | ||
private static final String GITHUB_ACTIONS = "GITHUB_ACTIONS"; | ||
private static final String GITHUB_OUTPUT = "GITHUB_OUTPUT"; | ||
|
||
public static void setOutputIfNotAlreadySet(String name, String value) { | ||
if (System.getenv().containsKey(GITHUB_ACTIONS)) { | ||
try { | ||
boolean alreadySet = Files.readAllLines(githubOutputPath()).stream() | ||
.anyMatch(line -> line.startsWith(name + "=")); | ||
|
||
if (!alreadySet) { | ||
setOutput(name, value); | ||
} | ||
} catch (IOException e) { | ||
logger.warn("Unable to the verify whether '{}' GitHub output is already set, cause: {}", name, e.getMessage()); | ||
} | ||
} | ||
} | ||
|
||
public static void setOutput(String name, String value) { | ||
if (System.getenv().containsKey(GITHUB_ACTIONS)) { | ||
try { | ||
Files.write( | ||
githubOutputPath(), | ||
String.format("%s=%s\n", name, value).getBytes(), | ||
StandardOpenOption.APPEND | ||
); | ||
} catch (IOException e) { | ||
logger.warn("Unable to the set '{}' GitHub output, cause: {}", name, e.getMessage()); | ||
} | ||
} | ||
} | ||
|
||
private static Path githubOutputPath() { | ||
return Paths.get(System.getenv(GITHUB_OUTPUT)); | ||
} | ||
} |