From 46dfc06ab165fd0fd44be13079f36d3e37e86831 Mon Sep 17 00:00:00 2001 From: Edwin Jakobs Date: Tue, 31 Aug 2021 15:22:31 +0200 Subject: [PATCH] Reimplement collectScreenshots --- .github/workflows/generate-screenshots.yml | 46 ++++++ build.gradle | 142 +----------------- buildSrc/build.gradle.kts | 2 + .../kotlin/orx.collect-screenshots.gradle.kts | 90 +++++++++++ orx-color/README.md | 20 +-- orx-color/build.gradle.kts | 5 +- orx-compositor/build.gradle.kts | 5 + orx-easing/build.gradle.kts | 6 +- orx-fx/README.md | 10 -- orx-fx/build.gradle.kts | 16 +- orx-fx/src/demo/kotlin/DemoBlend01.kt | 2 - orx-quadtree/build.gradle.kts | 7 +- orx-shade-styles/build.gradle.kts | 5 +- orx-shapes/README.md | 25 +++ orx-shapes/build.gradle.kts | 8 +- 15 files changed, 213 insertions(+), 176 deletions(-) create mode 100644 .github/workflows/generate-screenshots.yml create mode 100644 buildSrc/src/main/kotlin/orx.collect-screenshots.gradle.kts diff --git a/.github/workflows/generate-screenshots.yml b/.github/workflows/generate-screenshots.yml new file mode 100644 index 000000000..0790d6071 --- /dev/null +++ b/.github/workflows/generate-screenshots.yml @@ -0,0 +1,46 @@ +name: Generate screenshots +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-java@v1 + with: + java-version: 16 + - uses: openrndr/setup-opengl@v1.1 + - name: Test glxinfo + run: | + echo $LD_LIBRARY_PATH + export GALLIUM_DRIVER=swr + xvfb-run glxinfo + + - uses: actions/cache@v2 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: Collect screenshots + run: xvfb-run ./gradlew collectScreenshots + - name: Build main readme + run: xvfb-run ./gradlew buildMainReadme + - name: Prepare media branch + run: | + git config --global user.email "actions@openrndr.org" + git config --global user.name "OPENRNDR Actions" + git reset HEAD -- . + (git add README.md && git commit -m "add auto-generated README" && git push origin master) || true + (git add [a-z-]*/README.md && git commit -m "add demos to README.md" && git push origin master) || true + git checkout --orphan media + git reset HEAD -- . + git add [a-z-]*/images/*.png + git commit -m "add auto-generated media" + git push -f origin media diff --git a/build.gradle b/build.gradle index 3c3b5dace..020c07481 100644 --- a/build.gradle +++ b/build.gradle @@ -12,8 +12,8 @@ buildscript { plugins { // remember to update all the versions here when upgrading kotlin version - id 'org.jetbrains.kotlin.jvm' version '1.5.30' apply false - id 'org.jetbrains.kotlin.multiplatform' version '1.5.30' apply false + id 'org.jetbrains.kotlin.jvm' apply false + id 'org.jetbrains.kotlin.multiplatform' apply false id 'org.jetbrains.kotlin.plugin.serialization' version '1.5.30' apply false } @@ -32,7 +32,6 @@ def multiplatformModules = [ "orx-shader-phrases", "orx-shapes", "orx-quadtree", - ] project.ext { @@ -101,62 +100,6 @@ dokka { sourceDirs = files(subprojects.collect { p -> new File(p.projectDir, "/src/main/kotlin") }) } -//allprojects { -// apply plugin: 'idea' -// apply plugin: 'java' -// apply plugin: 'kotlin' -// apply plugin: 'nebula.release' -// -// apply plugin: "com.github.ben-manes.versions" -// -// group 'org.openrndr.extra' -// -// repositories { -// if (openrndrUseSnapshot) { -// mavenLocal() -// } -// -// mavenCentral() -// jcenter() -// maven { -// url "https://dl.bintray.com/spekframework/spek" -// } -// } -// -// dependencies { -// implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion" -// implementation 'io.github.microutils:kotlin-logging-jvm:2.0.6' -// implementation "org.openrndr:openrndr-application:$openrndrVersion" -// implementation "org.openrndr:openrndr-shape:$openrndrVersion" -// implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: '1.4.3' -// testImplementation "org.spekframework.spek2:spek-dsl-jvm:$spekVersion" -// testImplementation "org.amshove.kluent:kluent:1.65" -// testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlinVersion" -// testRuntimeOnly "org.spekframework.spek2:spek-runner-junit5:$spekVersion" -// testRuntimeOnly "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion" -// runtimeOnly "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion" -// } -// -// java { -// sourceCompatibility = JavaVersion.VERSION_1_8 -// targetCompatibility = JavaVersion.VERSION_1_8 -// } -// javadoc { -// options.addBooleanOption 'Xdoclint:none', true -// } -// -// test { -// useJUnitPlatform { -// includeEngines 'spek2' -// } -// } -// tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { -// kotlinOptions { -// jvmTarget = "1.8" -// } -// } -//} - task buildMainReadme { doFirst { def subProjects = project.subprojects @@ -238,80 +181,9 @@ task buildMainReadme { } } -task collectScreenshots { - doFirst { - def demoProjects = project.subprojects.findAll { it.sourceSets.hasProperty("demo") } - for (sub in demoProjects) { - if (sub.name == "openrndr-demos") - continue - if (sub.name == "orx-rabbit-control") - continue - if (sub.name == "orx-runway") - continue - if (sub.name == "orx-chataigne") - continue - if (sub.name == "orx-video-profiles") - continue - if (sub.name == "orx-realsense2") - continue - def set = sub.sourceSets.demo - def ucl = new URLClassLoader(set.runtimeClasspath.collect { it.toURI().toURL() } as URL[]) - - def runDemos = [] - - for (x in set.output) { - if (x.exists()) { - for (y in x.listFiles()) { - def name = y.name - if (!name.contains('$') && name.contains(".class")) { - def klassName = y.name.replace(".class", "") - def klass = ucl.loadClass(klassName) - try { - def mainMethod = klass.getMethod("main") - println "Collecting screenshot for ${klassName}" - javaexec { - classpath += set.runtimeClasspath - classpath += set.compileClasspath - def className = y.name.replace(".class", "") - main = className - jvmArgs += "-DtakeScreenshot=true" - jvmArgs += "-DscreenshotPath=${sub.name}/images/${className}.png" - jvmArgs += "-Dorg.openrndr.exceptions=JVM" - } - runDemos.add(klassName) - } catch (e) { - e.printStackTrace() - } - } - } - } - } - runDemos = runDemos.sort() - def readme = sub.file("README.md") - if (readme.exists()) { - def lines = readme.readLines() - def screenshotsLine = lines.findIndexOf { it == "" } - if (screenshotsLine != -1) { - lines = lines.subList(0, screenshotsLine) - } - lines.add("") - lines.add("## Demos") - for (demo in runDemos) { - lines.add("### ${demo[0..-3]}") - lines.add("[source code](src/demo/kotlin/${demo[0..-3]}.kt)") - lines.add("") - lines.add("![${demo}](https://raw.githubusercontent.com/openrndr/orx/media/${sub.name}/images/${demo}.png)") - lines.add("") - } - readme.delete() - readme.write(lines.join("\n")) - } - } - } -} configure(allprojects.findAll { !multiplatformModules.contains(it.name) }) { - apply plugin: 'idea' +// apply plugin: 'idea' apply plugin: 'java' apply plugin: 'kotlin' apply plugin: 'maven-publish' @@ -360,8 +232,6 @@ configure(allprojects.findAll { !multiplatformModules.contains(it.name) }) { tasks.withType(org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile).all { kotlinOptions.freeCompilerArgs += ["-Xuse-experimental=kotlinx.coroutines.InternalCoroutinesApi"] } - - } configure(allprojects.findAll { it.name != "openrndr-demos" }) { @@ -370,6 +240,6 @@ configure(allprojects.findAll { it.name != "openrndr-demos" }) { } -collectScreenshots.dependsOn { - project.subprojects.findAll { it.sourceSets.hasProperty("demo") }.collect { it.tasks.demoClasses } -} +//collectScreenshots.dependsOn { +// project.subprojects.findAll { it.sourceSets.hasProperty("demo") }.collect { it.tasks.demoClasses } +//} diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index ded7207f0..638ca7426 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -6,7 +6,9 @@ plugins { repositories { mavenCentral() + gradlePluginPortal() } dependencies { + implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30") } diff --git a/buildSrc/src/main/kotlin/orx.collect-screenshots.gradle.kts b/buildSrc/src/main/kotlin/orx.collect-screenshots.gradle.kts new file mode 100644 index 000000000..af2248e3e --- /dev/null +++ b/buildSrc/src/main/kotlin/orx.collect-screenshots.gradle.kts @@ -0,0 +1,90 @@ +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmCompilation +import java.net.URLClassLoader + +abstract class CollectScreenshotsTask @Inject constructor() : DefaultTask() { + @get:Incremental + @get:PathSensitive(PathSensitivity.NAME_ONLY) + @get:InputDirectory + abstract val inputDir: DirectoryProperty + + @get:Input + abstract val runtimeDependencies: Property + + @get:OutputDirectory + abstract val outputDir: DirectoryProperty + + @get:Input + abstract val ignore: ListProperty + + + init { + ignore.set(emptyList()) + } + @TaskAction + fun execute(inputChanges: InputChanges) { + inputChanges.getFileChanges(inputDir).forEach { change -> + if (change.fileType == FileType.DIRECTORY) return@forEach + if (change.file.extension == "class" && !(change.file.name.contains("$"))) { + val klassName = change.file.nameWithoutExtension + if (klassName.dropLast(2) in ignore.get()) + return@forEach + + val cp = (runtimeDependencies.get().map { it.toURI().toURL() } + inputDir.get().asFile.toURI().toURL()) + .toTypedArray() + + val ucl = URLClassLoader(cp) + + + + + val klass = ucl.loadClass(klassName) + println("Collecting screenshot for ${klassName} ${klass}") + + val mainMethod = klass.getMethod("main") + println(mainMethod) + project.javaexec { + this.classpath += project.files(inputDir.get().asFile) + this.classpath += runtimeDependencies.get() + this.mainClass.set(klassName) + this.workingDir(project.rootProject.projectDir) + jvmArgs("-DtakeScreenshot=true", "-DscreenshotPath=${outputDir.get().asFile}/$klassName.png") + } + } + } + // this is only executed if there are chances in the inputDir + val runDemos = outputDir.get().asFile.listFiles { file: File -> + file.extension == "png" + }.map { it.nameWithoutExtension } + val readme = File(project.projectDir, "README.md") + if (readme.exists()) { + var lines = readme.readLines().toMutableList() + val screenshotsLine = lines.indexOfFirst { it == "" } + if (screenshotsLine != -1) { + lines = lines.subList(0, screenshotsLine) + } + lines.add("") + lines.add("## Demos") + for (demo in runDemos) { + lines.add("### ${demo.dropLast(2)}") + lines.add("[source code](src/demo/kotlin/${demo.dropLast(2)}.kt)") + lines.add("") + lines.add("![${demo}](https://raw.githubusercontent.com/openrndr/orx/media/${project.name}/images/${demo}.png)") + lines.add("") + } + readme.delete() + readme.writeText(lines.joinToString("\n")) + } + } +} + +object ScreenshotsHelper { + fun KotlinJvmCompilation.collectScreenshots(config: CollectScreenshotsTask.() -> Unit): CollectScreenshotsTask { + val task = this.project.tasks.register("collectScreenshots").get() + task.outputDir.set(project.file(project.projectDir.toString() + "/images")) + task.inputDir.set(output.classesDirs.first()) + task.runtimeDependencies.set(runtimeDependencyFiles) + task.config() + return task + } +} + diff --git a/orx-color/README.md b/orx-color/README.md index a043efb5f..d01fd8899 100644 --- a/orx-color/README.md +++ b/orx-color/README.md @@ -79,16 +79,6 @@ Two color spaces are added: `ColorHSLUVa` and `ColorHPLUVa`, they are an impleme ![DemoColorRange04Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoColorRange04Kt.png) -### DemoHSLUV01 -[source code](src/demo/kotlin/DemoHSLUV01.kt) - -![DemoHSLUV01Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoHSLUV01Kt.png) - -### DemoHSLUV02 -[source code](src/demo/kotlin/DemoHSLUV02.kt) - -![DemoHSLUV02Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoHSLUV02Kt.png) - ### DemoHistogram01 [source code](src/demo/kotlin/DemoHistogram01.kt) @@ -104,6 +94,16 @@ Two color spaces are added: `ColorHSLUVa` and `ColorHPLUVa`, they are an impleme ![DemoHistogram03Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoHistogram03Kt.png) +### DemoHSLUV01 +[source code](src/demo/kotlin/DemoHSLUV01.kt) + +![DemoHSLUV01Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoHSLUV01Kt.png) + +### DemoHSLUV02 +[source code](src/demo/kotlin/DemoHSLUV02.kt) + +![DemoHSLUV02Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoHSLUV02Kt.png) + ### DemoXSLUV01 [source code](src/demo/kotlin/DemoXSLUV01.kt) diff --git a/orx-color/build.gradle.kts b/orx-color/build.gradle.kts index bba4c390c..82839061f 100644 --- a/orx-color/build.gradle.kts +++ b/orx-color/build.gradle.kts @@ -1,9 +1,9 @@ -import Orx_embed_shaders_gradle.EmbedShadersTask +import Orx_collect_screenshots_gradle.ScreenshotsHelper.collectScreenshots plugins { kotlin("multiplatform") kotlin("plugin.serialization") - id("orx.embed-shaders") + id("orx.collect-screenshots") } val kotlinxSerializationVersion: String by rootProject.extra @@ -36,6 +36,7 @@ kotlin { runtimeOnly("org.openrndr:openrndr-gl3-natives-$openrndrOS:$openrndrVersion") implementation(compilations["main"]!!.output.allOutputs) } + collectScreenshots { } } } compilations.all { diff --git a/orx-compositor/build.gradle.kts b/orx-compositor/build.gradle.kts index 5b15b911f..c8f1a4025 100644 --- a/orx-compositor/build.gradle.kts +++ b/orx-compositor/build.gradle.kts @@ -1,6 +1,9 @@ +import Orx_collect_screenshots_gradle.ScreenshotsHelper.collectScreenshots + plugins { kotlin("multiplatform") kotlin("plugin.serialization") + id("orx.collect-screenshots") } val kotlinxSerializationVersion: String by rootProject.extra @@ -31,6 +34,8 @@ kotlin { implementation(compilations["main"]!!.output.allOutputs) } } + collectScreenshots { + } } } compilations.all { diff --git a/orx-easing/build.gradle.kts b/orx-easing/build.gradle.kts index 3a5fed5a7..2e43b7f26 100644 --- a/orx-easing/build.gradle.kts +++ b/orx-easing/build.gradle.kts @@ -1,9 +1,9 @@ -import Orx_embed_shaders_gradle.EmbedShadersTask +import Orx_collect_screenshots_gradle.ScreenshotsHelper.collectScreenshots plugins { kotlin("multiplatform") kotlin("plugin.serialization") - id("orx.embed-shaders") + id("orx.collect-screenshots") } val kotlinxSerializationVersion: String by rootProject.extra @@ -33,6 +33,8 @@ kotlin { implementation(compilations["main"]!!.output.allOutputs) } } + collectScreenshots { + } } } compilations.all { diff --git a/orx-fx/README.md b/orx-fx/README.md index 6ac25841f..f27f1d34b 100644 --- a/orx-fx/README.md +++ b/orx-fx/README.md @@ -106,17 +106,7 @@ All distortion effects are opacity preserving ![DemoFluidDistort01Kt](https://github.com/openrndr/orx/blob/media/orx-fx/images/DemoFluidDistort01Kt.png ## Demos -### DemoBlur01 -[source code](src/demo/kotlin/DemoBlur01.kt) - -![DemoBlur01Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-fx/images/DemoBlur01Kt.png) - ### DemoFluidDistort01 [source code](src/demo/kotlin/DemoFluidDistort01.kt) ![DemoFluidDistort01Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-fx/images/DemoFluidDistort01Kt.png) - -### DemoLaserBlur01 -[source code](src/demo/kotlin/DemoLaserBlur01.kt) - -![DemoLaserBlur01Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-fx/images/DemoLaserBlur01Kt.png) diff --git a/orx-fx/build.gradle.kts b/orx-fx/build.gradle.kts index ce8d2e3f6..89b70b35c 100644 --- a/orx-fx/build.gradle.kts +++ b/orx-fx/build.gradle.kts @@ -1,9 +1,12 @@ +import Orx_collect_screenshots_gradle.ScreenshotsHelper.collectScreenshots import Orx_embed_shaders_gradle.EmbedShadersTask + plugins { kotlin("multiplatform") kotlin("plugin.serialization") id("orx.embed-shaders") + id("orx.collect-screenshots") } val kotlinxSerializationVersion: String by rootProject.extra @@ -42,6 +45,10 @@ kotlin { implementation(compilations["main"]!!.output.allOutputs) } } + collectScreenshots { + ignore.set(listOf("DemoBlur01")) + + } } } compilations.all { @@ -111,11 +118,4 @@ kotlin { } } } -} - - -//tasks.getByName("compileKotlinJvm").dependsOn(embedShaders) -//tasks.getByName("compileKotlinJs").dependsOn(embedShaders) -//tasks.getByName("compileKotlinMetadata").dependsOn(embedShaders) -//tasks.getByName("jvmSourcesJar").dependsOn(embedShaders) -//tasks.getByName("sourcesJar").dependsOn(embedShaders) +} \ No newline at end of file diff --git a/orx-fx/src/demo/kotlin/DemoBlend01.kt b/orx-fx/src/demo/kotlin/DemoBlend01.kt index 66af87675..ecdf78c9d 100644 --- a/orx-fx/src/demo/kotlin/DemoBlend01.kt +++ b/orx-fx/src/demo/kotlin/DemoBlend01.kt @@ -1,5 +1,3 @@ -package org.openrndr.extra.fx.demo - import org.openrndr.application import org.openrndr.extra.fx.blend.* fun main() { diff --git a/orx-quadtree/build.gradle.kts b/orx-quadtree/build.gradle.kts index 3a978b2c9..ff5054834 100644 --- a/orx-quadtree/build.gradle.kts +++ b/orx-quadtree/build.gradle.kts @@ -1,9 +1,9 @@ -import Orx_embed_shaders_gradle.EmbedShadersTask +import Orx_collect_screenshots_gradle.ScreenshotsHelper.collectScreenshots plugins { kotlin("multiplatform") kotlin("plugin.serialization") - id("orx.embed-shaders") + id("orx.collect-screenshots") } val kotlinxSerializationVersion: String by rootProject.extra @@ -34,6 +34,9 @@ kotlin { implementation(compilations["main"]!!.output.allOutputs) } } + collectScreenshots { + + } } } compilations.all { diff --git a/orx-shade-styles/build.gradle.kts b/orx-shade-styles/build.gradle.kts index a93ecfef6..781ee12b7 100644 --- a/orx-shade-styles/build.gradle.kts +++ b/orx-shade-styles/build.gradle.kts @@ -1,9 +1,10 @@ -import Orx_embed_shaders_gradle.EmbedShadersTask +import Orx_collect_screenshots_gradle.ScreenshotsHelper.collectScreenshots plugins { kotlin("multiplatform") kotlin("plugin.serialization") id("orx.embed-shaders") + id("orx.collect-screenshots") } val kotlinxSerializationVersion: String by rootProject.extra @@ -32,6 +33,7 @@ kotlin { runtimeOnly("org.openrndr:openrndr-gl3-natives-$openrndrOS:$openrndrVersion") implementation(compilations["main"]!!.output.allOutputs) } + collectScreenshots { } } } } @@ -63,6 +65,7 @@ kotlin { implementation("io.github.microutils:kotlin-logging:$kotlinLoggingVersion") } } + @Suppress("UNUSED_VARIABLE") val commonTest by getting { dependencies { diff --git a/orx-shapes/README.md b/orx-shapes/README.md index 394a2d418..36a13caee 100644 --- a/orx-shapes/README.md +++ b/orx-shapes/README.md @@ -24,6 +24,31 @@ Collection of 2D shape generators (polygon, star, rounded rectangle) and shape m ![DemoBezierPatch04Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-shapes/images/DemoBezierPatch04Kt.png) +### DemoBezierPatch05 +[source code](src/demo/kotlin/DemoBezierPatch05.kt) + +![DemoBezierPatch05Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-shapes/images/DemoBezierPatch05Kt.png) + +### DemoBezierPatchDrawer01 +[source code](src/demo/kotlin/DemoBezierPatchDrawer01.kt) + +![DemoBezierPatchDrawer01Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-shapes/images/DemoBezierPatchDrawer01Kt.png) + +### DemoBezierPatchDrawer02 +[source code](src/demo/kotlin/DemoBezierPatchDrawer02.kt) + +![DemoBezierPatchDrawer02Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-shapes/images/DemoBezierPatchDrawer02Kt.png) + +### DemoBezierPatchDrawer03 +[source code](src/demo/kotlin/DemoBezierPatchDrawer03.kt) + +![DemoBezierPatchDrawer03Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-shapes/images/DemoBezierPatchDrawer03Kt.png) + +### DemoBezierPatches01 +[source code](src/demo/kotlin/DemoBezierPatches01.kt) + +![DemoBezierPatches01Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-shapes/images/DemoBezierPatches01Kt.png) + ### DemoRectangleGrid [source code](src/demo/kotlin/DemoRectangleGrid.kt) diff --git a/orx-shapes/build.gradle.kts b/orx-shapes/build.gradle.kts index 7d8c51b32..eeb97de9a 100644 --- a/orx-shapes/build.gradle.kts +++ b/orx-shapes/build.gradle.kts @@ -1,9 +1,8 @@ -import Orx_embed_shaders_gradle.EmbedShadersTask - +import Orx_collect_screenshots_gradle.ScreenshotsHelper.collectScreenshots plugins { kotlin("multiplatform") kotlin("plugin.serialization") - id("orx.embed-shaders") + id("orx.collect-screenshots") } val kotlinxSerializationVersion: String by rootProject.extra @@ -34,6 +33,9 @@ kotlin { implementation(compilations["main"]!!.output.allOutputs) } } + collectScreenshots { + + } } } compilations.all {