diff --git a/.github/actions/setup-android/action.yml b/.github/actions/setup-android/action.yml new file mode 100644 index 00000000..111cf908 --- /dev/null +++ b/.github/actions/setup-android/action.yml @@ -0,0 +1,41 @@ +name: 'Setup Android Environment' +description: 'Installs JDK 21, Android SDK, configures Gradle caches, and generates local.properties for Android CI jobs.' + +runs: + using: "composite" + steps: + - name: Setup JDK 21 + uses: actions/setup-java@v4 + with: + java-version: '21' + distribution: 'temurin' + cache: gradle + + - name: Setup Android SDK + uses: android-actions/setup-android@v3 + + - name: Cache Gradle Wrapper + uses: actions/cache@v4 + with: + path: ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle-wrapper- + + - name: Cache Build Cache + uses: actions/cache@v4 + with: + path: ~/.gradle/caches/build-cache-1 + key: ${{ runner.os }}-build-cache-${{ hashFiles('**/build.gradle*', '**/gradle-wrapper.properties') }}-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-build-cache-${{ hashFiles('**/build.gradle*', '**/gradle-wrapper.properties') }} + ${{ runner.os }}-build-cache- + + - name: Generate local.properties + shell: bash + run: | + echo '${{ env.LOCAL_PROPERTIES }}' | base64 -d > ./local.properties + + - name: Grant execute permission for gradlew + shell: bash + run: chmod +x gradlew diff --git a/.github/workflows/android-ci.yml b/.github/workflows/android-ci.yml index 086a14a5..06441664 100644 --- a/.github/workflows/android-ci.yml +++ b/.github/workflows/android-ci.yml @@ -20,38 +20,10 @@ jobs: - name: Checkout Repository uses: actions/checkout@v4 - - name: Setup JDK 21 - uses: actions/setup-java@v4 - with: - java-version: '21' - distribution: 'temurin' - cache: gradle - - - name: Setup Android SDK - uses: android-actions/setup-android@v2 - - - name: Cache Gradle Wrapper - uses: actions/cache@v4 - with: - path: ~/.gradle/wrapper - key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }} - restore-keys: | - ${{ runner.os }}-gradle-wrapper- - - - name: Cache Build Cache - uses: actions/cache@v4 - with: - path: ~/.gradle/caches/build-cache-1 - key: ${{ runner.os }}-build-cache-${{ hashFiles('**/build.gradle*', '**/gradle-wrapper.properties') }}-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-build-cache-${{ hashFiles('**/build.gradle*', '**/gradle-wrapper.properties') }} - ${{ runner.os }}-build-cache- - - - name: Generate local.properties - run: echo '${{ secrets.LOCAL_PROPERTIES }}' | base64 -d > ./local.properties - - - name: Grant execute permission for gradlew - run: chmod +x gradlew + - name: Setup + uses: ./.github/actions/setup-android + env: + LOCAL_PROPERTIES: ${{ secrets.LOCAL_PROPERTIES }} - name: Code Style Check id: ktlint @@ -61,14 +33,6 @@ jobs: end=$(date +%s) echo "time=$((end-start))" >> $GITHUB_OUTPUT - - name: Unit Test - id: test - run: | - start=$(date +%s) - ./gradlew testDebugUnitTest --parallel - end=$(date +%s) - echo "time=$((end-start))" >> $GITHUB_OUTPUT - - name: Debug Build with Gradle id: assemble run: | @@ -91,11 +55,6 @@ jobs: with: script: | const results = { - test: { - status: '${{ steps.test.outcome }}', - name: 'Unit Test', - time: '${{ steps.test.outputs.time }}' - }, assemble: { status: '${{ steps.assemble.outcome }}', name: 'Debug Build', diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml new file mode 100644 index 00000000..98a7cdf7 --- /dev/null +++ b/.github/workflows/unit-test.yml @@ -0,0 +1,42 @@ +name: unit-test + +on: + pull_request: + paths-ignore: + - '**.md' + +run-name: "unit-test by ${{ github.actor }}" + +permissions: + contents: read + pull-requests: write + actions: write + +jobs: + unit-test: + runs-on: ubuntu-latest + if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip-ci') }} + timeout-minutes: 30 + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Setup + uses: ./.github/actions/setup-android + env: + LOCAL_PROPERTIES: ${{ secrets.LOCAL_PROPERTIES }} + + - name: Run Unit Tests and Record Screenshots + id: test + run: ./gradlew testDebugUnitTest --parallel --stacktrace + + - name: Upload Test Reports and Screenshots + if: always() + uses: actions/upload-artifact@v4 + with: + name: test-reports + path: | + **/build/reports/tests + **/build/outputs/roborazzi + retention-days: 7