Skip to content

[protocol] Add positionBytes in KafkaInputMapperValue #1

[protocol] Add positionBytes in KafkaInputMapperValue

[protocol] Add positionBytes in KafkaInputMapperValue #1

name: Enforce Max Lines Added Per File
on:
pull_request:
branches:
- main
paths:
- '**/*.java' # Monitor changes to Java files
- '**/*.avsc' # Monitor changes to Avro schema files
- '**/*.proto' # Monitor changes to proto schema files
jobs:
enforce-lines-added:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Fetch PR Title via GitHub API
id: pr_details
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
PR_TITLE=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER" | jq -r '.title')
echo "pr_title=$PR_TITLE" >> $GITHUB_ENV
PR_DESCRIPTION=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ -H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER" | jq -r '.body')
{
echo "pr_description<<EOF"
echo "$PR_DESCRIPTION"
echo "EOF"
} >> "$GITHUB_ENV"
- name: Check for Override Keyword
id: check_override
run: |
# Define the keyword for override
OVERRIDE_KEYWORD="VALIDATION_OVERRIDE"
# Check PR title and body for the keyword
if printf "%s%s" "$pr_title$pr_description" | grep -iq "$OVERRIDE_KEYWORD"; then
echo "Override keyword found. Skipping validation."
echo "override=true" >> $GITHUB_OUTPUT
else
echo "override=false" >> $GITHUB_OUTPUT
fi
- name: Calculate Lines Added Per File
if: ${{ steps.check_override.outputs.override != 'true' }}
id: lines_added_per_file
run: |
# Define the maximum allowed lines added per file
MAX_LINES=500
MAX_TOTAL_LINES_ADDED=2000
TOTAL_LINES_ADDED=0
TOTAL_LINES_REMOVED=0
# Get the diff of the PR and process each file
EXCEEDED=false
JAVA_FILE=false
SCHEMA_FILE=false
while IFS=$'\t' read -r added removed file; do
# Skip test files
if [[ "$file" != *src/main* || "$file" == *test-common* ]]; then
echo "Skipping file: $file"
continue
fi
if [[ "$file" == *.java ]]; then
JAVA_FILE=true
else
SCHEMA_FILE=true
fi
# Calculate total lines added for the file
ADDED_IN_FILE=$((added))
REMOVED_IN_FILE=$((removed))
TOTAL_LINES_ADDED=$((TOTAL_LINES_ADDED + added))
TOTAL_LINES_REMOVED=$((TOTAL_LINES_REMOVED + removed))
echo "File: $file, lines removed: $REMOVED_IN_FILE, lines added: $ADDED_IN_FILE"
# Fail if there are both schema and Java file changes
if [[ "$JAVA_FILE" == true && "$SCHEMA_FILE" == true ]]; then
echo "The PR has both schema and Java code changes, please make a separate PR for schema changes."
echo "For schema file changes, please update build.gradle to update 'versionOverrides' inside compileAvro task to use fixed protocol version"
exit 1
fi
if [[ "$ADDED_IN_FILE" -gt "$MAX_LINES" && "$JAVA_FILE" == "true" ]]; then
echo "File $file exceeds the maximum allowed lines added ($ADDED_IN_FILE > $MAX_LINES)"
EXCEEDED=true
fi
done < <(git diff --numstat origin/main | grep -E '\.(java|avsc|proto)$')
echo "Total lines removed: $TOTAL_LINES_REMOVED"
# Fail if total line added exceeds max limit
if [ "$TOTAL_LINES_ADDED" -gt "$MAX_TOTAL_LINES_ADDED" ]; then
echo "Total added lines of all files exceed the maximum allowed lines ($TOTAL_LINES_ADDED > $MAX_TOTAL_LINES_ADDED)."
exit 1
fi
echo "Total lines added: $TOTAL_LINES_ADDED"
# Fail if total number of lines added exceeds max limit
if [ "$EXCEEDED" = true ]; then
echo "Above files exceed the maximum allowed lines added ($MAX_LINES)."
exit 1
fi
- name: Notify
if: failure()
run: |
echo "One or more files in the PR exceed the maximum allowed lines added. Please review and adjust your changes to your files."