Reimplement collectScreenshots

This commit is contained in:
Edwin Jakobs
2021-08-31 15:22:31 +02:00
parent 9a2f10f81d
commit 46dfc06ab1
15 changed files with 213 additions and 176 deletions

View File

@@ -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

View File

@@ -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 == "<!-- __demos__ -->" }
if (screenshotsLine != -1) {
lines = lines.subList(0, screenshotsLine)
}
lines.add("<!-- __demos__ -->")
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 }
//}

View File

@@ -6,7 +6,9 @@ plugins {
repositories {
mavenCentral()
gradlePluginPortal()
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30")
}

View File

@@ -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<FileCollection>
@get:OutputDirectory
abstract val outputDir: DirectoryProperty
@get:Input
abstract val ignore: ListProperty<String>
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 == "<!-- __demos__ -->" }
if (screenshotsLine != -1) {
lines = lines.subList(0, screenshotsLine)
}
lines.add("<!-- __demos__ -->")
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<CollectScreenshotsTask>("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
}
}

View File

@@ -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)

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -106,17 +106,7 @@ All distortion effects are opacity preserving
![DemoFluidDistort01Kt](https://github.com/openrndr/orx/blob/media/orx-fx/images/DemoFluidDistort01Kt.png
<!-- __demos__ -->
## 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)

View File

@@ -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 {
@@ -112,10 +119,3 @@ 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)

View File

@@ -1,5 +1,3 @@
package org.openrndr.extra.fx.demo
import org.openrndr.application
import org.openrndr.extra.fx.blend.*
fun main() {

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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)

View File

@@ -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 {