-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathRemoveCrazyMax.java
51 lines (47 loc) · 2.34 KB
/
RemoveCrazyMax.java
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
///usr/bin/env jbang "$0" "$@" ; exit $?
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.OptionalInt;
import java.util.stream.IntStream;
/**
* Remove the crazy-max/ghaction-import-gpg action from the release.yml workflow and update actions
*/
public class RemoveCrazyMax {
public static void main(String... args) throws Exception {
Path workflowFile = Path.of(".github/workflows/release.yml");
if (Files.exists(workflowFile)) {
List<String> lines = Files.readAllLines(workflowFile);
// Find the index of the line that ends with "Import GPG key"
OptionalInt indexOpt = IntStream.range(0, lines.size())
.filter(i -> lines.get(i).endsWith("Import GPG key"))
.findFirst();
if (indexOpt.isPresent()) {
int index = indexOpt.getAsInt();
int end = index;
while (end != lines.size() && !lines.get(end).endsWith("passphrase: ${{ secrets.GPG_PASSPHRASE }}")) {
end++;
}
lines.subList(index, end + 2).clear();
}
indexOpt = IntStream.range(0, lines.size()).filter(i -> lines.get(i).endsWith("server-password: MAVEN_PASSWORD")).findFirst();
if (indexOpt.isPresent()) {
int index = indexOpt.getAsInt();
lines.add(index + 1, " gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}");
lines.add(index + 2, " gpg-passphrase: MAVEN_GPG_PASSPHRASE");
}
indexOpt = IntStream.range(0, lines.size()).filter(i -> lines.get(i).endsWith("MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}")).findFirst();
if (indexOpt.isPresent()) {
int index = indexOpt.getAsInt();
lines.add(index + 1, " MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}");
}
indexOpt = IntStream.range(0, lines.size()).filter(i -> lines.get(i).endsWith("- uses: actions/checkout@v3")).findFirst();
if (indexOpt.isPresent()) {
int index = indexOpt.getAsInt();
lines.set(index, lines.get(index).replace("v3", "v4"));
}
Files.write(workflowFile, lines, StandardCharsets.UTF_8);
}
}
}