Skip to content

Commit 0ee86cd

Browse files
committed
ci: analyze code submitted in pr (#754)
1 parent e16a613 commit 0ee86cd

File tree

3 files changed

+80
-4
lines changed

3 files changed

+80
-4
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ name: Build CI
33
on:
44
push:
55
tags: [ '[0-9]+.[0-9]+.[0-9]+' ]
6-
branches: [ main ]
76
pull_request:
87
branches: [ main ]
98
types: [ opened, reopened, synchronize ]
109
paths:
11-
- .github/workflows/**
10+
- .github/workflows/build.yml
1211
- gradle/**
13-
- kata/**
1412
- build.gradle.kts
1513
- settings.gradle.kts
1614
- gradle.properties
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Kata PR Analysis
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
types: [ opened, reopened, synchronize ]
7+
paths:
8+
- kata/**/*.java
9+
- '!kata/retired/**'
10+
11+
concurrency:
12+
group: ${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
analysis:
17+
runs-on: ubuntu-24.04
18+
timeout-minutes: 10
19+
permissions:
20+
contents: write
21+
pull-requests: write
22+
env:
23+
VERSION: 1.25.0
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
27+
with:
28+
fetch-depth: 0
29+
30+
- name: Modified projects
31+
id: projects
32+
run: |
33+
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }})
34+
echo "Changed files: $CHANGED_FILES"
35+
CHANGED_PROJECTS=""
36+
DIRS=""
37+
TASKS=""
38+
for file in $CHANGED_FILES; do
39+
if [[ $file == *.java ]]; then
40+
PROJECT_HOME=$(echo $file | cut -d'/' -f1-3)
41+
RANK=$(basename "$(dirname "$PROJECT_HOME")")
42+
if [[ "$RANK" != "retired" && ! ",$CHANGED_PROJECTS," =~ ",$PROJECT_HOME," ]]; then
43+
CHANGED_PROJECTS="$CHANGED_PROJECTS,$PROJECT_HOME"
44+
DIRS="$DIRS,$PROJECT_HOME/**"
45+
PROJECT_NAME=$(basename "$PROJECT_HOME")
46+
TASKS="$TASKS :$PROJECT_NAME:test :$PROJECT_NAME:jacocoTestReport"
47+
fi
48+
fi
49+
done
50+
echo "dirs=${DIRS#,}" >> $GITHUB_OUTPUT
51+
echo "tasks=${TASKS# }" >> $GITHUB_OUTPUT
52+
53+
- name: Setup Java
54+
uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0
55+
with:
56+
distribution: temurin
57+
java-version: 17
58+
59+
- name: Setup Gradle
60+
uses: gradle/actions/setup-gradle@94baf225fe0a508e581a564467443d0e2379123b # v4
61+
with:
62+
add-job-summary-as-pr-comment: always
63+
64+
- name: Analyze code quality
65+
run: |
66+
./gradlew ${{ steps.projects.outputs.tasks }} sonar -x processResources -x processTestResources\
67+
--parallel \
68+
--configuration-cache \
69+
--build-cache \
70+
--no-daemon \
71+
--scan \
72+
--no-problems-report \
73+
-Pversion=${{ format('{0}+{1}', env.VERSION, github.RUN_NUMBER) }} \
74+
-Dsonar.token=${{ secrets.SONAR_TOKEN }} \
75+
-Dsonar.organization=${{ secrets.SONAR_KEY }} \
76+
-Dsonar.inclusions=${{ steps.projects.outputs.dirs }} \
77+
-Dsonar.qualitygate.wait=true \
78+
-Dsonar.gradle.skipCompile=true
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Train Kata
1+
name: Kata PR Initialization
22
run-name: Kata ${{ inputs.kata }}
33

44
on:

0 commit comments

Comments
 (0)