From 29f364a2b0ae8304483e5001a090fae7d6a9d72a Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Wed, 27 Nov 2024 15:18:01 -0500 Subject: [PATCH] added collectors to init scripts. Also publishing all artifacts. --- .github/workflows/main.yml | 2 +- .../squareup/invert/examples/AppComponent.kt | 1 + examples/build.gradle.kts | 11 +- ...ctor.kt => InvertContainsStatCollector.kt} | 4 +- .../linesofcode/LinesOfCodeStatCollector.kt | 2 +- invert-owners-github/build.gradle.kts | 4 + invert.init.script.gradle.kts | 109 ++-- scripts/github-pages.main.kts | 608 +++++++++--------- 8 files changed, 392 insertions(+), 349 deletions(-) rename invert-collectors/src/main/kotlin/com/squareup/invert/collectors/contains/{LineContainsStatCollector.kt => InvertContainsStatCollector.kt} (95%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index aaa2aa8..be8a35b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -103,7 +103,7 @@ jobs: run: echo "VERSION_NAME=$(cat gradle.properties | grep "^version=" | awk -F'=' '{print $2}')" >> $GITHUB_ENV - name: Publish Snapshot - run: ./gradlew :invert-report:publish :invert-models:publish :invert-gradle-plugin:publish --no-configuration-cache --stacktrace + run: ./gradlew publish --no-configuration-cache --stacktrace if: success() && endsWith(env.VERSION_NAME, '-SNAPSHOT') env: ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }} diff --git a/examples/app/src/main/kotlin/com/squareup/invert/examples/AppComponent.kt b/examples/app/src/main/kotlin/com/squareup/invert/examples/AppComponent.kt index 986ef40..0a42fcb 100644 --- a/examples/app/src/main/kotlin/com/squareup/invert/examples/AppComponent.kt +++ b/examples/app/src/main/kotlin/com/squareup/invert/examples/AppComponent.kt @@ -8,5 +8,6 @@ import javax.inject.Singleton @Singleton @MergeComponent(AppScope::class) interface AppComponent { + // TODO make this app better fun networking(): NetworkGraph } diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts index 75c9a58..ad5e6e6 100644 --- a/examples/build.gradle.kts +++ b/examples/build.gradle.kts @@ -29,7 +29,6 @@ plugins { } invert { - ownershipCollector(com.squareup.invert.owners.GitHubCodeOwnersInvertOwnershipCollector) addStatCollector( com.squareup.invert.collectors.linesofcode.LinesOfCodeStatCollector( @@ -38,13 +37,21 @@ invert { ) ) addStatCollector( - com.squareup.invert.collectors.contains.LineContainsStatCollector( + com.squareup.invert.collectors.contains.InvertContainsStatCollector( statKey = "wildcard-imports", statDescription = "Wildcard Imports", linePredicate = { it.contains("import") && it.contains("*") }, filePredicate = { it.extension == "kt" || it.extension == "kts" }, ) ) + addStatCollector( + com.squareup.invert.collectors.contains.InvertContainsStatCollector( + statKey = "todos", + statDescription = "TODOs", + linePredicate = { it.contains("TODO") }, + filePredicate = { true }, + ) + ) } /** diff --git a/invert-collectors/src/main/kotlin/com/squareup/invert/collectors/contains/LineContainsStatCollector.kt b/invert-collectors/src/main/kotlin/com/squareup/invert/collectors/contains/InvertContainsStatCollector.kt similarity index 95% rename from invert-collectors/src/main/kotlin/com/squareup/invert/collectors/contains/LineContainsStatCollector.kt rename to invert-collectors/src/main/kotlin/com/squareup/invert/collectors/contains/InvertContainsStatCollector.kt index a16f952..c82a6e3 100644 --- a/invert-collectors/src/main/kotlin/com/squareup/invert/collectors/contains/LineContainsStatCollector.kt +++ b/invert-collectors/src/main/kotlin/com/squareup/invert/collectors/contains/InvertContainsStatCollector.kt @@ -9,7 +9,7 @@ import com.squareup.invert.models.StatDataType import com.squareup.invert.models.StatMetadata import java.io.File -open class LineContainsStatCollector( +open class InvertContainsStatCollector( private val statKey: String, private val statDescription: String, private val linePredicate: (String) -> Boolean, @@ -58,6 +58,6 @@ open class LineContainsStatCollector( } override fun getName(): String { - return this::class.java.name + return this::class.java.name + "-" + statKey } } \ No newline at end of file diff --git a/invert-collectors/src/main/kotlin/com/squareup/invert/collectors/linesofcode/LinesOfCodeStatCollector.kt b/invert-collectors/src/main/kotlin/com/squareup/invert/collectors/linesofcode/LinesOfCodeStatCollector.kt index 7a718c5..cbcdd9e 100644 --- a/invert-collectors/src/main/kotlin/com/squareup/invert/collectors/linesofcode/LinesOfCodeStatCollector.kt +++ b/invert-collectors/src/main/kotlin/com/squareup/invert/collectors/linesofcode/LinesOfCodeStatCollector.kt @@ -12,7 +12,7 @@ import java.io.File open class LinesOfCodeStatCollector( name: String, private val fileExtensions: List, - keySuffix: String = fileExtensions.joinToString(","), + keySuffix: String = fileExtensions.joinToString("_"), private val sourcesDirectory: (InvertProjectData) -> File = { it.projectSrcDir }, diff --git a/invert-owners-github/build.gradle.kts b/invert-owners-github/build.gradle.kts index 558993b..66b4939 100644 --- a/invert-owners-github/build.gradle.kts +++ b/invert-owners-github/build.gradle.kts @@ -5,6 +5,10 @@ plugins { alias(libs.plugins.dokka) } +java { + withSourcesJar() +} + dependencies { implementation(project(":invert-gradle-plugin")) diff --git a/invert.init.script.gradle.kts b/invert.init.script.gradle.kts index 804640e..8184fe0 100644 --- a/invert.init.script.gradle.kts +++ b/invert.init.script.gradle.kts @@ -1,55 +1,84 @@ -import com.squareup.invert.InvertGradlePlugin import com.squareup.invert.InvertExtension +import com.squareup.invert.InvertGradlePlugin initscript { - repositories { - mavenCentral() - gradlePluginPortal() - // SNAPSHOT Versions - maven { - url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots") - } - } - dependencies { - val invertVersion = "+" - classpath("com.squareup.invert:invert-gradle-plugin:$invertVersion") + repositories { + mavenCentral() + gradlePluginPortal() + // SNAPSHOT Versions + maven { + url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots") } + } + dependencies { + val invertVersion = "+" + classpath("com.squareup.invert:invert-gradle-plugin:$invertVersion") + } } apply() class InvertInitScriptPlugin : Plugin { - override fun apply(gradle: Gradle) { - gradle.settingsEvaluated { - gradle.rootProject { - buildscript { - repositories { - mavenCentral() - gradlePluginPortal() - mavenLocal() - // SNAPSHOT Versions - maven { - url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots") - } - } - - dependencies { - val invertVersion = "0.0.4-dev-SNAPSHOT" - classpath("com.squareup.invert:invert-gradle-plugin:$invertVersion") - } - } + override fun apply(gradle: Gradle) { + gradle.settingsEvaluated { + gradle.rootProject { + buildscript { + repositories { + mavenCentral() + gradlePluginPortal() + mavenLocal() + // SNAPSHOT Versions + maven { + url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots") } + } - gradle.rootProject { - afterEvaluate { - plugins.apply(com.squareup.invert.InvertGradlePlugin::class.java) - this.extensions.getByType(com.squareup.invert.InvertExtension::class.java).apply { -// ownershipCollector(...) -// addStatCollector(...) - } - } - } + dependencies { + val invertVersion = "0.0.4-dev-SNAPSHOT" + classpath("com.squareup.invert:invert-gradle-plugin:$invertVersion") + classpath("com.squareup.invert:invert-collectors:$invertVersion") + classpath("com.squareup.invert:invert-owners-github:$invertVersion") + } + } + } + + gradle.rootProject { + afterEvaluate { + plugins.apply(com.squareup.invert.InvertGradlePlugin::class.java) + this.extensions.getByType(com.squareup.invert.InvertExtension::class.java).apply { + ownershipCollector(com.squareup.invert.owners.GitHubCodeOwnersInvertOwnershipCollector) + addStatCollector( + com.squareup.invert.collectors.linesofcode.LinesOfCodeStatCollector( + name = "Kotlin", + fileExtensions = listOf("kt", "kts"), + ) + ) + addStatCollector( + com.squareup.invert.collectors.linesofcode.LinesOfCodeStatCollector( + name = "Java", + fileExtensions = listOf("java"), + ) + ) + addStatCollector( + com.squareup.invert.collectors.contains.InvertContainsStatCollector( + statKey = "wildcard-imports", + statDescription = "Wildcard Imports", + linePredicate = { it.contains("import") && it.contains("*") }, + filePredicate = { it.extension == "kt" || it.extension == "kts" }, + ) + ) + addStatCollector( + com.squareup.invert.collectors.contains.InvertContainsStatCollector( + statKey = "todos", + statDescription = "TODOs", + linePredicate = { it.contains("TODO") }, + filePredicate = { true }, + ) + ) + } } + } } + } } \ No newline at end of file diff --git a/scripts/github-pages.main.kts b/scripts/github-pages.main.kts index ff5b799..2630739 100755 --- a/scripts/github-pages.main.kts +++ b/scripts/github-pages.main.kts @@ -6,30 +6,30 @@ import java.util.concurrent.Executors val PROJECT_ROOT_DIR = File(".") val INVERT_VERSION = File(PROJECT_ROOT_DIR, "gradle.properties").readText() - .lines() - .first { it.startsWith("version=") } - .substringAfter("version=") + .lines() + .first { it.startsWith("version=") } + .substringAfter("version=") val INVERT_INIT_SCRIPT = File(PROJECT_ROOT_DIR, "invert.init.script.gradle.kts") /** * Data bundle that includes standard output, error output, and exit code of a process. */ data class TerminalExecRunnerResult( - val stdOut: String, - val stdErr: String, - val exitCode: Int + val stdOut: String, + val stdErr: String, + val exitCode: Int ) fun readStream(inputStream: InputStream): String { - return inputStream.bufferedReader().use { reader -> - val output = StringBuilder() - var line: String? - while (reader.readLine().also { line = it } != null) { - println(line) // This prints each line in real-time. - output.append(line).append("\n") - } - output.toString().trim() + return inputStream.bufferedReader().use { reader -> + val output = StringBuilder() + var line: String? + while (reader.readLine().also { line = it } != null) { + println(line) // This prints each line in real-time. + output.append(line).append("\n") } + output.toString().trim() + } } /** @@ -38,60 +38,60 @@ fun readStream(inputStream: InputStream): String { * @param [command] shell command split into a list that includes the program and it's arguments. */ fun exec( - command: List, - workingDir: File, - envVars: Map = emptyMap() + command: List, + workingDir: File, + envVars: Map = emptyMap() ): TerminalExecRunnerResult { - println("*****\nBEGIN ${command.joinToString(" ")}") - println("CWD ${workingDir.path}") - val process = ProcessBuilder(command) - .directory(workingDir) - .apply { - envVars.entries.forEach { - environment()[it.key] = it.value - } - } - .start() + println("*****\nBEGIN ${command.joinToString(" ")}") + println("CWD ${workingDir.path}") + val process = ProcessBuilder(command) + .directory(workingDir) + .apply { + envVars.entries.forEach { + environment()[it.key] = it.value + } + } + .start() - val executor = Executors.newFixedThreadPool(2) + val executor = Executors.newFixedThreadPool(2) - // Start reading stdout and stderr in separate threads - val stdoutFuture = executor.submit { readStream(process.inputStream) } - val stderrFuture = executor.submit { readStream(process.errorStream) } + // Start reading stdout and stderr in separate threads + val stdoutFuture = executor.submit { readStream(process.inputStream) } + val stderrFuture = executor.submit { readStream(process.errorStream) } - // Wait for the process to terminate - val exitCode = process.waitFor() - executor.shutdown() + // Wait for the process to terminate + val exitCode = process.waitFor() + executor.shutdown() - // Get the outputs from futures - val stdout = stdoutFuture.get() - val stderr = stderrFuture.get() + // Get the outputs from futures + val stdout = stdoutFuture.get() + val stderr = stderrFuture.get() - println("END (Exit Code $exitCode) ${command.joinToString(" ")}\n-----") + println("END (Exit Code $exitCode) ${command.joinToString(" ")}\n-----") - return TerminalExecRunnerResult(stdout, stderr, exitCode) + return TerminalExecRunnerResult(stdout, stderr, exitCode) } val slackRemoveExclusiveContentPostCheckout: (File) -> Unit = { clonedProjectDir -> - val settingsKts = File(clonedProjectDir, "settings.gradle.kts") - var waitForClosingBracket = false - settingsKts.readLines().mapNotNull { line -> - if (line.trim().startsWith("exclusiveContent")) { - waitForClosingBracket = true - null - } else if (waitForClosingBracket) { - if (line.startsWith(" }")) { - waitForClosingBracket = false - "gradlePluginPortal()" - } else { - null - } - } else { - line - } - }.also { lines -> - settingsKts.writeText(lines.joinToString("\n")) + val settingsKts = File(clonedProjectDir, "settings.gradle.kts") + var waitForClosingBracket = false + settingsKts.readLines().mapNotNull { line -> + if (line.trim().startsWith("exclusiveContent")) { + waitForClosingBracket = true + null + } else if (waitForClosingBracket) { + if (line.startsWith(" }")) { + waitForClosingBracket = false + "gradlePluginPortal()" + } else { + null + } + } else { + line } + }.also { lines -> + settingsKts.writeText(lines.joinToString("\n")) + } } /** @@ -105,17 +105,17 @@ val slackRemoveExclusiveContentPostCheckout: (File) -> Unit = { clonedProjectDir * @param [command] shell command as you would enter it in the terminal. */ fun executeCmd(command: String, workingDir: File, envVars: Map = mapOf()): TerminalExecRunnerResult { - return exec( - // https://stackoverflow.com/a/51356605 - // This regex splits strings only outside of double quotes. - command.split(" (?=(?:[^\"]*\"[^\"]*\")*[^\"]*\$)".toRegex()) - .map { - // Strip surrounding double quotes. - it.trim('"') - }, - workingDir, - envVars, - ) + return exec( + // https://stackoverflow.com/a/51356605 + // This regex splits strings only outside of double quotes. + command.split(" (?=(?:[^\"]*\"[^\"]*\")*[^\"]*\$)".toRegex()) + .map { + // Strip surrounding double quotes. + it.trim('"') + }, + workingDir, + envVars, + ) } executeCmd("./gradlew publishToMavenLocal --no-daemon --no-configuration-cache --rerun-tasks", PROJECT_ROOT_DIR) @@ -123,271 +123,273 @@ executeCmd("./gradlew publishToMavenLocal --no-daemon --no-configuration-cache - val DEFAULT_INIT_SCRIPT_LINE = "./gradlew --init-script ${INVERT_INIT_SCRIPT.canonicalPath} :invert --no-daemon" data class TargetRepo( - val org: String, - val project: String, - val runOnGitHubAction: Boolean = true, - val hasAnvil: Boolean = false, - val buildDirPath: String = "build", - val invertGradleCmd: () -> String = { DEFAULT_INIT_SCRIPT_LINE }, - val postCheckout: (File) -> Unit = { projectCloneDir -> }, - val runInvert: (File) -> Unit = { projectCloneDir -> - executeCmd( - invertGradleCmd(), - projectCloneDir - ) - } + val org: String, + val project: String, + val runOnGitHubAction: Boolean = true, + val hasAnvil: Boolean = false, + val buildDirPath: String = "build", + val invertGradleCmd: () -> String = { DEFAULT_INIT_SCRIPT_LINE }, + val postCheckout: (File) -> Unit = { projectCloneDir -> }, + val runInvert: (File) -> Unit = { projectCloneDir -> + executeCmd( + invertGradleCmd(), + projectCloneDir + ) + } ) { - val url = "https://github.com/$org/$project" + val url = "https://github.com/$org/$project" } val OTHER_REPOS_TO_CONSIDER = listOf( - TargetRepo( - org = "airbnb", - project = "mavericks", - ), - TargetRepo( - org = "SonarSource", - project = "sonar-kotlin", - ), - TargetRepo( - org = "apereo", - project = "cas", - runOnGitHubAction = false, - ), - TargetRepo( - org = "androidx", - project = "androidx", - runOnGitHubAction = false, - ), - TargetRepo( - org = "InsertKoinIO", - project = "koin", - runInvert = { projectCloneDir -> - executeCmd( - DEFAULT_INIT_SCRIPT_LINE, - File(projectCloneDir, "projects") - ) - }, - runOnGitHubAction = false, - ), - TargetRepo( - org = "square", - project = "anvil", - buildDirPath = "build/root-build", - runOnGitHubAction = false, - ), - TargetRepo( - org = "PaulWoitaschek", - project = "Voice", - hasAnvil = true, - runOnGitHubAction = false, - ), - TargetRepo( - org = "spring-projects", - project = "spring-boot", - runOnGitHubAction = false, - ), - TargetRepo( - org = "skydoves", - project = "pokedex-compose", - runOnGitHubAction = false, - ), - TargetRepo( - org = "square", - project = "okhttp", - ), - TargetRepo( - org = "slackhq", - project = "circuit", - postCheckout = slackRemoveExclusiveContentPostCheckout, - runOnGitHubAction = false, - ), - TargetRepo( - org = "chrisbanes", - project = "tivi", - ), - TargetRepo( - org = "android", - project = "nowinandroid", - ), - TargetRepo( - org = "handstandsam", - project = "ShoppingApp", - ), - TargetRepo( - org = "rickbusarow", - project = "ModuleCheck", - hasAnvil = true, - ), + TargetRepo( + org = "airbnb", + project = "mavericks", + ), + TargetRepo( + org = "SonarSource", + project = "sonar-kotlin", + ), + TargetRepo( + org = "apereo", + project = "cas", + runOnGitHubAction = false, + ), + TargetRepo( + org = "androidx", + project = "androidx", + runOnGitHubAction = false, + ), + TargetRepo( + org = "InsertKoinIO", + project = "koin", + runInvert = { projectCloneDir -> + executeCmd( + DEFAULT_INIT_SCRIPT_LINE, + File(projectCloneDir, "projects") + ) + }, + runOnGitHubAction = false, + ), + TargetRepo( + org = "square", + project = "anvil", + buildDirPath = "build/root-build", + runOnGitHubAction = false, + ), + TargetRepo( + org = "PaulWoitaschek", + project = "Voice", + hasAnvil = true, + runOnGitHubAction = false, + ), + TargetRepo( + org = "spring-projects", + project = "spring-boot", + runOnGitHubAction = false, + ), + TargetRepo( + org = "skydoves", + project = "pokedex-compose", + runOnGitHubAction = false, + ), + TargetRepo( + org = "square", + project = "okhttp", + ), + TargetRepo( + org = "slackhq", + project = "circuit", + postCheckout = slackRemoveExclusiveContentPostCheckout, + runOnGitHubAction = false, + ), + TargetRepo( + org = "chrisbanes", + project = "tivi", + ), + TargetRepo( + org = "android", + project = "nowinandroid", + ), + TargetRepo( + org = "handstandsam", + project = "ShoppingApp", + ), + TargetRepo( + org = "rickbusarow", + project = "ModuleCheck", + hasAnvil = true, + ), ) val ALL_REPOS = listOf( - TargetRepo( - org = "JetBrains", - project = "kotlin", - invertGradleCmd = { - "./gradlew :invert" - }, - postCheckout = { clonedProjectDir -> - // Remove Dependency Verification - File(clonedProjectDir, "gradle/verification-metadata.xml").apply { - if (exists()) delete() - } + TargetRepo( + runOnGitHubAction = false, + org = "JetBrains", + project = "kotlin", + invertGradleCmd = { + "./gradlew :invert" + }, + postCheckout = { clonedProjectDir -> + // Remove Dependency Verification + File(clonedProjectDir, "gradle/verification-metadata.xml").apply { + if (exists()) delete() + } - // Add Maven Local Repo - File(clonedProjectDir, "settings.gradle").apply { - readText().also { text -> - val toFind = "gradlePluginPortal()" - val toReplace = "$toFind\nmavenLocal()" - if (!text.contains(toReplace)) { - writeText(text.replace(toFind, toReplace)) - } - } - } + // Add Maven Local Repo + File(clonedProjectDir, "settings.gradle").apply { + readText().also { text -> + val toFind = "gradlePluginPortal()" + val toReplace = "$toFind\nmavenLocal()" + if (!text.contains(toReplace)) { + writeText(text.replace(toFind, toReplace)) + } + } + } - // Add Invert Plugin - File(clonedProjectDir, "build.gradle.kts").apply { - readText().also { text -> - val toFind = "plugins {" - val toReplace = "$toFind\nid(\"com.squareup.invert\") version \"$INVERT_VERSION\"" - if (!text.contains(toReplace)) { - writeText(text.replace(toFind, toReplace)) - } - } - } - }, - ), + // Add Invert Plugin + File(clonedProjectDir, "build.gradle.kts").apply { + readText().also { text -> + val toFind = "plugins {" + val toReplace = "$toFind\nid(\"com.squareup.invert\") version \"$INVERT_VERSION\"" + if (!text.contains(toReplace)) { + writeText(text.replace(toFind, toReplace)) + } + } + } + }, + ), - TargetRepo( - org = "gradle", - project = "gradle", - postCheckout = { - // Delete Verification Metadata to disable Dependency Verification - File(it, "gradle/verification-metadata.xml").apply { - if (exists()) { - delete() - } - } - }, - invertGradleCmd = { - // ignoreBuildJavaVersionCheck=true is needed for https://github.com/gradle/gradle for the Java 11/Java 17 mix - "$DEFAULT_INIT_SCRIPT_LINE -Dorg.gradle.ignoreBuildJavaVersionCheck=true" - }, - runOnGitHubAction = false, - ), - TargetRepo( - org = "detekt", - project = "detekt", - ), - TargetRepo( - org = "ZacSweers", - project = "CatchUp", - postCheckout = slackRemoveExclusiveContentPostCheckout, - runInvert = { clonedProjectDir -> - val envVars = mutableMapOf().apply { - val javaHome = System.getenv("JAVA_HOME") - if (!javaHome.contains("21")) { - val home = System.getenv("HOME") - val javaHome21 = - File("$home/Library/Java/JavaVirtualMachines/azul-21.0.3/Contents/Home") - if (!javaHome21.exists()) { - throw IllegalStateException("Java 21 is required.") - } - put("JAVA_HOME", javaHome21.absolutePath) - } - } - executeCmd( - DEFAULT_INIT_SCRIPT_LINE, - clonedProjectDir, - envVars, - ) - }, - hasAnvil = true - ), - TargetRepo( - org = "duckduckgo", - project = "Android", - hasAnvil = true, - ), - TargetRepo( - org = "flipperdevices", - project = "Flipper-Android-App", - hasAnvil = true, - ), -) - .filter { - val isCi = System.getenv().containsKey("GITHUB_ACTIONS") - if (isCi) { - it.runOnGitHubAction - } else { - true + TargetRepo( + org = "gradle", + project = "gradle", + postCheckout = { + // Delete Verification Metadata to disable Dependency Verification + File(it, "gradle/verification-metadata.xml").apply { + if (exists()) { + delete() } + } + }, + invertGradleCmd = { + // ignoreBuildJavaVersionCheck=true is needed for https://github.com/gradle/gradle for the Java 11/Java 17 mix + "$DEFAULT_INIT_SCRIPT_LINE -Dorg.gradle.ignoreBuildJavaVersionCheck=true" + }, + runOnGitHubAction = false, + ), + TargetRepo( + org = "detekt", + project = "detekt", + ), + TargetRepo( + org = "ZacSweers", + project = "CatchUp", + postCheckout = slackRemoveExclusiveContentPostCheckout, + runInvert = { clonedProjectDir -> + val envVars = mutableMapOf().apply { + val javaHome = System.getenv("JAVA_HOME") + if (!javaHome.contains("21")) { + val home = System.getenv("HOME") + val javaHome21 = + File("$home/Library/Java/JavaVirtualMachines/azul-21.0.3/Contents/Home") + if (!javaHome21.exists()) { + throw IllegalStateException("Java 21 is required.") + } + put("JAVA_HOME", javaHome21.absolutePath) + } + } + executeCmd( + DEFAULT_INIT_SCRIPT_LINE, + clonedProjectDir, + envVars, + ) + }, + hasAnvil = true + ), + TargetRepo( + org = "duckduckgo", + project = "Android", + hasAnvil = true, + ), + TargetRepo( + org = "flipperdevices", + project = "Flipper-Android-App", + hasAnvil = true, + ), +) + .filter { + val isCi = System.getenv().containsKey("GITHUB_ACTIONS") + if (isCi) { + it.runOnGitHubAction + } else { + true } + } + .filter { it.org == "flipperdevices" } val CLONES_DIR = File("build/clones").apply { - if (!exists()) { - mkdirs() - } + if (!exists()) { + mkdirs() + } } val STATIC_SITE_FOLDER = File("build/static").apply { - if (exists()) { - deleteRecursively() - } - mkdirs() + if (exists()) { + deleteRecursively() + } + mkdirs() } ALL_REPOS.forEach { targetRepo -> - val PROJECT_CLONE_DIR = File(CLONES_DIR, "${targetRepo.org}/${targetRepo.project}") + val PROJECT_CLONE_DIR = File(CLONES_DIR, "${targetRepo.org}/${targetRepo.project}") - if (!PROJECT_CLONE_DIR.exists()) { - executeCmd( - "git clone --depth=1 ${targetRepo.url}", - PROJECT_CLONE_DIR.parentFile.apply { if (!exists()) mkdirs() } - ) - } else { - executeCmd("git reset --hard HEAD", PROJECT_CLONE_DIR) - executeCmd("git pull", PROJECT_CLONE_DIR) - } + if (!PROJECT_CLONE_DIR.exists()) { + executeCmd( + "git clone --depth=1 ${targetRepo.url}", + PROJECT_CLONE_DIR.parentFile.apply { if (!exists()) mkdirs() } + ) + } else { + executeCmd("git reset --hard HEAD", PROJECT_CLONE_DIR) + executeCmd("git pull", PROJECT_CLONE_DIR) + } - targetRepo.postCheckout(PROJECT_CLONE_DIR) - targetRepo.runInvert(PROJECT_CLONE_DIR) + targetRepo.postCheckout(PROJECT_CLONE_DIR) + targetRepo.runInvert(PROJECT_CLONE_DIR) - val INVERT_REPORT_DIR = File(PROJECT_CLONE_DIR, "${targetRepo.buildDirPath}/reports/invert") + val INVERT_REPORT_DIR = File(PROJECT_CLONE_DIR, "${targetRepo.buildDirPath}/reports/invert") - val OUTPUT_FOLDER = File(STATIC_SITE_FOLDER, "${targetRepo.org}-${targetRepo.project}").apply { - if (exists()) { - deleteRecursively() - } + val OUTPUT_FOLDER = File(STATIC_SITE_FOLDER, "${targetRepo.org}-${targetRepo.project}").apply { + if (exists()) { + deleteRecursively() + } + } + INVERT_REPORT_DIR + .walkTopDown() + .forEach { + val relativePath = it.canonicalPath.replace(INVERT_REPORT_DIR.canonicalPath, "").drop(1) + val OUTPUT_FILE = File(OUTPUT_FOLDER, relativePath) + it.copyTo( + OUTPUT_FILE, + overwrite = true + ) } - INVERT_REPORT_DIR - .walkTopDown() - .forEach { - val relativePath = it.canonicalPath.replace(INVERT_REPORT_DIR.canonicalPath, "").drop(1) - val OUTPUT_FILE = File(OUTPUT_FOLDER, relativePath) - it.copyTo( - OUTPUT_FILE, - overwrite = true - ) - } } val html = buildString { - appendLine("") - appendLine("") - appendLine("

Invert results for GitHub Projects


    ") - STATIC_SITE_FOLDER.listFiles()!! - .mapNotNull { file -> - ALL_REPOS.firstOrNull { repo -> file.name == "${repo.org}-${repo.project}" } - } - .forEach { - println("Found $it") - appendLine("
  • ${it.org}/${it.project} (${it.url})
  • ") - } - appendLine("
") + appendLine("") + appendLine("") + appendLine("

Invert results for GitHub Projects


    ") + STATIC_SITE_FOLDER.listFiles()!! + .mapNotNull { file -> + ALL_REPOS.firstOrNull { repo -> file.name == "${repo.org}-${repo.project}" } + } + .forEach { + println("Found $it") + appendLine("
  • ${it.org}/${it.project} (${it.url})
  • ") + } + appendLine("
") } val HTML_FILE = File(STATIC_SITE_FOLDER, "index.html").apply { - writeText(html) + writeText(html) } \ No newline at end of file