Snapshot Build (#5)

* Test snapshot

* Invert snapshot flag

* Change version format

* Detect if file is properly closed.

* Use ATOMIC_MOVE

* Try using renameTo

* Check if can access before remap

* Check if can access before remap

* Please, delete it

* Can you please work

* Maybe just maybe

* Test

* So it works?
This commit is contained in:
shedaniel
2021-01-23 20:50:52 +08:00
committed by GitHub
parent c1bbb052a5
commit 7f725c16f9
9 changed files with 64 additions and 16 deletions

View File

@@ -1,7 +1,9 @@
name: Java CI
name: Compile & Release
on:
[push]
push:
branches:
- master
jobs:
build:

22
.github/workflows/snapshot.yml vendored Normal file
View File

@@ -0,0 +1,22 @@
name: Snapshot Compile & Release
on:
[pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Upload to Bintray
run: ./gradlew bintrayUpload
env:
BINTRAY_USER: shedaniel
BINTRAY_KEY: ${{ secrets.BINTRAY_KEY }}
PR_NUM: ${{github.event.number}}

View File

@@ -9,7 +9,17 @@ plugins {
}
group "me.shedaniel"
version = "2.0." + (System.getenv("GITHUB_RUN_NUMBER") == null ? (((short) new Random().nextInt()).abs() + 1000).toString() : System.getenv("GITHUB_RUN_NUMBER"))
def isSnapshot = System.getenv("PR_NUM") != null
def runNumber = (System.getenv("GITHUB_RUN_NUMBER") == null ? (((short) new Random().nextInt()).abs() + 1000).toString() : System.getenv("GITHUB_RUN_NUMBER"))
if (!isSnapshot) {
version = base_version + "." + runNumber
} else {
version = base_version + "-PR." + System.getenv("PR_NUM") + "." + runNumber
}
def pluginId = "architectury-plugin"
logger.lifecycle(":building architectury plugin v${version}")
@@ -67,7 +77,7 @@ compileKotlin {
gradlePlugin {
plugins {
architect {
id = 'architectury-plugin'
id = pluginId
implementationClass = 'me.shedaniel.architect.plugin.ArchitectPlugin'
}
}
@@ -100,8 +110,8 @@ bintray {
publishing {
publications {
MyPublication(MavenPublication) {
groupId 'architectury-plugin'
artifactId 'architectury-plugin.gradle.plugin'
groupId pluginId
artifactId pluginId + '.gradle.plugin'
from components.java
artifact(sourcesJar)

View File

@@ -1,2 +1,3 @@
kotlin.code.style=official
loom_version=0.6.33
loom_version=0.6.33
base_version=2.0

View File

@@ -8,6 +8,7 @@ import org.gradle.jvm.tasks.Jar
import java.io.File
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.StandardCopyOption
import java.util.*
import kotlin.properties.Delegates
import kotlin.time.Duration
@@ -28,10 +29,11 @@ open class TransformingTask : Jar() {
.toPath()
}
val output: Path = this.archiveFile.get().asFile.toPath()
Files.deleteIfExists(output)
transformers.forEachIndexed { index, transformer ->
val i = if (index == 0) input else taskOutputs[index - 1]
val o = if (index == taskOutputs.lastIndex) output else taskOutputs[index]
val o = taskOutputs[index]
Files.deleteIfExists(o)
Files.createDirectories(o.parent)
runCatching {
@@ -49,7 +51,18 @@ open class TransformingTask : Jar() {
it
)
}
runCatching {
o.toFile().also { it.renameTo(it) }
}.onFailure {
throw RuntimeException(
"Transformer step ${index + 1}/${transformers.size} [${transformer::class.simpleName}] did not properly close the output file!",
it
)
}
}
Files.move(taskOutputs.last(), output, StandardCopyOption.REPLACE_EXISTING)
}
operator fun invoke(transformer: Transformer) {

View File

@@ -47,10 +47,9 @@ object RemapMixinVariables : Transformer {
remapper.apply(outputConsumer)
}
} catch (e: Exception) {
remapper.finish()
throw RuntimeException("Failed to remap $input to $output", e)
} finally {
remapper.finish()
}
remapper.finish()
}
}

View File

@@ -37,8 +37,9 @@ object TransformForgeEnvironment : Transformer {
remapper.apply(outputConsumer)
}
} catch (e: Exception) {
remapper.finish()
throw RuntimeException("Failed to remap $input to $output", e)
} finally {
remapper.finish()
}
}

View File

@@ -59,8 +59,9 @@ object TransformInjectables : Transformer {
remapper.apply(outputConsumer)
}
} catch (e: Exception) {
remapper.finish()
throw RuntimeException("Failed to remap $input to $output", e)
} finally {
remapper.finish()
}
}
}

View File

@@ -39,8 +39,7 @@ object Transform {
}
output.toFile().writeBytes(allBytes)
} else {
val zipOutputStream = ZipOutputStream(output.toFile().outputStream())
zipOutputStream.use {
ZipOutputStream(output.toFile().outputStream()).use { zipOutputStream ->
ZipInputStream(Files.newInputStream(input)).use {
while (true) {
val entry = it.nextEntry ?: break