From fdfca51cccc30b436f2f95724f9fb0a03041ed1d Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Tue, 2 Apr 2024 19:50:23 +0200 Subject: [PATCH 1/4] Use latest version of autograding-model. - Add optional limits for the line annotations. - Show Maven version and Git hash in output. --- README.md | 2 + action.yml | 10 ++++- doc/dependency-graph.puml | 4 +- pom.xml | 17 ++------ .../github/GitHubAnnotationsBuilder.java | 40 ++++++++++++++++++- .../github/GitHubAutoGradingRunner.java | 22 ++++++---- .../github/GitHubAnnotationBuilderTest.java | 2 +- .../GitHubAutoGradingRunnerDockerITest.java | 2 +- 8 files changed, 71 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index bd3ed2d..4581dbd 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,8 @@ This action can be configured using the following parameters (see example above) - ``pr-number: ${{ steps.pr.outputs.number }}``: optional number of the pull request. If not set, then just the checks will be published but not a pull request comment. - ``checks-name: "Name of checks"``: optional name of GitHub checks (overwrites the default: "Autograding result"). - ``skip-annotations: true``: Optional flag to skip the creation of annotations (for warnings and missed coverage). +- ``max-warning-comments: ``: Optional parameter to limit the number of warning comments at specific lines. By default, all line comments are created. +- ``max-coverage-comments: ``: Optional parameter to limit the number of coverage comments at specific lines. By default, all line comments are created. ## Metrics Configuration diff --git a/action.yml b/action.yml index d3591b5..344f417 100644 --- a/action.yml +++ b/action.yml @@ -17,16 +17,24 @@ inputs: skip-annotations: description: "Skip the creation of annotations (for warnings and missed coverage) if not empty" required: false + max-warning-annotations: + description: "Limit the number of warning annotations at specific lines. By default, all annotations are created." + required: false + max-coverage-annotations: + description: "Limit the number of coverage annotations at specific lines. By default, all annotations are created." + required: false runs: using: 'docker' - image: 'docker://uhafner/autograding-github-action:3.18.0' + image: 'docker://uhafner/autograding-github-action:3.19.0-SNAPSHOT' env: CONFIG: ${{ inputs.config }} CHECKS_NAME: ${{ inputs.checks-name }} PR_NUMBER: ${{ inputs.pr-number }} GITHUB_TOKEN: ${{ inputs.github-token }} SKIP_ANNOTATIONS: ${{ inputs.skip-annotations }} + MAX_WARNING_ANNOTATIONS: ${{ inputs.max-warning-annotations }} + MAX_COVERAGE_ANNOTATIONS: ${{ inputs.max-coverage-annotations }} branding: icon: check-square diff --git a/doc/dependency-graph.puml b/doc/dependency-graph.puml index 921b8ff..ffbf79a 100644 --- a/doc/dependency-graph.puml +++ b/doc/dependency-graph.puml @@ -42,7 +42,7 @@ rectangle "jackson-databind\n\n2.17.0" as com_fasterxml_jackson_core_jackson_dat rectangle "jackson-annotations\n\n2.17.0" as com_fasterxml_jackson_core_jackson_annotations_jar rectangle "jackson-core\n\n2.17.0" as com_fasterxml_jackson_core_jackson_core_jar rectangle "byte-buddy\n\n1.14.12" as net_bytebuddy_byte_buddy_jar -rectangle "autograding-github-action\n\n3.18.0" as edu_hm_hafner_autograding_github_action_jar +rectangle "autograding-github-action\n\n3.19.0-SNAPSHOT" as edu_hm_hafner_autograding_github_action_jar rectangle "github-api\n\n1.320" as org_kohsuke_github_api_jar rectangle "spotbugs-annotations\n\n4.8.3" as com_github_spotbugs_spotbugs_annotations_jar rectangle "error_prone_annotations\n\n2.25.0" as com_google_errorprone_error_prone_annotations_jar @@ -101,4 +101,4 @@ edu_hm_hafner_autograding_github_action_jar -[#000000]-> edu_hm_hafner_codingsty edu_hm_hafner_autograding_github_action_jar -[#000000]-> org_apache_commons_commons_lang3_jar edu_hm_hafner_autograding_github_action_jar -[#000000]-> commons_io_commons_io_jar edu_hm_hafner_autograding_github_action_jar -[#000000]-> net_bytebuddy_byte_buddy_jar -@enduml \ No newline at end of file +@enduml diff --git a/pom.xml b/pom.xml index 7d0cb26..7b35d21 100644 --- a/pom.xml +++ b/pom.xml @@ -5,13 +5,13 @@ edu.hm.hafner codingstyle-pom - 3.44.0 + 4.3.0 edu.hm.hafner autograding-github-action - 3.18.0 + 3.19.0-SAPSHOT jar @@ -30,7 +30,7 @@ 3.4.1 1.19.7 - 3.25.0 + 3.28.0 @@ -139,15 +139,6 @@ build - - - docker.io/uhafner/autograding-github-action:${docker-image-tag} - - ${env.DOCKER_IO_USERNAME} - ${env.DOCKER_IO_PASSWORD} - - - @@ -159,7 +150,7 @@ - maven:3.9.5-eclipse-temurin-21-alpine + maven:3.9.6-eclipse-temurin-21-alpine diff --git a/src/main/java/edu/hm/hafner/grading/github/GitHubAnnotationsBuilder.java b/src/main/java/edu/hm/hafner/grading/github/GitHubAnnotationsBuilder.java index ef4c197..7c0789d 100644 --- a/src/main/java/edu/hm/hafner/grading/github/GitHubAnnotationsBuilder.java +++ b/src/main/java/edu/hm/hafner/grading/github/GitHubAnnotationsBuilder.java @@ -3,6 +3,7 @@ import org.apache.commons.lang3.StringUtils; import edu.hm.hafner.grading.CommentBuilder; +import edu.hm.hafner.util.FilteredLog; import org.kohsuke.github.GHCheckRun.AnnotationLevel; import org.kohsuke.github.GHCheckRunBuilder.Annotation; @@ -19,11 +20,46 @@ class GitHubAnnotationsBuilder extends CommentBuilder { private static final String GITHUB_WORKSPACE_ABS = "/github/workspace/"; private final Output output; + private final FilteredLog log; + private final int maxWarningComments; + private final int maxCoverageComments; - GitHubAnnotationsBuilder(final Output output, final String prefix) { + GitHubAnnotationsBuilder(final Output output, final String prefix, final FilteredLog log) { super(prefix, GITHUB_WORKSPACE_REL, GITHUB_WORKSPACE_ABS); this.output = output; + this.log = log; + + maxWarningComments = getIntegerEnvironment("MAX_WARNING_ANNOTATIONS"); + log.logInfo(">>>> MAX_WARNING_ANNOTATIONS: ", getMaxWarningComments()); + + maxCoverageComments = getIntegerEnvironment("MAX_COVERAGE_ANNOTATIONS"); + log.logInfo(">>>> MAX_COVERAGE_ANNOTATIONS: ", getMaxCoverageComments()); + } + + @Override + protected int getMaxWarningComments() { + return maxWarningComments; + } + + @Override + protected int getMaxCoverageComments() { + return maxCoverageComments; + } + + private int getIntegerEnvironment(final String key) { + try { + return Integer.parseInt(getEnv(key)); + } + catch (NumberFormatException exception) { + log.logError(">>>> Error: no integer value"); + + return Integer.MAX_VALUE; + } + } + + private String getEnv(final String name) { + return StringUtils.defaultString(System.getenv(name)); } @Override @@ -32,7 +68,7 @@ protected void createComment(final CommentType commentType, final String relativ final int lineStart, final int lineEnd, final String message, final String title, final int columnStart, final int columnEnd, - final String details) { + final String details, final String markDownDetails) { Annotation annotation = new Annotation(relativePath, lineStart, lineEnd, AnnotationLevel.WARNING, message).withTitle(title); diff --git a/src/main/java/edu/hm/hafner/grading/github/GitHubAutoGradingRunner.java b/src/main/java/edu/hm/hafner/grading/github/GitHubAutoGradingRunner.java index ce939f1..63add6e 100644 --- a/src/main/java/edu/hm/hafner/grading/github/GitHubAutoGradingRunner.java +++ b/src/main/java/edu/hm/hafner/grading/github/GitHubAutoGradingRunner.java @@ -110,10 +110,12 @@ private void addComment(final AggregatedScore score, final String textSummary, .withStartedAt(Date.from(Instant.now())) .withConclusion(conclusion); - Output output = new Output(textSummary, markdownSummary).withText(markdownDetails); + var summaryWithFooter = markdownSummary + "\n\nCreated by " + getVersionLink(log); + Output output = new Output(textSummary, summaryWithFooter).withText(markdownDetails); if (getEnv("SKIP_ANNOTATIONS", log).isEmpty()) { - var annotationBuilder = new GitHubAnnotationsBuilder(output, computeAbsolutePathPrefixToRemove(log)); + var annotationBuilder = new GitHubAnnotationsBuilder( + output, computeAbsolutePathPrefixToRemove(log), log); annotationBuilder.createAnnotations(score); } @@ -124,9 +126,11 @@ private void addComment(final AggregatedScore score, final String textSummary, var prNumber = getEnv("PR_NUMBER", log); if (!prNumber.isBlank()) { // optional PR comment + var footer = "Created by %s. More details are shown in the [GitHub Checks Result](%s)." + .formatted(getVersionLink(log), run.getDetailsUrl().toString()); github.getRepository(repository) .getPullRequest(Integer.parseInt(prNumber)) - .comment(prSummary + addCheckLink(run)); + .comment(prSummary + "\n\n" + footer + "\n"); log.logInfo("Successfully commented PR#" + prNumber); } } @@ -135,6 +139,13 @@ private void addComment(final AggregatedScore score, final String textSummary, } } + private String getVersionLink(final FilteredLog log) { + var version = readVersion(log); + var sha = readSha(log); + return "[%s](https://github.com/uhafner/autograding-github-action/releases/tag/v%s) v%s (#%s)" + .formatted(getDisplayName(), version, version, sha); + } + String createEnvironmentVariables(final AggregatedScore score, final FilteredLog log) { var metrics = new StringBuilder(); score.getMetrics().forEach((metric, value) -> metrics.append(String.format("%s=%d%n", metric, value))); @@ -154,11 +165,6 @@ private String computeAbsolutePathPrefixToRemove(final FilteredLog log) { StringUtils.substringAfter(getEnv("GITHUB_REPOSITORY", log), "/")); } - private String addCheckLink(final GHCheckRun run) { - return String.format("%n%n More details are available in the [GitHub Checks Result](%s).%n", - run.getDetailsUrl().toString()); - } - private String getEnv(final String key, final FilteredLog log) { String value = StringUtils.defaultString(System.getenv(key)); log.logInfo(">>>> " + key + ": " + value); diff --git a/src/test/java/edu/hm/hafner/grading/github/GitHubAnnotationBuilderTest.java b/src/test/java/edu/hm/hafner/grading/github/GitHubAnnotationBuilderTest.java index 6a3a36e..150f500 100644 --- a/src/test/java/edu/hm/hafner/grading/github/GitHubAnnotationBuilderTest.java +++ b/src/test/java/edu/hm/hafner/grading/github/GitHubAnnotationBuilderTest.java @@ -16,7 +16,7 @@ void shouldSkipAnnotationsWhenEmpty() { var log = new FilteredLog("unused"); var output = mock(Output.class); - new GitHubAnnotationsBuilder(output, "/tmp").createAnnotations(new AggregatedScore("{}", log)); + new GitHubAnnotationsBuilder(output, "/tmp", log).createAnnotations(new AggregatedScore("{}", log)); verify(output, never()).add(any(Annotation.class)); } diff --git a/src/test/java/edu/hm/hafner/grading/github/GitHubAutoGradingRunnerDockerITest.java b/src/test/java/edu/hm/hafner/grading/github/GitHubAutoGradingRunnerDockerITest.java index e0ab26f..ba985e6 100644 --- a/src/test/java/edu/hm/hafner/grading/github/GitHubAutoGradingRunnerDockerITest.java +++ b/src/test/java/edu/hm/hafner/grading/github/GitHubAutoGradingRunnerDockerITest.java @@ -218,7 +218,7 @@ void shouldShowErrors() throws TimeoutException { } private GenericContainer createContainer() { - return new GenericContainer<>(DockerImageName.parse("uhafner/autograding-github-action:3.18.0")); + return new GenericContainer<>(DockerImageName.parse("uhafner/autograding-github-action:3.19.0-SNAPSHOT")); } private String readStandardOut(final GenericContainer> container) throws TimeoutException { From fff462d99b7ab47ace9fc1610c80159ade1707cf Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Wed, 3 Apr 2024 09:44:10 +0200 Subject: [PATCH 2/4] Update workflow. --- .github/workflows/autograding.yml | 87 --------------------------- .github/workflows/dogfood.yml | 97 ------------------------------- 2 files changed, 184 deletions(-) diff --git a/.github/workflows/autograding.yml b/.github/workflows/autograding.yml index e26835e..ce9d951 100644 --- a/.github/workflows/autograding.yml +++ b/.github/workflows/autograding.yml @@ -35,90 +35,3 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} pr-number: ${{ steps.pr.outputs.number }} checks-name: 'Quality Checks' - config: > - { - "tests": { - "tools": [ - { - "id": "test", - "name": "Unittests", - "pattern": "**/target/*-reports/TEST*.xml" - } - ], - "name": "JUnit", - "passedImpact": 0, - "skippedImpact": -1, - "failureImpact": -5, - "maxScore": 100 - }, - "analysis": { - "name": "Warnings", - "id": "warnings", - "tools": [ - { - "id": "checkstyle", - "name": "CheckStyle", - "pattern": "**/target/checkstyle-result.xml" - }, - { - "id": "pmd", - "name": "PMD", - "pattern": "**/target/pmd.xml" - }, - { - "id": "error-prone", - "name": "Error Prone", - "pattern": "**/maven.log" - }, - { - "id": "spotbugs", - "name": "SpotBugs", - "sourcePath": "src/main/java", - "pattern": "**/target/spotbugsXml.xml" - } - - ], - "errorImpact": -1, - "highImpact": -1, - "normalImpact": -1, - "lowImpact": -1, - "maxScore": 100 - }, - "coverage": [ - { - "tools": [ - { - "id": "jacoco", - "name": "Line Coverage", - "metric": "line", - "sourcePath": "src/main/java", - "pattern": "**/target/site/jacoco/jacoco.xml" - }, - { - "id": "jacoco", - "name": "Branch Coverage", - "metric": "branch", - "sourcePath": "src/main/java", - "pattern": "**/target/site/jacoco/jacoco.xml" - } - ], - "name": "JaCoCo", - "maxScore": 100, - "missedPercentageImpact": -1 - }, - { - "tools": [ - { - "id": "pit", - "name": "Mutation Coverage", - "metric": "mutation", - "sourcePath": "src/main/java", - "pattern": "**/target/pit-reports/mutations.xml" - } - ], - "name": "PIT", - "maxScore": 100, - "missedPercentageImpact": -1 - } - ] - } diff --git a/.github/workflows/dogfood.yml b/.github/workflows/dogfood.yml index af79036..b6aed7d 100644 --- a/.github/workflows/dogfood.yml +++ b/.github/workflows/dogfood.yml @@ -144,103 +144,6 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} checks-name: "Autograding GitHub Action" - config: > - { - "tests": { - "tools": [ - { - "id": "test", - "name": "Unittests", - "pattern": "**/target/*-reports/TEST*.xml" - } - ], - "name": "JUnit", - "passedImpact": 0, - "skippedImpact": -1, - "failureImpact": -5, - "maxScore": 100 - }, - "analysis": [ - { - "name": "Style", - "id": "style", - "tools": [ - { - "id": "checkstyle", - "name": "CheckStyle", - "pattern": "**/target/checkstyle-result.xml" - }, - { - "id": "pmd", - "name": "PMD", - "pattern": "**/target/pmd.xml" - } - ], - "errorImpact": 1, - "highImpact": 2, - "normalImpact": 3, - "lowImpact": 4, - "maxScore": 100 - }, - { - "name": "Bugs", - "id": "bugs", - "icon": "bug", - "tools": [ - { - "id": "spotbugs", - "name": "SpotBugs", - "sourcePath": "src/main/java", - "pattern": "**/target/spotbugsXml.xml" - } - ], - "errorImpact": -11, - "highImpact": -12, - "normalImpact": -13, - "lowImpact": -14, - "maxScore": 100 - } - ], - "coverage": [ - { - "tools": [ - { - "id": "jacoco", - "sourcePath": "src/main/java", - "name": "Line Coverage", - "metric": "line", - "pattern": "**/target/site/jacoco/jacoco.xml" - }, - { - "id": "jacoco", - "sourcePath": "src/main/java", - "name": "Branch Coverage", - "metric": "branch", - "pattern": "**/target/site/jacoco/jacoco.xml" - } - ], - "name": "JaCoCo", - "maxScore": 100, - "coveredPercentageImpact": 1, - "missedPercentageImpact": -1 - }, - { - "tools": [ - { - "id": "pit", - "name": "Mutation Coverage", - "metric": "mutation", - "sourcePath": "src/main/java", - "pattern": "**/target/pit-reports/mutations.xml" - } - ], - "name": "PIT", - "maxScore": 100, - "coveredPercentageImpact": 1, - "missedPercentageImpact": -1 - } - ] - } - name: Write metrics to GitHub output id: metrics run: | From 9ea15d03ef4e33b6f14d7ede871d3bde0fe1a439 Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Wed, 3 Apr 2024 10:04:51 +0200 Subject: [PATCH 3/4] Fix missing `%d` when logging the env variables. --- pom.xml | 2 +- .../hm/hafner/grading/github/GitHubAnnotationsBuilder.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 7b35d21..5fbb888 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ edu.hm.hafner autograding-github-action - 3.19.0-SAPSHOT + 3.19.0-SNAPSHOT jar diff --git a/src/main/java/edu/hm/hafner/grading/github/GitHubAnnotationsBuilder.java b/src/main/java/edu/hm/hafner/grading/github/GitHubAnnotationsBuilder.java index 7c0789d..5293d6e 100644 --- a/src/main/java/edu/hm/hafner/grading/github/GitHubAnnotationsBuilder.java +++ b/src/main/java/edu/hm/hafner/grading/github/GitHubAnnotationsBuilder.java @@ -31,10 +31,10 @@ class GitHubAnnotationsBuilder extends CommentBuilder { this.log = log; maxWarningComments = getIntegerEnvironment("MAX_WARNING_ANNOTATIONS"); - log.logInfo(">>>> MAX_WARNING_ANNOTATIONS: ", getMaxWarningComments()); + log.logInfo(">>>> MAX_WARNING_ANNOTATIONS: %d", getMaxWarningComments()); maxCoverageComments = getIntegerEnvironment("MAX_COVERAGE_ANNOTATIONS"); - log.logInfo(">>>> MAX_COVERAGE_ANNOTATIONS: ", getMaxCoverageComments()); + log.logInfo(">>>> MAX_COVERAGE_ANNOTATIONS: %d", getMaxCoverageComments()); } @Override From 839fca4ec8aac6e7f8f321eeacdeb6cf75508446 Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Wed, 3 Apr 2024 11:28:27 +0200 Subject: [PATCH 4/4] Fix naming of labeler. --- .github/workflows/sync-labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 786bb2e..e0ce7c9 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -9,7 +9,7 @@ on: - .github/workflows/sync-labels.yml jobs: - snyc-labels: + sync-labels: name: Sync labels runs-on: ubuntu-latest steps: