Skip to content

Commit f3142b2

Browse files
committed
Replace kscript with jbang for cron job
This is needed because kscript doesn't work well with Java 11
1 parent 111134e commit f3142b2

File tree

3 files changed

+103
-112
lines changed

3 files changed

+103
-112
lines changed

.github/NativeBuildReport.java

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
//usr/bin/env jbang "$0" "$@" ; exit $?
2+
3+
//DEPS org.kohsuke:github-api:1.101
4+
//DEPS info.picocli:picocli:4.2.0
5+
6+
import org.kohsuke.github.GitHub;
7+
import org.kohsuke.github.GitHubBuilder;
8+
import org.kohsuke.github.GHRepository;
9+
import org.kohsuke.github.GHIssue;
10+
import org.kohsuke.github.GHIssueComment;
11+
import org.kohsuke.github.GHIssueState;
12+
import picocli.CommandLine;
13+
import picocli.CommandLine.Command;
14+
import picocli.CommandLine.Option;
15+
import picocli.CommandLine.Parameters;
16+
17+
import java.io.File;
18+
import java.io.IOException;
19+
import java.io.UncheckedIOException;
20+
import java.util.concurrent.TimeUnit;
21+
22+
@Command(name = "report", mixinStandardHelpOptions = true,
23+
description = "Takes care of updating the appropriate issue depending on the status of the build")
24+
class Report implements Runnable {
25+
26+
@Option(names = "token", description = "Github token to use when calling the Github API")
27+
private String token;
28+
29+
@Option(names = "status", description = "The status of the CI run")
30+
private String status;
31+
32+
@Option(names = "issueRepo", description = "The repository where the issue resides (i.e. quarkusio/quarkus)")
33+
private String issueRepo;
34+
35+
@Option(names = "issueNumber", description = "The issue to update")
36+
private Integer issueNumber;
37+
38+
@Option(names = "thisRepo", description = "The repository for which we are reporting the CI status")
39+
private String thisRepo;
40+
41+
@Option(names = "runId", description = "The ID of the Github Action run for which we are reporting the CI status")
42+
private String runId;
43+
44+
@Override
45+
public void run() {
46+
try {
47+
final boolean succeed = "success".equalsIgnoreCase(status);
48+
if ("cancelled".equalsIgnoreCase(status)) {
49+
System.out.println("Job status is `cancelled` - exiting");
50+
System.exit(0);
51+
}
52+
53+
System.out.println(String.format("The CI build had status %s.", status));
54+
55+
final GitHub github = new GitHubBuilder().withOAuthToken(token).build();
56+
final GHRepository repository = github.getRepository(issueRepo);
57+
58+
final GHIssue issue = repository.getIssue(issueNumber);
59+
if (issue == null) {
60+
System.out.println(String.format("Unable to find the issue %s in project %s", issueNumber, issueRepo));
61+
System.exit(-1);
62+
} else {
63+
System.out.println(String.format("Report issue found: %s - %s", issue.getTitle(), issue.getHtmlUrl().toString()));
64+
System.out.println(String.format("The issue is currently %s", issue.getState().toString()));
65+
}
66+
67+
if (succeed) {
68+
if (issue != null && isOpen(issue)) {
69+
// close issue with a comment
70+
final GHIssueComment comment = issue.comment(String.format("Build fixed:\n* Link to latest CI run: https://github.com/%s/actions/runs/%s", thisRepo, runId));
71+
issue.close();
72+
System.out.println(String.format("Comment added on issue %s - %s, the issue has also been closed", issue.getHtmlUrl().toString(), comment.getHtmlUrl().toString()));
73+
} else {
74+
System.out.println("Nothing to do - the build passed and the issue is already closed");
75+
}
76+
} else {
77+
if (isOpen(issue)) {
78+
final GHIssueComment comment = issue.comment(String.format("The build is still failing:\n* Link to latest CI run: https://github.com/%s/actions/runs/%s", thisRepo, runId));
79+
System.out.println(String.format("Comment added on issue %s - %s", issue.getHtmlUrl().toString(), comment.getHtmlUrl().toString()));
80+
} else {
81+
issue.reopen();
82+
final GHIssueComment comment = issue.comment(String.format("Unfortunately, the build failed:\n* Link to latest CI run: https://github.com/%s/actions/runs/%s", thisRepo, runId));
83+
System.out.println(String.format("Comment added on issue %s - %s, the issue has been re-opened", issue.getHtmlUrl().toString(), comment.getHtmlUrl().toString()));
84+
}
85+
}
86+
}
87+
catch (IOException e) {
88+
throw new UncheckedIOException(e);
89+
}
90+
}
91+
92+
private static boolean isOpen(GHIssue issue) {
93+
return (issue.getState() == GHIssueState.OPEN);
94+
}
95+
96+
public static void main(String... args) {
97+
int exitCode = new CommandLine(new Report()).execute(args);
98+
System.exit(exitCode);
99+
}
100+
}

.github/NativeBuildReport.kts

-108
This file was deleted.

.github/workflows/native-build-development.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,12 @@ jobs:
8686
GITHUB_TOKEN: ${{ secrets.GITHUB_API_TOKEN }}
8787
STATUS: ${{ job.status }}
8888
run: |
89+
echo "The report step got status: ${STATUS}"
8990
sudo apt-get update -o Dir::Etc::sourcelist="sources.list" \
9091
-o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"
9192
sudo apt-get install -y gnupg2 gnupg-agent
9293
echo Installing SDKMAN
9394
curl -s "https://get.sdkman.io" | bash
9495
source ~/.sdkman/bin/sdkman-init.sh && \
95-
sdk install kotlin 1.3.61 && \
96-
sdk install kscript 2.9.0
97-
echo "The report step got status: ${STATUS}"
98-
kscript .github/NativeBuildReport.kts ${GITHUB_TOKEN} ${STATUS}
96+
sdk install jbang 0.36.1
97+
jbang .github/NativeBuildReport.java token="${GITHUB_TOKEN}" status="${STATUS}" issueRepo="quarkusio/quarkus" issueNumber="6588" thisRepo="${GITHUB_REPOSITORY}" runId="${GITHUB_RUN_ID}"

0 commit comments

Comments
 (0)