diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 51307bc..20b04c0 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -1,7 +1,9 @@ -name: Java CI +name: Compile & Release on: - [push] + push: + branches: + - master jobs: build: diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml new file mode 100644 index 0000000..6646d0c --- /dev/null +++ b/.github/workflows/snapshot.yml @@ -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}} \ No newline at end of file diff --git a/build.gradle b/build.gradle index 177d036..bd6fb61 100644 --- a/build.gradle +++ b/build.gradle @@ -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) diff --git a/gradle.properties b/gradle.properties index 458942e..364a910 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,3 @@ kotlin.code.style=official -loom_version=0.6.33 \ No newline at end of file +loom_version=0.6.33 +base_version=2.0 \ No newline at end of file diff --git a/src/main/kotlin/me/shedaniel/architect/plugin/TransformingTask.kt b/src/main/kotlin/me/shedaniel/architect/plugin/TransformingTask.kt index 0167cce..e7259b0 100644 --- a/src/main/kotlin/me/shedaniel/architect/plugin/TransformingTask.kt +++ b/src/main/kotlin/me/shedaniel/architect/plugin/TransformingTask.kt @@ -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) { diff --git a/src/main/kotlin/me/shedaniel/architect/plugin/transformers/RemapMixinVariables.kt b/src/main/kotlin/me/shedaniel/architect/plugin/transformers/RemapMixinVariables.kt index 7502a75..11abc23 100644 --- a/src/main/kotlin/me/shedaniel/architect/plugin/transformers/RemapMixinVariables.kt +++ b/src/main/kotlin/me/shedaniel/architect/plugin/transformers/RemapMixinVariables.kt @@ -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() } } \ No newline at end of file diff --git a/src/main/kotlin/me/shedaniel/architect/plugin/transformers/TransformForgeEnvironment.kt b/src/main/kotlin/me/shedaniel/architect/plugin/transformers/TransformForgeEnvironment.kt index b87cc1b..53f386a 100644 --- a/src/main/kotlin/me/shedaniel/architect/plugin/transformers/TransformForgeEnvironment.kt +++ b/src/main/kotlin/me/shedaniel/architect/plugin/transformers/TransformForgeEnvironment.kt @@ -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() } } diff --git a/src/main/kotlin/me/shedaniel/architect/plugin/transformers/TransformInjectables.kt b/src/main/kotlin/me/shedaniel/architect/plugin/transformers/TransformInjectables.kt index ff89406..9f06679 100644 --- a/src/main/kotlin/me/shedaniel/architect/plugin/transformers/TransformInjectables.kt +++ b/src/main/kotlin/me/shedaniel/architect/plugin/transformers/TransformInjectables.kt @@ -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() } } } \ No newline at end of file diff --git a/src/main/kotlin/me/shedaniel/architect/plugin/utils/Transform.kt b/src/main/kotlin/me/shedaniel/architect/plugin/utils/Transform.kt index f5a40f3..e6b7e19 100644 --- a/src/main/kotlin/me/shedaniel/architect/plugin/utils/Transform.kt +++ b/src/main/kotlin/me/shedaniel/architect/plugin/utils/Transform.kt @@ -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