From 2c9f08d24e60f2d3659b258e35b09d6af1e05cd2 Mon Sep 17 00:00:00 2001 From: TBSten <81161390+TBSten@users.noreply.github.com> Date: Sun, 13 Apr 2025 06:56:54 +0900 Subject: [PATCH 01/11] =?UTF-8?q?unit=20test=20report=20=E5=87=BA=E5=8A=9B?= =?UTF-8?q?=E5=85=88=E3=81=AE=E8=A8=AD=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/kotlin/BuildOutputFiles.kt | 4 ++++ .../convention/src/main/kotlin/module/Android.kt | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/buildLogic/convention/src/main/kotlin/BuildOutputFiles.kt b/buildLogic/convention/src/main/kotlin/BuildOutputFiles.kt index 6b9a93e1..a1a0e8fa 100644 --- a/buildLogic/convention/src/main/kotlin/BuildOutputFiles.kt +++ b/buildLogic/convention/src/main/kotlin/BuildOutputFiles.kt @@ -18,6 +18,10 @@ internal class BuildOutputFiles(private val rootDir: Directory) { .dir(projectDir(project)) .dir("android-lint-report") .file("lint-result.${type.extension}") + + fun unitTestReportDir(project: Project): Directory = rootDir + .dir("unit-test-report") + .dir(projectDir(project)) } internal enum class AndroidLintReportType(val extension: String) { diff --git a/buildLogic/convention/src/main/kotlin/module/Android.kt b/buildLogic/convention/src/main/kotlin/module/Android.kt index 37e5c161..f4e6501a 100644 --- a/buildLogic/convention/src/main/kotlin/module/Android.kt +++ b/buildLogic/convention/src/main/kotlin/module/Android.kt @@ -15,6 +15,7 @@ import dsl.version import org.gradle.api.JavaVersion import org.gradle.api.Project import org.gradle.kotlin.dsl.apply +import org.gradle.kotlin.dsl.assign import org.gradle.kotlin.dsl.dependencies import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension @@ -58,6 +59,8 @@ internal fun Project.configureAndroid() { } } + configureAndroidTest() + val kotlin = kotlinExtension as KotlinAndroidProjectExtension kotlin.compilerOptions { jvmTarget.set(JvmTarget.JVM_17) @@ -73,3 +76,16 @@ internal fun Project.configureAndroid() { androidTestImplementation(libs.library("androidxEspressoCore")) } } + +private fun Project.configureAndroidTest() { + android { + @Suppress("UnstableApiUsage") + testOptions { + // unitTest.reportDir looks like not work + // refs: https://issuetracker.google.com/issues/37132023 + unitTests.all { + it.reports.html.outputLocation = BuildOutputFiles(rootProject).unitTestReportDir(project) + } + } + } +} From 1d41f1bc2c7ab84700b2b458388f195043d10378 Mon Sep 17 00:00:00 2001 From: TBSten <81161390+TBSten@users.noreply.github.com> Date: Sun, 13 Apr 2025 06:57:15 +0900 Subject: [PATCH 02/11] =?UTF-8?q?unit=20test=20=E5=AE=9F=E8=A1=8C=E6=99=82?= =?UTF-8?q?=E3=81=AB=20=E3=83=86=E3=82=B9=E3=83=88=E3=83=AC=E3=83=9D?= =?UTF-8?q?=E3=83=BC=E3=83=88=E3=82=92=20pages=20=E3=81=AB=E3=83=87?= =?UTF-8?q?=E3=83=97=E3=83=AD=E3=82=A4=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/pull-request-check.yaml | 35 +++++++- .github/workflows/unit-test-top-html.js | 103 ++++++++++++++++++++++ 2 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/unit-test-top-html.js diff --git a/.github/workflows/pull-request-check.yaml b/.github/workflows/pull-request-check.yaml index 4105c107..0b3e2c06 100644 --- a/.github/workflows/pull-request-check.yaml +++ b/.github/workflows/pull-request-check.yaml @@ -1,6 +1,6 @@ name: Pull Request Check -on: [ pull_request ] +on: [pull_request] concurrency: group: pull-request-check-${{ github.event.pull_request.number }} @@ -135,13 +135,44 @@ jobs: with: cache-read-only: false - run: ./gradlew test - - uses: yumemi-inc/comment-pull-request@v1 + - uses: actions/github-script@v7 + with: + script: require("${{ github.workspace }}/.github/workflows/pull-request-check.yaml") + - uses: actions/upload-artifact@v4 + if: ${{ !cancelled() }} + with: + name: "unit-test-reports" + path: | + build/build-outputs/unit-test-report + - name: Comment Pull Request + uses: yumemi-inc/comment-pull-request@v1 if: cancelled() != true with: comment-if-failure: | > [!CAUTION] > There was a problem with the **Unit Test** check. See details [here](${{ env.LOG_URL }}). + deploy-unit-test-report: + needs: [unit-test] + runs-on: ubuntu-latest + permissions: + contents: write # for peaceiris/actions-gh-pages + pull-requests: write # for yumemi-inc/comment-pull-request + concurrency: + group: pages + cancel-in-progress: false + steps: + - uses: actions/download-artifact@v4 + with: + name: "unit-test-reports" + path: build/build-outputs/unit-test-report + - uses: peaceiris/actions-gh-pages@v4 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: build/build-outputs/unit-test-report + destination_dir: ./pr/${{ github.event.pull_request.number }}/unit-test/ + keep_files: true + build: runs-on: ubuntu-latest strategy: diff --git a/.github/workflows/unit-test-top-html.js b/.github/workflows/unit-test-top-html.js new file mode 100644 index 00000000..71317bd8 --- /dev/null +++ b/.github/workflows/unit-test-top-html.js @@ -0,0 +1,103 @@ +const fs = require('node:fs'); +const path = require('node:path'); + +export const createTopHtml = () => { + const testReportDir = 'build/build-outputs/unit-test-report'; + const outputFile = path.join(testReportDir, 'index.html'); + + function generateHTML(files) { + // ファイルパスをディレクトリ構造に変換 + const structure = {}; + for (const file of files) { + const relativePath = path.relative(testReportDir, file); + const dirPath = path.dirname(relativePath); + const parts = dirPath.split(path.sep); + let current = structure; + + for (const [index, part] of parts.entries()) { + if (index === parts.length - 1) { + current[part] = dirPath; + } else { + if (!current[part]) { + current[part] = {}; + } + current = current[part]; + } + } + } + + // ディレクトリ構造をHTMLに変換 + function generateList(items) { + if (typeof items === 'string') { + return `
  • ${path.basename(items)}
  • `; + } + + return Object.entries(items).map(([key, value]) => { + if (typeof value === 'string') { + return `
  • ${path.basename(value)}
  • `; + } + return `
  • ${key}
  • `; + }).join('\n'); + } + + const html = ` + + + Unit Test Reports Summary + + + +

    Unit Test Reports

    + + + `; + + return html; + } + + function findHTMLFiles(dir) { + let files = []; + const items = fs.readdirSync(dir); + + for (const item of items) { + const fullPath = path.join(dir, item); + const stat = fs.statSync(fullPath); + + if (stat.isDirectory()) { + files = files.concat(findHTMLFiles(fullPath)); + } else if (item === 'index.html' && fullPath !== outputFile) { + files.push(fullPath); + } + } + + return files; + } + + // Main execution + try { + const htmlFiles = findHTMLFiles(testReportDir); + const htmlContent = generateHTML(htmlFiles); + fs.writeFileSync(outputFile, htmlContent); + console.log(`Successfully generated ${outputFile}`); + } catch (error) { + console.error('Error generating test reports list:', error); + } +} From 1d73f6817b31776b53ee0d80624913bfad2be06b Mon Sep 17 00:00:00 2001 From: TBSten <81161390+TBSten@users.noreply.github.com> Date: Sun, 13 Apr 2025 07:00:14 +0900 Subject: [PATCH 03/11] =?UTF-8?q?PR=20=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E3=81=A7=E3=83=86=E3=82=B9=E3=83=88=E3=83=AC=E3=83=9D=E3=83=BC?= =?UTF-8?q?=E3=83=88=E3=81=AE=E3=83=AA=E3=83=B3=E3=82=AF=E3=82=82=E8=A1=A8?= =?UTF-8?q?=E7=A4=BA=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/pull-request-check.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pull-request-check.yaml b/.github/workflows/pull-request-check.yaml index 0b3e2c06..e88ec80f 100644 --- a/.github/workflows/pull-request-check.yaml +++ b/.github/workflows/pull-request-check.yaml @@ -151,6 +151,7 @@ jobs: comment-if-failure: | > [!CAUTION] > There was a problem with the **Unit Test** check. See details [here](${{ env.LOG_URL }}). + > Or check test report from [here](https://$owner_name.github.io/$repo_name/pr/${{ github.event.pull_request.number }}/unit-test/). deploy-unit-test-report: needs: [unit-test] From f5bfafb2324bce308317ee2b9019585d8e0e396d Mon Sep 17 00:00:00 2001 From: TBSten <81161390+TBSten@users.noreply.github.com> Date: Sun, 13 Apr 2025 07:11:14 +0900 Subject: [PATCH 04/11] fix --- .github/workflows/pull-request-check.yaml | 6 +++--- .github/workflows/unit-test-top-html.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pull-request-check.yaml b/.github/workflows/pull-request-check.yaml index e88ec80f..224e8e43 100644 --- a/.github/workflows/pull-request-check.yaml +++ b/.github/workflows/pull-request-check.yaml @@ -1,6 +1,6 @@ name: Pull Request Check -on: [pull_request] +on: [ pull_request ] concurrency: group: pull-request-check-${{ github.event.pull_request.number }} @@ -137,7 +137,7 @@ jobs: - run: ./gradlew test - uses: actions/github-script@v7 with: - script: require("${{ github.workspace }}/.github/workflows/pull-request-check.yaml") + script: require("${{ github.workspace }}/.github/workflows/unit-test-top-html.js").createTopHtml() - uses: actions/upload-artifact@v4 if: ${{ !cancelled() }} with: @@ -154,7 +154,7 @@ jobs: > Or check test report from [here](https://$owner_name.github.io/$repo_name/pr/${{ github.event.pull_request.number }}/unit-test/). deploy-unit-test-report: - needs: [unit-test] + needs: [ unit-test ] runs-on: ubuntu-latest permissions: contents: write # for peaceiris/actions-gh-pages diff --git a/.github/workflows/unit-test-top-html.js b/.github/workflows/unit-test-top-html.js index 71317bd8..3a683b7e 100644 --- a/.github/workflows/unit-test-top-html.js +++ b/.github/workflows/unit-test-top-html.js @@ -1,5 +1,5 @@ -const fs = require('node:fs'); -const path = require('node:path'); +import * as fs from "node:fs" +import * as path from "node:path" export const createTopHtml = () => { const testReportDir = 'build/build-outputs/unit-test-report'; From efe96fb56d83213e073182d434e8ecc1d74415bd Mon Sep 17 00:00:00 2001 From: TBSten <81161390+TBSten@users.noreply.github.com> Date: Mon, 14 Apr 2025 04:11:53 +0900 Subject: [PATCH 05/11] fix --- .github/workflows/pull-request-check.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pull-request-check.yaml b/.github/workflows/pull-request-check.yaml index 224e8e43..bbbcc182 100644 --- a/.github/workflows/pull-request-check.yaml +++ b/.github/workflows/pull-request-check.yaml @@ -144,6 +144,12 @@ jobs: name: "unit-test-reports" path: | build/build-outputs/unit-test-report + - id: get-outputs + run: | + owner_name=${{ github.repository_owner }} + repo_name=$(echo ${{ github.repository }} | cut -d'/' -f2) + pages_url="https://$owner_name.github.io/$repo_name/pr/${{ github.event.pull_request.number }}/unit-test/" + echo "pages_url=$pages_url" >> $GITHUB_OUTPUT - name: Comment Pull Request uses: yumemi-inc/comment-pull-request@v1 if: cancelled() != true @@ -151,7 +157,7 @@ jobs: comment-if-failure: | > [!CAUTION] > There was a problem with the **Unit Test** check. See details [here](${{ env.LOG_URL }}). - > Or check test report from [here](https://$owner_name.github.io/$repo_name/pr/${{ github.event.pull_request.number }}/unit-test/). + > Or check test report from [here](${{ steps.get_outputs.outputs.pages_url }). deploy-unit-test-report: needs: [ unit-test ] From fbc614167c71de52c8dcf7bdf312e5bdd043b5d5 Mon Sep 17 00:00:00 2001 From: TBSten <81161390+TBSten@users.noreply.github.com> Date: Mon, 14 Apr 2025 04:36:08 +0900 Subject: [PATCH 06/11] Update pull request check workflow to improve test report links and formatting --- .github/workflows/pull-request-check.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pull-request-check.yaml b/.github/workflows/pull-request-check.yaml index bbbcc182..99a8fbbd 100644 --- a/.github/workflows/pull-request-check.yaml +++ b/.github/workflows/pull-request-check.yaml @@ -1,6 +1,6 @@ name: Pull Request Check -on: [ pull_request ] +on: [pull_request] concurrency: group: pull-request-check-${{ github.event.pull_request.number }} @@ -156,11 +156,11 @@ jobs: with: comment-if-failure: | > [!CAUTION] - > There was a problem with the **Unit Test** check. See details [here](${{ env.LOG_URL }}). - > Or check test report from [here](${{ steps.get_outputs.outputs.pages_url }). + > There was a problem with the **Unit Test** check. See details [here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}). + > Or check test report from [here](${{ steps.get-outputs.outputs.pages_url }}). deploy-unit-test-report: - needs: [ unit-test ] + needs: [unit-test] runs-on: ubuntu-latest permissions: contents: write # for peaceiris/actions-gh-pages From 5a5f33a0aa5220257834b3556665bccb5bc38965 Mon Sep 17 00:00:00 2001 From: TBSten <81161390+TBSten@users.noreply.github.com> Date: Mon, 14 Apr 2025 04:52:45 +0900 Subject: [PATCH 07/11] Add condition to skip deployment of unit test report if cancelled --- .github/workflows/pull-request-check.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pull-request-check.yaml b/.github/workflows/pull-request-check.yaml index 99a8fbbd..ed843eb5 100644 --- a/.github/workflows/pull-request-check.yaml +++ b/.github/workflows/pull-request-check.yaml @@ -161,6 +161,7 @@ jobs: deploy-unit-test-report: needs: [unit-test] + if: ${{ !cancelled() }} runs-on: ubuntu-latest permissions: contents: write # for peaceiris/actions-gh-pages From 742e5e5d5bd1605f7dd0cfd8d60e921f1f353169 Mon Sep 17 00:00:00 2001 From: TBSten <81161390+TBSten@users.noreply.github.com> Date: Mon, 14 Apr 2025 04:57:40 +0900 Subject: [PATCH 08/11] Refactor pull request check workflow to rename job and improve unit test report handling --- .github/workflows/pull-request-check.yaml | 30 +++++++++++------------ 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/pull-request-check.yaml b/.github/workflows/pull-request-check.yaml index ed843eb5..43ee3900 100644 --- a/.github/workflows/pull-request-check.yaml +++ b/.github/workflows/pull-request-check.yaml @@ -144,22 +144,8 @@ jobs: name: "unit-test-reports" path: | build/build-outputs/unit-test-report - - id: get-outputs - run: | - owner_name=${{ github.repository_owner }} - repo_name=$(echo ${{ github.repository }} | cut -d'/' -f2) - pages_url="https://$owner_name.github.io/$repo_name/pr/${{ github.event.pull_request.number }}/unit-test/" - echo "pages_url=$pages_url" >> $GITHUB_OUTPUT - - name: Comment Pull Request - uses: yumemi-inc/comment-pull-request@v1 - if: cancelled() != true - with: - comment-if-failure: | - > [!CAUTION] - > There was a problem with the **Unit Test** check. See details [here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}). - > Or check test report from [here](${{ steps.get-outputs.outputs.pages_url }}). - deploy-unit-test-report: + report-unit-test: needs: [unit-test] if: ${{ !cancelled() }} runs-on: ubuntu-latest @@ -180,6 +166,20 @@ jobs: publish_dir: build/build-outputs/unit-test-report destination_dir: ./pr/${{ github.event.pull_request.number }}/unit-test/ keep_files: true + - id: get-outputs + run: | + owner_name=${{ github.repository_owner }} + repo_name=$(echo ${{ github.repository }} | cut -d'/' -f2) + pages_url="https://$owner_name.github.io/$repo_name/pr/${{ github.event.pull_request.number }}/unit-test/" + echo "pages_url=$pages_url" >> $GITHUB_OUTPUT + - name: Comment Pull Request + uses: yumemi-inc/comment-pull-request@v1 + if: cancelled() != true + with: + comment-if-failure: | + > [!CAUTION] + > There was a problem with the **Unit Test** check. See details [here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}). + > Or check test report from [here](${{ steps.get-outputs.outputs.pages_url }}). build: runs-on: ubuntu-latest From 528b4ce9ba69f90860afa3eb50229593878d52f2 Mon Sep 17 00:00:00 2001 From: TBSten <81161390+TBSten@users.noreply.github.com> Date: Mon, 14 Apr 2025 05:02:45 +0900 Subject: [PATCH 09/11] fix --- .github/workflows/pull-request-check.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request-check.yaml b/.github/workflows/pull-request-check.yaml index 43ee3900..83929961 100644 --- a/.github/workflows/pull-request-check.yaml +++ b/.github/workflows/pull-request-check.yaml @@ -176,7 +176,7 @@ jobs: uses: yumemi-inc/comment-pull-request@v1 if: cancelled() != true with: - comment-if-failure: | + comment: | > [!CAUTION] > There was a problem with the **Unit Test** check. See details [here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}). > Or check test report from [here](${{ steps.get-outputs.outputs.pages_url }}). From 625ce51627ce863524d075ba284b3830fc258546 Mon Sep 17 00:00:00 2001 From: TBSten <81161390+TBSten@users.noreply.github.com> Date: Mon, 14 Apr 2025 05:11:23 +0900 Subject: [PATCH 10/11] fix --- .github/workflows/pull-request-check.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull-request-check.yaml b/.github/workflows/pull-request-check.yaml index 83929961..d1df0120 100644 --- a/.github/workflows/pull-request-check.yaml +++ b/.github/workflows/pull-request-check.yaml @@ -1,6 +1,6 @@ name: Pull Request Check -on: [pull_request] +on: [ pull_request ] concurrency: group: pull-request-check-${{ github.event.pull_request.number }} @@ -136,6 +136,7 @@ jobs: cache-read-only: false - run: ./gradlew test - uses: actions/github-script@v7 + if: ${{ !cancelled() }} with: script: require("${{ github.workspace }}/.github/workflows/unit-test-top-html.js").createTopHtml() - uses: actions/upload-artifact@v4 @@ -146,7 +147,7 @@ jobs: build/build-outputs/unit-test-report report-unit-test: - needs: [unit-test] + needs: [ unit-test ] if: ${{ !cancelled() }} runs-on: ubuntu-latest permissions: From e95024921c1b40efc4ab5d4d75b22965d10a7fc8 Mon Sep 17 00:00:00 2001 From: TBSten <81161390+TBSten@users.noreply.github.com> Date: Mon, 14 Apr 2025 05:22:07 +0900 Subject: [PATCH 11/11] fix --- .github/workflows/pull-request-check.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pull-request-check.yaml b/.github/workflows/pull-request-check.yaml index d1df0120..faefaac8 100644 --- a/.github/workflows/pull-request-check.yaml +++ b/.github/workflows/pull-request-check.yaml @@ -1,6 +1,6 @@ name: Pull Request Check -on: [ pull_request ] +on: [pull_request] concurrency: group: pull-request-check-${{ github.event.pull_request.number }} @@ -134,7 +134,7 @@ jobs: - uses: yumemi-inc/setup-java-gradle@v3 with: cache-read-only: false - - run: ./gradlew test + - run: ./gradlew test --continue - uses: actions/github-script@v7 if: ${{ !cancelled() }} with: @@ -147,8 +147,8 @@ jobs: build/build-outputs/unit-test-report report-unit-test: - needs: [ unit-test ] - if: ${{ !cancelled() }} + needs: [unit-test] + if: ${{ !failure() }} runs-on: ubuntu-latest permissions: contents: write # for peaceiris/actions-gh-pages