Feat: RecentViewModelTest #59
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 | |
- 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/(java|kotlin)/.+\.(kt|java)$' \ | |
| sed -E 's|^(.+)/src/test/(java|kotlin)/(.+)\.(kt|java)$|\1 \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 | |
echo "$TEST_FILES" | while read FILE; do | |
MODULE=$(echo "$FILE" | cut -d' ' -f1) | |
TEST_CLASS=$(echo "$FILE" | cut -d' ' -f2) | |
MODULE=$(echo "$MODULE" | sed 's|\.|:|g') | |
TEST_CLASS="kr.co.explore.ExploreViewModelTest" | |
echo "MODULE: $MODULE" | |
echo "TEST_CLASS: $TEST_CLASS" | |
echo "Running: ./gradlew :$MODULE:testDebugUnitTest --tests \"$TEST_CLASS\"" | |
./gradlew :$MODULE:testDebugUnitTest --tests "$TEST_CLASS" --scan | |
done | |
- name: Test Result | |
uses: EnricoMi/publish-unit-test-result-action@v2 | |
if: always() | |
with: | |
files: "**/test-results/**/*.xml" |