-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
213 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
buildSrc/src/main/kotlin/orx.collect-screenshots.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.