Skip to content

Feat: Dev브랜치 PR시 변경된 파일만 테스트 #29

Feat: Dev브랜치 PR시 변경된 파일만 테스트

Feat: Dev브랜치 PR시 변경된 파일만 테스트 #29

Workflow file for this run

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 }}" | tr ' ' '\n' | grep -E '^.+/src/test/kotlin/.+\.kt$' | sed -E 's|^([^/]+)/([^/]+)/src/test/kotlin/(.*)\.kt$|\1:\2:testDebugUnitTest --tests \3|' | 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"