Feat: Dev브랜치 PR시 변경된 파일만 테스트 #24
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Unit Test | |
on: | |
pull_request: | |
branches: [ "dev" ] | |
jobs: | |
unit_test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Get changed files | |
id: changed_files | |
uses: tj-actions/changed-files@v45 | |
- name: Filter out test files | |
id: test_files | |
run: | | |
TEST_FILES=$(echo "${{ steps.changed_files.outputs.all_changed_files }}" | grep -E '/src/test/kotlin/.*\.kt$' | sed -E 's|([^/]+)/src/test/kotlin/(.*)\.kt$|\1:testDebugUnitTest --tests "\2"|' | sed 's|/|.|g') | |
echo "TEST_FILES=$TEST_FILES" >> $GITHUB_ENV | |
if [ -n "$TEST_FILES" ]; then | |
echo "any_changed=true" >> $GITHUB_ENV | |
else | |
echo "any_changed=false" >> $GITHUB_ENV | |
fi | |
- name: Debug Changed Files | |
run: | | |
echo "changed files: ${{ env.TEST_FILES }}" | |
echo "files changed: ${{ env.any_changed }}" | |
- name: setup JDK | |
if: env.any_changed == 'true' | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'corretto' | |
java-version: '17' | |
- name: setup Android SDK | |
if: env.any_changed == 'true' | |
uses: android-actions/setup-android@v3 | |
- name: Run unit tests | |
if: env.any_changed == 'true' | |
run: | | |
chmod +x gradlew | |
for FILE in ${{ env.TEST_FILES }}; do | |
./gradlew $FILE | |
done | |
- name: Test Result | |
uses: EnricoMi/publish-unit-test-result-action@v2 | |
if: always() | |
with: | |
files: "**/test-results/**/*.xml" |