chia7712 commented on code in PR #16948:
URL: https://github.com/apache/kafka/pull/16948#discussion_r1725724743
##########
.github/workflows/pr.yml:
##########
@@ -47,6 +50,22 @@ jobs:
- name: Compile and validate
# Publish build scans for now. This will only work on PRs from
apache/kafka, not public forks.
run: ./gradlew --build-cache --info --scan check -x test
+ - name: Archive check reports
+ if: always()
+ uses: actions/upload-artifact@v4
+ with:
+ name: check-reports-${{ matrix.java }}
+ path: |
+ **/build/**/*.html
+ if-no-files-found: ignore
+ - name: Annotate checkstyle errors
+ if: ${{ failure() && matrix.java == '21' }} # Avoid duplicate
annotations, only process java 21
+ run: python .github/scripts/checkstyle.py
+ env:
+ GITHUB: 1
+ GITHUB_WORKSPACE: ${{ github.workspace }}
+ GITHUB_REPOSITORY: ${{ github.repository }}
Review Comment:
not sure why we need to set `GITHUB_REPOSITORY` and `GITHUB_BRANCH`
##########
.github/workflows/pr.yml:
##########
@@ -31,22 +31,45 @@ jobs:
strategy:
fail-fast: false
matrix:
- java: [ 8, 11, 17, 21 ]
+ java: [ 21, 8, 11, 17 ]
name: Compile and Check Java ${{ matrix.java }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials: false
+ - uses: actions/setup-python@v5
+ with:
+ python-version: '3.12'
- name: Setup Gradle
uses: ./.github/actions/setup-gradle
with:
java-version: ${{ matrix.java }}
gradle-cache-read-only: true
develocity-access-key: ${{ secrets.GE_ACCESS_TOKEN }}
- name: Compile and validate
- # Publish build scans for now. This will only work on PRs from
apache/kafka, not public forks.
+ # Gradle flags
+ # --build-cache: Let Gradle restore the build cache
+ # --info: For now, we'll generate lots of logs while setting
up the GH Actions
Review Comment:
happy to know the purpose of `--info`
##########
settings.gradle:
##########
@@ -45,7 +45,7 @@ develocity {
buildCache {
local {
- enabled = !isCI
+ enabled = !isJenkins
Review Comment:
could you please add comment for this change?
##########
.github/workflows/pr.yml:
##########
@@ -31,22 +31,47 @@ jobs:
strategy:
fail-fast: false
matrix:
- java: [ 8, 11, 17, 21 ]
+ java: [ 21, 8, 11, 17 ]
name: Compile and Check Java ${{ matrix.java }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials: false
+ - uses: actions/setup-python@v5
+ with:
+ python-version: '3.12'
- name: Setup Gradle
uses: ./.github/actions/setup-gradle
with:
java-version: ${{ matrix.java }}
gradle-cache-read-only: true
develocity-access-key: ${{ secrets.GE_ACCESS_TOKEN }}
- name: Compile and validate
- # Publish build scans for now. This will only work on PRs from
apache/kafka, not public forks.
- run: ./gradlew --build-cache --info --scan check -x test
+ # Gradle flags
+ # --build-cache: Let Gradle restore the build cache
+ # --info: For now, we'll generate lots of logs while setting
up the GH Actions
+ # --scan: Attempt to publish build scans in PRs. This will
only work on PRs from apache/kafka, not public forks.
+ # spotlessCheck: Skip spotless. While it is faster than checkstyle,
it does not produce a report
+ # which makes it a bit less useful when running on CI.
+ run: ./gradlew --build-cache --info --scan check -x test -x
spotlessCheck
Review Comment:
Disabling the `spotlessCheck` may misdirect us to merge a PR with imports
error. The "import order" check of `spotless` is different from `checkstyle`.
`spotless` has stricter check than `checkstyle`
##########
.github/scripts/checkstyle.py:
##########
@@ -0,0 +1,98 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from glob import glob
+import logging
+import os
+import os.path
+import sys
+from typing import Tuple, Optional
+import xml.etree.ElementTree
+
+
+logger = logging.getLogger()
+logger.setLevel(logging.DEBUG)
+handler = logging.StreamHandler(sys.stderr)
+handler.setLevel(logging.DEBUG)
+logger.addHandler(handler)
+
+
+def get_env(key: str) -> str:
+ value = os.getenv(key)
+ logger.debug(f"Read env {key}: {value}")
+ return value
+
+
+def parse_report(workspace_path, fp) -> Tuple[int, int]:
+ stack = []
+ errors = []
+ file_count = 0
+ error_count = 0
+ for (event, elem) in xml.etree.ElementTree.iterparse(fp, events=["start",
"end"]):
+ if event == "start":
+ stack.append(elem)
+ if elem.tag == "file":
+ file_count += 1
+ errors.clear()
+ if elem.tag == "error":
+ logger.debug(f"Found checkstyle error: {elem.attrib}")
+ errors.append(elem)
+ error_count += 1
+ elif event == "end":
+ if elem.tag == "file" and len(errors) > 0:
+ filename = elem.get("name")
+ rel_path = os.path.relpath(filename, workspace_path)
+ logger.debug(f"Outputting errors for file: {elem.attrib}")
+ for error in errors:
+ line = error.get("line")
+ col = error.get("column")
+ severity = error.get("severity")
+ message = error.get('message')
+ title = f"Checkstyle {severity}"
+ print(f"::notice
file={rel_path},line={line},col={col},title={title}::{message}")
+ stack.pop()
+ else:
+ logger.error(f"Unhandled xml event {event}: {elem}")
+ return file_count, error_count
+
+
+if __name__ == "__main__":
+ """
+ Parse checkstyle XML reports and generate GitHub annotations.
Review Comment:
I do love this script, but have you considered using existent Github action?
like https://github.com/jwgmeligmeyling/checkstyle-github-action
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]