Skip to content

Commit

Permalink
Merge branch 'trunk' into KAFKA-16437
Browse files Browse the repository at this point in the history
  • Loading branch information
cshannon committed Sep 18, 2024
2 parents 1e4e7ae + 77e9526 commit 935f2b2
Show file tree
Hide file tree
Showing 1,305 changed files with 65,350 additions and 31,542 deletions.
59 changes: 59 additions & 0 deletions .github/actions/gh-api-update-status/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# 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.
#
---
name: "Update Commit Status Check"
description: "Update the status of a commit check using the GH CLI"
inputs:
gh-token:
description: "The GitHub token for use with the CLI"
required: true
repository:
description: "The GitHub repository"
required: true
default: "apache/kafka"
commit_sha:
description: "The SHA of the commit we are updating"
required: true
url:
description: "The URL of the status check"
required: false
default: ""
description:
description: "The text to display next to the check"
default: ""
required: false
context:
description: "The name of the status check"
required: true
state:
description: "The state of the check. Can be one of: error, failure, pending, success"
required: true

runs:
using: "composite"
steps:
- name: Update Check
shell: bash
env:
GH_TOKEN: ${{ inputs.gh-token }}
run: |
gh api --method POST -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" \
/repos/${{ inputs.repository }}/statuses/${{ inputs.commit_sha }} \
-f "state=${{ inputs.state }}" -f "target_url=${{ inputs.url }}" \
-f "description=${{ inputs.description }}" \
-f "context=${{ inputs.context }}"
57 changes: 57 additions & 0 deletions .github/actions/setup-gradle/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# 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.
#
---
name: "Gradle Setup"
description: "Setup Java and Gradle"
inputs:
java-version:
description: "Java version to use"
default: "17"
gradle-cache-read-only:
description: "Should the Gradle cache be read-only?"
default: "true"
gradle-cache-write-only:
description: "Should the Gradle cache be write-only?"
default: "false"
develocity-access-key:
description: "Optional access key for uploading build scans to Develocity"
default: ""
runs:
using: "composite"
steps:
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: ${{ inputs.java-version }}
- name: Setup Gradle
uses: gradle/actions/setup-gradle@d156388eb19639ec20ade50009f3d199ce1e2808 # v4.1.0
env:
GRADLE_BUILD_ACTION_CACHE_DEBUG_ENABLED: true
with:
gradle-version: wrapper
develocity-access-key: ${{ inputs.develocity-access-key }}
develocity-token-expiry: 4
cache-read-only: ${{ inputs.gradle-cache-read-only }}
cache-write-only: ${{ inputs.gradle-cache-write-only }}
# Cache downloaded JDKs in addition to the default directories.
gradle-home-cache-includes: |
caches
notifications
jdks
cache-cleanup: on-success
98 changes: 98 additions & 0 deletions .github/scripts/checkstyle.py
Original file line number Diff line number Diff line change
@@ -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.
See: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-a-notice-message
"""
if not os.getenv("GITHUB_WORKSPACE"):
print("This script is intended to by run by GitHub Actions.")
exit(1)

reports = glob(pathname="**/checkstyle/*.xml", recursive=True)
logger.debug(f"Found {len(reports)} checkstyle reports")
total_file_count = 0
total_error_count = 0

workspace_path = get_env("GITHUB_WORKSPACE") # e.g., /home/runner/work/apache/kafka

for report in reports:
with open(report, "r") as fp:
logger.debug(f"Parsing report file: {report}")
file_count, error_count = parse_report(workspace_path, fp)
if error_count == 1:
logger.debug(f"Checked {file_count} files from {report} and found 1 error")
else:
logger.debug(f"Checked {file_count} files from {report} and found {error_count} errors")
total_file_count += file_count
total_error_count += error_count
exit(0)
Loading

0 comments on commit 935f2b2

Please sign in to comment.