Add orx-git-archiver
This commit is contained in:
25
orx-jvm/orx-git-archiver/build.gradle
Normal file
25
orx-jvm/orx-git-archiver/build.gradle
Normal file
@@ -0,0 +1,25 @@
|
||||
sourceSets {
|
||||
demo {
|
||||
java {
|
||||
srcDirs = ["src/demo/kotlin"]
|
||||
compileClasspath += main.getCompileClasspath()
|
||||
runtimeClasspath += main.getRuntimeClasspath()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.eclipse.jgit:org.eclipse.jgit:5.12.0.202106070339-r'
|
||||
|
||||
demoImplementation(project(":orx-camera"))
|
||||
demoImplementation(project(":orx-mesh-generators"))
|
||||
demoImplementation(project(":orx-noise"))
|
||||
|
||||
demoImplementation("org.openrndr:openrndr-application:$openrndrVersion")
|
||||
demoImplementation("org.openrndr:openrndr-extensions:$openrndrVersion")
|
||||
demoImplementation("org.openrndr:openrndr-ffmpeg:$openrndrVersion")
|
||||
demoImplementation("org.openrndr:openrndr-filter:$openrndrVersion")
|
||||
demoRuntimeOnly("org.openrndr:openrndr-gl3:$openrndrVersion")
|
||||
demoRuntimeOnly("org.openrndr:openrndr-gl3-natives-$openrndrOS:$openrndrVersion")
|
||||
demoImplementation(sourceSets.getByName("main").output)
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import org.openrndr.applicationSynchronous
|
||||
import org.openrndr.extensions.Screenshots
|
||||
|
||||
fun main() = applicationSynchronous {
|
||||
program {
|
||||
val ga = extend(GitArchiver()) {
|
||||
commitOnRun = false
|
||||
commitOnProduceAssets = false
|
||||
}
|
||||
extend(Screenshots())
|
||||
extend {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
63
orx-jvm/orx-git-archiver/src/main/kotlin/GitArchiver.kt
Normal file
63
orx-jvm/orx-git-archiver/src/main/kotlin/GitArchiver.kt
Normal file
@@ -0,0 +1,63 @@
|
||||
import mu.KotlinLogging
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.eclipse.jgit.internal.storage.file.FileRepository
|
||||
import org.eclipse.jgit.lib.Constants
|
||||
import org.openrndr.AssetMetadata
|
||||
import org.openrndr.Extension
|
||||
import org.openrndr.Program
|
||||
|
||||
val logger = KotlinLogging.logger { }
|
||||
class GitArchiver : Extension {
|
||||
override var enabled: Boolean = true
|
||||
|
||||
var commitOnRun = false
|
||||
var commitOnProduceAssets = true
|
||||
|
||||
var autoCommitMessage = "auto commit"
|
||||
|
||||
private val repo = FileRepository(".git")
|
||||
private val git = Git(repo)
|
||||
|
||||
|
||||
fun commitChanges() {
|
||||
git.add().addFilepattern("src").call()
|
||||
git.commit().setMessage(autoCommitMessage).call()
|
||||
}
|
||||
|
||||
fun tag(name: String) : Boolean {
|
||||
val existing = git.tagList().call().find { it.name == name }
|
||||
if (existing != null) {
|
||||
git.tag().setName(name).call()
|
||||
} else {
|
||||
logger.warn { "tag $name exists" }
|
||||
}
|
||||
return existing != null
|
||||
}
|
||||
|
||||
val commitHash:String
|
||||
get() {
|
||||
val id = repo.resolve(Constants.HEAD)
|
||||
return id.name
|
||||
}
|
||||
|
||||
override fun setup(program: Program) {
|
||||
val oldMetadataFunction = program.assetMetadata
|
||||
program.assetMetadata = {
|
||||
val oldMetadata = oldMetadataFunction()
|
||||
val commitHash = this.commitHash.take(7)
|
||||
program.assetProperties["git-commit-hash"] = commitHash
|
||||
logger.info { "current commit hash '$commitHash'" }
|
||||
AssetMetadata(oldMetadata.programName, "${oldMetadata.assetBaseName}$commitHash", program.assetProperties.mapValues { it.value })
|
||||
}
|
||||
|
||||
program.produceAssets.listen {
|
||||
if (commitOnProduceAssets) {
|
||||
commitChanges()
|
||||
}
|
||||
}
|
||||
|
||||
if (commitOnRun) {
|
||||
commitChanges()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user