Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create new CI workflow and run unit tests using it #17700

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .github/scripts/create-jacoco-coverage-report.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash

# 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.

set -e
set -x

echo "GITHUB_BASE_REF: ${GITHUB_BASE_REF}"

echo "Setting up git remote"
git remote set-branches --add origin ${GITHUB_BASE_REF}
git fetch

Akshat-Jain marked this conversation as resolved.
Show resolved Hide resolved
# Compile the project. jacoco:report needs class files along with jacoco.exec files to generate the report.
mvn -B install -DskipTests -P skip-static-checks -Dweb.console.skip=true -Dmaven.javadoc.skip=true

# If there are multiple jacoco.exec files present in any module, merge them into a single jacoco.exec file for that module.
mvn jacoco:merge

mvn jacoco:report

changed_files="$(git diff --name-only origin/${GITHUB_BASE_REF}...HEAD | grep "\.java$" || [[ $? == 1 ]])"

echo "Changed files:"
for f in ${changed_files}
do
echo $f
done

mvn com.github.eirslett:frontend-maven-plugin:install-node-and-npm@install-node-and-npm -pl web-console/
PATH+=:web-console/target/node/
npm install @connectis/[email protected]

export FORCE_COLOR=2

if [ -n "${changed_files}" ]
then
git diff origin/${GITHUB_BASE_REF}...HEAD -- ${changed_files} |
node_modules/.bin/diff-test-coverage \
--coverage "**/target/site/jacoco/jacoco.xml" \
--type jacoco \
--line-coverage 50 \
--branch-coverage 50 \
--function-coverage 0 \
--log-template "coverage-lines-complete" \
--log-template "coverage-files-complete" \
--log-template "totals-complete" \
--log-template "errors" \
-- ||
{ printf "\n\n****FAILED****\nDiff code coverage check failed. To view coverage report, run 'mvn clean test jacoco:report' and open 'target/site/jacoco/index.html'\nFor more details on how to run code coverage locally, follow instructions here - https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md#running-code-coverage-locally\n\n" && exit 1; }
fi
25 changes: 25 additions & 0 deletions .github/scripts/run-unit-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# 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.

set -e
set -x

OPTS+="-pl !integration-tests,!:druid-it-tools,!:druid-it-image,!:druid-it-cases"
OPTS+=" -Dsurefire.failIfNoSpecifiedTests=false -P skip-static-checks -Dweb.console.skip=true -Dmaven.javadoc.skip=true"
OPTS+=" -Djacoco.destFile=\"target/jacoco-${HASH}.exec\""

mvn -B $OPTS test "$@"
80 changes: 0 additions & 80 deletions .github/scripts/unit_tests_script.sh

This file was deleted.

70 changes: 70 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# 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: "CI"

on:
workflow_call:
inputs:
jdk:
required: false
type: string
default: '17'

jobs:
run-unit-tests:
name: "unit tests"
strategy:
fail-fast: false
matrix:
Dtest: [ "A*,F*,S*", "B*,D*,L*,T*", "C*,O*", "E*,N*,Q*", "G*,R*,U*", "H*,I*,J*", "K*,P*,V*,W*,X*,Y*,Z*", "M*"]
uses: ./.github/workflows/worker.yml
with:
script: .github/scripts/run-unit-tests.sh -Dtest='${{ matrix.Dtest }}' -Dmaven.test.failure.ignore=true
jdk: ${{ inputs.jdk }}
artifact_prefix: "unit-test-reports"
key: ${{ matrix.Dtest }}

reporting-unit-test-failures:
name: "report-unit-test-failures"
needs: run-unit-tests
runs-on: ubuntu-latest
steps:
- name: Download reports for all unit test jobs
uses: actions/download-artifact@v4
with:
pattern: "unit-test-reports-*"
path: target/surefire-reports

- name: Publish Test Report
uses: mikepenz/action-junit-report@v5
with:
check_name: "Unit Test Report"
report_paths: '**/target/surefire-reports/TEST-*.xml'
detailed_summary: true
flaky_summary: true
annotate_only: true
fail_on_failure: true
check_retries: true
truncate_stack_traces: false

reporting-jacoco-coverage-failures:
name: "report-jacoco-coverage-failures"
needs: run-unit-tests
uses: ./.github/workflows/worker.yml
with:
script: .github/scripts/create-jacoco-coverage-report.sh
artifacts_to_download: "unit-test-reports-*"
key: "jacoco-coverage-report"
75 changes: 75 additions & 0 deletions .github/workflows/cron-job-unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# 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: "Cron Job Unit Tests"
on:
schedule: # Runs by default on master branch
- cron: '0 3 * * 6' # Runs every Saturday at 03:00 AM UTC

jobs:
run-unit-tests:
name: "unit tests"
if: (github.event_name == 'schedule' && github.repository == 'apache/druid')
strategy:
fail-fast: false
matrix:
jdk: [ '11', '21' ]
Dtest: [ "A*,F*,S*", "B*,D*,L*,T*", "C*,O*", "E*,N*,Q*", "G*,R*,U*", "H*,I*,J*", "K*,P*,V*,W*,X*,Y*,Z*", "M*"]
uses: ./.github/workflows/worker.yml
with:
script: .github/scripts/run-unit-tests.sh -Dtest='${{ matrix.Dtest }}' -Dmaven.test.failure.ignore=true
jdk: ${{ matrix.jdk }}
artifact_prefix: "unit-test-reports-${{ matrix.jdk }}"
key: ${{ matrix.Dtest }}

reporting-unit-test-failures:
name: "report-unit-test-failures-${{ matrix.jdk }}"
needs: run-unit-tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
jdk: [ '11', '21' ]
steps:
- name: Download reports for all unit test jobs
uses: actions/download-artifact@v4
with:
pattern: "unit-test-reports-${{ matrix.jdk }}-*"
path: target/surefire-reports

- name: Publish Test Report
uses: mikepenz/action-junit-report@v5
with:
check_name: "Unit Test Report (JDK ${{ matrix.jdk }})"
report_paths: '**/target/surefire-reports/TEST-*.xml'
detailed_summary: true
flaky_summary: true
annotate_only: true
fail_on_failure: true
check_retries: true
truncate_stack_traces: false

reporting-jacoco-coverage-failures:
name: "report-jacoco-coverage-failures-${{ matrix.jdk }}"
needs: run-unit-tests
uses: ./.github/workflows/worker.yml
strategy:
fail-fast: false
matrix:
jdk: [ '11', '21' ]
with:
script: .github/scripts/create-jacoco-coverage-report.sh
artifacts_to_download: "unit-test-reports-${{ matrix.jdk }}-*"
key: "jacoco-coverage-report"
Loading
Loading