-
Notifications
You must be signed in to change notification settings - Fork 3
146 lines (120 loc) · 4.7 KB
/
pull-request-test-v1.yml
File metadata and controls
146 lines (120 loc) · 4.7 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
on:
workflow_call:
jobs:
changed-files:
runs-on: ubuntu-latest
outputs:
modified_modules: ${{ steps.determine_modules.outputs.modules || '[]' }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set Up Modules
run: |
# Project root path
project_root=$(pwd)
# Initialize modules array
modules_to_format=()
# Function to identify module
function find_module() {
dir="$1"
while [[ "$dir" != "$project_root" && "$dir" != "/" ]]; do
# Module criteria: check build.gradle or build.gradle.kts file
if [[ -f "$dir/build.gradle.kts" || -f "$dir/build.gradle" ]]; then
# Return the directory as a module
echo "$(realpath --relative-to="$project_root" "$dir")"
return
fi
# Move to parent directory
dir=$(dirname "$dir")
done
}
# Fetch changed files (customize as needed)
BASE_SHA=$(git rev-parse origin/${{ github.event.pull_request.base.ref }})
git fetch origin ${{ github.event.pull_request.base.ref }} # base 브랜치 최신 상태로 가져오기
changed_files=$(git diff --name-only origin/${{ github.event.pull_request.base.ref }}...${{ github.sha }} | tr '\n' ' ')
# Identify modules in changed files
for file in $changed_files; do
# Directory where the file belongs
file_dir=$(dirname "$file")
# Find the module path
module=$(find_module "$project_root/$file_dir")
build_module=$(echo "$module" | tr '/' ':')
# Remove unnecessary spaces
build_module=$(echo "$build_module" | xargs)
# Exclude "." modules
if [[ "$build_module" == "." ]]; then
continue
fi
# Add unique modules to the list
if [[ -n "$build_module" && ! " ${modules_to_format[*]} " =~ " ${build_module} " ]]; then
modules_to_format+=("$build_module")
fi
done
# Export modules as a single string
echo "modules=$(IFS=' '; echo "${modules_to_format[*]}")" >> $GITHUB_ENV
env:
GITHUB_ENV: $GITHUB_ENV
- name: Set Module Matrix
id: determine_modules
run: |
# 문자열을 배열로 전환
IFS=' ' read -r -a MODIFIED_FILES_ARRAY <<< "${{ env.MODIFIED_FILES }}"
IFS=' ' read -r -a MODULES_ARRAY <<< "${{ env.modules }}"
# 변경 모듈 MATRIX 문자열 변환
MODULE_MATRIX=""
for MODULE in "${MODULES_ARRAY[@]}"; do
if [ -n "$MODULE_MATRIX" ]; then
MODULE_MATRIX+=",\"${MODULE}\""
else
MODULE_MATRIX+="\"${MODULE}\""
fi
done
MODULE_MATRIX="[$MODULE_MATRIX]"
echo "MODIFIED_MODULE_MATRIX=$MODULE_MATRIX"
echo "modules=$(echo $MODULE_MATRIX)" >> $GITHUB_OUTPUT
execute-test:
needs: changed-files
runs-on: ubuntu-latest
if: ${{ needs.changed-files.outputs.modified_modules != '[]' }}
strategy:
matrix:
module: ${{ fromJSON(needs.changed-files.outputs.modified_modules) }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: '21'
cache: 'gradle'
- name: Cache Gradle Package
uses: actions/cache@v3
id: gradle-cache
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle.kts') }}
restore-keys: ${{ runner.os }}-gradle-
- name: Execute Gradle Test
if: ${{ matrix.module && matrix.module != '' }}
run: |
TARGET_MODULE=$(echo "${{ matrix.module }}")
echo "TARGET : $TARGET_MODULE"
chmod +x ./gradlew
./gradlew :$TARGET_MODULE:test --parallel
PR_MODULE=${TARGET_MODULE//:/\/} # ':'을 '/'로 변경
echo "pr_module=$PR_MODULE" >> $GITHUB_ENV
- name: Coverage Report as Comment to the PR
uses: madrapps/jacoco-report@v1.6.1
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: 📝 ${{ matrix.module }} 테스트 커버리지 리포트
update-comment: true
min-coverage-overall: 60
min-coverage-changed-files: 60
paths: |
${{ github.workspace }}/${{ env.pr_module }}/build/reports/jacoco/test/jacocoTestReport.xml
extra-info: |
Target Module: ${{ matrix.module }}