Skip to content

Feature/recent repository test #81

Feature/recent repository test

Feature/recent repository test #81

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
- name: Get changed files
id: changed_files
uses: tj-actions/changed-files@v45
- name: Filter out test files
id: test_files
run: |
echo "Changed files: ${{ steps.changed_files.outputs.all_changed_files }}"
TEST_FILES=$(echo "${{ steps.changed_files.outputs.all_changed_files }}" \
| tr ' ' '\n' \
| grep -E '^.+/src/test/(java|kotlin)/.+\.(kt|java)$')
echo "Filtered by grep: $TEST_FILES"
TEST_FILES=$(echo "$TEST_FILES" \
| sed -E 's/^(.+)\/src\/test\/(java|kotlin)\/(.+)\.(kt|java)$/\1 \3/' \
| sed 's/\//./g')
echo "Processed by sed: $TEST_FILES"
TEST_FILES_SINGLE_LINE=$(echo "$TEST_FILES" | tr '\n' ' ')
echo "TEST_FILES=$TEST_FILES_SINGLE_LINE" >> $GITHUB_ENV
echo "$TEST_FILES" > test_files.txt
if [ -s test_files.txt ]; then
echo "any_changed=true" >> $GITHUB_ENV
else
echo "any_changed=false" >> $GITHUB_ENV
fi
- name: Debug Changed Files
run: |
if [ -f test_files.txt ]; then
echo "changed files:"
cat test_files.txt
else
echo "No changed files found."
fi
# Check the "any_changed" environment variable
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
cat test_files.txt | while IFS=$'\n' read -r LINE; do
MODULE=$(echo "$LINE" | awk '{print $1}')
TEST_CLASS=$(echo "$LINE" | awk '{print $2}')
MODULE=$(echo "$MODULE" | sed 's|\.|:|g')
echo "MODULE: $MODULE"
echo "TEST_CLASS: $TEST_CLASS"
echo "Running: ./gradlew :$MODULE:testDebugUnitTest --tests \"$TEST_CLASS\""
./gradlew :$MODULE:testDebugUnitTest --tests "$TEST_CLASS" --scan || exit 1
done
- name: Test Result
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: "**/test-results/**/*.xml"