-
Notifications
You must be signed in to change notification settings - Fork 40
117 lines (97 loc) · 3.86 KB
/
prCheck.yml
File metadata and controls
117 lines (97 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# This will run for all PRs
name: Build
on:
push:
branches: [ main ]
pull_request: # Unit tests can be run for all external PRs
types: [opened, synchronize, reopened]
branches: [ main ]
jobs:
formatting-check:
strategy:
fail-fast: false
matrix:
java-version: [21] # For formatting, we don't need to run across multiple versions. Only sanity testing is required here, rest is taken care in the build.
runs-on:
group: databricks-protected-runner-group
labels: linux-ubuntu-latest
steps:
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java-version }}
distribution: 'adopt'
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref || github.ref_name }}
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Check formatting
run: mvn --errors spotless:check
unit-tests:
strategy:
fail-fast: false
matrix:
java-version: [11, 17, 21] # Adding LTS versions here. 21 is the latest LTS
github-runner: [ linux-ubuntu-latest, windows-server-latest ]
runs-on:
group: databricks-protected-runner-group
labels: ${{ matrix.github-runner }}
steps:
- name: Set up JDK ${{ matrix.java-version }}
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java-version }}
distribution: 'adopt'
- name: Enable long paths
if: runner.os == 'Windows'
run: git config --system core.longpaths true
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref || github.ref_name }}
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Check Unit Tests
shell: bash
run: mvn test -Dtest='!**/integration/**,!**/DatabricksDriverExamples.java,!**/ProxyTest.java,!**/LoggingTest.java,!**/SSLTest.java'
- name: Install xmllint
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y libxml2-utils
- name: JaCoCo report
run: mvn --batch-mode --errors jacoco:report --file pom.xml
- name: Extract codeCov percentage
shell: bash
run: |
COVERAGE_FILE="target/site/jacoco/jacoco.xml"
COVERED=$(xmllint --xpath "string(//report/counter[@type='INSTRUCTION']/@covered)" "$COVERAGE_FILE")
MISSED=$(xmllint --xpath "string(//report/counter[@type='INSTRUCTION']/@missed)" "$COVERAGE_FILE")
TOTAL=$((COVERED + MISSED))
# Use Python for floating-point math
PERCENTAGE=$(python -c "covered=${COVERED}; total=${TOTAL}; print(round((covered/total)*100, 2))")
echo "$PERCENTAGE" > coverage.txt
echo "::set-output name=coverage::$PERCENTAGE"
- name: Check coverage percentage
shell: bash
run: |
BRANCH_COVERAGE=$(cat coverage.txt)
echo "Branch Coverage: $BRANCH_COVERAGE%"
# Use Python to compare the coverage with 85
python -c "import sys; sys.exit(0 if float('$BRANCH_COVERAGE') >= 85 else 1)"
if [ $? -eq 1 ]; then
echo "Coverage is less than 85%"
exit 1
else
echo "Coverage is equal to or greater than 85%"
fi