diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1095d4f071c4..66dd7f5aed7a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -68,6 +68,8 @@ jobs: id: date run: echo "::set-output name=week_of_year::$(date +'%W' --utc)" - uses: actions/checkout@v4 + with: + fetch-depth: 0 - uses: actions/setup-java@v4 with: distribution: temurin @@ -79,8 +81,11 @@ jobs: path: ~/.m2/repository key: ${{ runner.os }}-maven-unified-${{ steps.date.outputs.week_of_year }} - run: java -version - - run: mvn -B -ntp com.spotify.fmt:fmt-maven-plugin:check -T 1C - - run: mvn -B -ntp checkstyle:check@checkstyle + - run: .kokoro/build.sh + env: + JOB_TYPE: lint + HEAD_BRANCH: ${{ github.head_ref }} + BASE_BRANCH: ${{ github.base_ref }} enforcer: runs-on: ubuntu-latest steps: diff --git a/.kokoro/build.sh b/.kokoro/build.sh index 2e2efd05017c..360ea5c3a7ff 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -92,6 +92,27 @@ case ${JOB_TYPE} in echo "Not running GraalVM checks -- No changes in relevant modules" fi ;; + lint) + git checkout "${BASE_BRANCH}" + git checkout "${HEAD_BRANCH}" + changed_file_list="$(git diff --name-only "${BASE_BRANCH}" HEAD)" + has_code_change="false" + while IFS= read -r changed_file; do + if [ -n "${changed_file}" ] && [[ "${changed_file}" == *.java ]]; then + has_code_change="true" + break + fi + done <<< "${changed_file_list}" + if [ "${has_code_change}" == "false" ]; then + echo "No java modules affected. Skipping linter check." + exit 0 + fi + + mvn -B -ntp \ + -T 1.5C \ + com.spotify.fmt:fmt-maven-plugin:check + mvn -B -ntp checkstyle:check@checkstyle + ;; *) ;; esac