From 27d676a019242790943bc61eea71653635ded615 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Sat, 18 Jan 2025 11:43:27 +0100 Subject: [PATCH] Replace NativeBuildReport.java with report-status-in-issue action --- .github/NativeBuildReport.java | 100 ------------------------- .github/workflows/deploy-snapshots.yml | 16 ++-- 2 files changed, 6 insertions(+), 110 deletions(-) delete mode 100644 .github/NativeBuildReport.java diff --git a/.github/NativeBuildReport.java b/.github/NativeBuildReport.java deleted file mode 100644 index c8abe7169e..0000000000 --- a/.github/NativeBuildReport.java +++ /dev/null @@ -1,100 +0,0 @@ -//usr/bin/env jbang "$0" "$@" ; exit $? - -//DEPS org.kohsuke:github-api:1.128 -//DEPS info.picocli:picocli:4.6.1 - -import org.kohsuke.github.GitHub; -import org.kohsuke.github.GitHubBuilder; -import org.kohsuke.github.GHRepository; -import org.kohsuke.github.GHIssue; -import org.kohsuke.github.GHIssueComment; -import org.kohsuke.github.GHIssueState; -import picocli.CommandLine; -import picocli.CommandLine.Command; -import picocli.CommandLine.Option; -import picocli.CommandLine.Parameters; - -import java.io.File; -import java.io.IOException; -import java.io.UncheckedIOException; -import java.util.concurrent.TimeUnit; - -@Command(name = "report", mixinStandardHelpOptions = true, - description = "Takes care of updating the appropriate issue depending on the status of the build") -class Report implements Runnable { - - @Option(names = "token", description = "Github token to use when calling the Github API") - private String token; - - @Option(names = "status", description = "The status of the CI run") - private String status; - - @Option(names = "issueRepo", description = "The repository where the issue resides (i.e. quarkusio/quarkus)") - private String issueRepo; - - @Option(names = "issueNumber", description = "The issue to update") - private Integer issueNumber; - - @Option(names = "thisRepo", description = "The repository for which we are reporting the CI status") - private String thisRepo; - - @Option(names = "runId", description = "The ID of the Github Action run for which we are reporting the CI status") - private String runId; - - @Override - public void run() { - try { - final boolean succeed = "success".equalsIgnoreCase(status); - if ("cancelled".equalsIgnoreCase(status)) { - System.out.println("Job status is `cancelled` - exiting"); - System.exit(0); - } - - System.out.println(String.format("The CI build had status %s.", status)); - - final GitHub github = new GitHubBuilder().withOAuthToken(token).build(); - final GHRepository repository = github.getRepository(issueRepo); - - final GHIssue issue = repository.getIssue(issueNumber); - if (issue == null) { - System.out.println(String.format("Unable to find the issue %s in project %s", issueNumber, issueRepo)); - System.exit(-1); - } else { - System.out.println(String.format("Report issue found: %s - %s", issue.getTitle(), issue.getHtmlUrl().toString())); - System.out.println(String.format("The issue is currently %s", issue.getState().toString())); - } - - if (succeed) { - if (issue != null && isOpen(issue)) { - // close issue with a comment - final GHIssueComment comment = issue.comment(String.format("Build fixed:\n* Link to latest CI run: https://github.com/%s/actions/runs/%s", thisRepo, runId)); - issue.close(); - System.out.println(String.format("Comment added on issue %s - %s, the issue has also been closed", issue.getHtmlUrl().toString(), comment.getHtmlUrl().toString())); - } else { - System.out.println("Nothing to do - the build passed and the issue is already closed"); - } - } else { - if (isOpen(issue)) { - 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)); - System.out.println(String.format("Comment added on issue %s - %s", issue.getHtmlUrl().toString(), comment.getHtmlUrl().toString())); - } else { - issue.reopen(); - 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)); - System.out.println(String.format("Comment added on issue %s - %s, the issue has been re-opened", issue.getHtmlUrl().toString(), comment.getHtmlUrl().toString())); - } - } - } - catch (IOException e) { - throw new UncheckedIOException(e); - } - } - - private static boolean isOpen(GHIssue issue) { - return (issue.getState() == GHIssueState.OPEN); - } - - public static void main(String... args) { - int exitCode = new CommandLine(new Report()).execute(args); - System.exit(exitCode); - } -} \ No newline at end of file diff --git a/.github/workflows/deploy-snapshots.yml b/.github/workflows/deploy-snapshots.yml index 1ff58daf82..774ad8f39a 100644 --- a/.github/workflows/deploy-snapshots.yml +++ b/.github/workflows/deploy-snapshots.yml @@ -57,14 +57,10 @@ jobs: run: rm -r ~/.m2/repository/io/quarkus/platform ~/.m2/repository/io/quarkus/quarkus-universe-bom - name: Report + uses: quarkusio/report-status-in-issue@main if: always() - shell: bash - run: | - curl -Ls https://sh.jbang.dev | bash -s - app setup - ~/.jbang/bin/jbang .github/NativeBuildReport.java \ - issueNumber=35716 \ - runId=${{ github.run_id }} \ - status=${{ job.status }} \ - token=${{ secrets.ECOSYSTEM_CI_TOKEN }} \ - issueRepo=quarkusio/quarkus \ - thisRepo=${{ github.repository }} + with: + github-token: ${{ secrets.ECOSYSTEM_CI_TOKEN }} + status: ${{ job.status }} + issue-repository: quarkusio/quarkus + issue-number: 35716