From 406872d8e1ae7ef1f9e4b8bd1269c3e413d735b4 Mon Sep 17 00:00:00 2001 From: Sebastian Hartte Date: Tue, 10 Dec 2024 12:52:23 +0100 Subject: [PATCH 1/3] Run a ZIP optimizer to get ~10% of ZIP size reduction --- .github/workflows/check.yml | 4 +++- build.gradle | 15 ++++++++++++++- gradle.properties | 5 ++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 4da65e0a..02296b44 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -95,6 +95,8 @@ jobs: - run: | git config --global user.name github-actions git config --global user.email 41898282+github-actions[bot]@users.noreply.github.com + - name: Install advzip for ZIP optimization + run: apt install advancecomp - name: Setup Gradle uses: gradle/actions/setup-gradle@v3 with: @@ -118,7 +120,7 @@ jobs: VERSION_NAME: ${{ fromJson(steps.split_version.outputs.result).version_name }} VERSION_TYPE: ${{ fromJson(steps.split_version.outputs.result).version_type }} if: ${{ always() }} - run: ./gradlew :$VERSION_NAME:makeZip -Ptype=$VERSION_TYPE + run: ./gradlew :$VERSION_NAME:makeZip -Ptype=$VERSION_TYPE -Poptimize_zip=true - name: Upload Zip as Artifact if: ${{ always() }} uses: actions/upload-artifact@v4 diff --git a/build.gradle b/build.gradle index 3cd459de..97132f48 100644 --- a/build.gradle +++ b/build.gradle @@ -781,7 +781,8 @@ subprojects { } } - task makeZip(type: Zip, dependsOn: [generateConfiguration]) { + def makeZip = tasks.register('makeZip', Zip) { + dependsOn generateConfiguration archiveBaseName = rootProject.name archiveVersion = project.version destinationDirectory = file(PATH_BUILD + '/distributions') @@ -815,6 +816,18 @@ subprojects { } } + // This uses advzip: https://linux.die.net/man/1/advzip + def optimizeZip = tasks.register('optimizeZip', Exec) { + description = "Optimizes the NeoForm ZIP-file in-place" + commandLine "advzip", "--recompress", "-k", "-4", makeZip.flatMap(Zip::getArchiveFile) + if (optimize_zip) { + mustRunAfter makeZip + } + } + if (optimize_zip) { + makeZip.configure { finalizedBy optimizeZip } + } + def componentMaker = objects.newInstance(ComponentMaker) def neoformComponent = componentMaker.componentFactory.adhoc('neoform') components.add(neoformComponent) diff --git a/gradle.properties b/gradle.properties index 3620c405..2c7ae5c3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,6 @@ org.gradle.parallel=true org.gradle.caching=true -org.gradle.configuration-cache=true \ No newline at end of file +org.gradle.configuration-cache=true + +# Run ZIP optimizations using advzip, which requires the tool to be installed +optimize_zip=false From 965aa5c1dc518cb4fc5f62f0ce59ecdf3291a135 Mon Sep 17 00:00:00 2001 From: Sebastian Hartte Date: Tue, 10 Dec 2024 12:57:45 +0100 Subject: [PATCH 2/3] Run a ZIP optimizer to get ~10% of ZIP size reduction --- .github/workflows/check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 02296b44..f88bcd2e 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -96,7 +96,7 @@ jobs: git config --global user.name github-actions git config --global user.email 41898282+github-actions[bot]@users.noreply.github.com - name: Install advzip for ZIP optimization - run: apt install advancecomp + run: sudo apt install advancecomp - name: Setup Gradle uses: gradle/actions/setup-gradle@v3 with: From 49871131142ac07b5175406578091bf62a1044a8 Mon Sep 17 00:00:00 2001 From: Sebastian Hartte Date: Tue, 10 Dec 2024 13:12:17 +0100 Subject: [PATCH 3/3] We have to use an arg provider :-| --- build.gradle | 11 +++++++---- .../tasks/PathArgumentProvider.groovy | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 buildSrc/src/main/groovy/net/minecraftforge/mcpconfig/tasks/PathArgumentProvider.groovy diff --git a/build.gradle b/build.gradle index 97132f48..ccd9fdde 100644 --- a/build.gradle +++ b/build.gradle @@ -818,11 +818,14 @@ subprojects { // This uses advzip: https://linux.die.net/man/1/advzip def optimizeZip = tasks.register('optimizeZip', Exec) { + dependsOn makeZip description = "Optimizes the NeoForm ZIP-file in-place" - commandLine "advzip", "--recompress", "-k", "-4", makeZip.flatMap(Zip::getArchiveFile) - if (optimize_zip) { - mustRunAfter makeZip - } + commandLine "advzip", "--recompress", "-k", "-4" + argumentProviders.add( + objects.newInstance(ZipPathArgumentProvider).tap { + file = makeZip.flatMap(AbstractArchiveTask::getArchiveFile) + } + ) } if (optimize_zip) { makeZip.configure { finalizedBy optimizeZip } diff --git a/buildSrc/src/main/groovy/net/minecraftforge/mcpconfig/tasks/PathArgumentProvider.groovy b/buildSrc/src/main/groovy/net/minecraftforge/mcpconfig/tasks/PathArgumentProvider.groovy new file mode 100644 index 00000000..57efc1ac --- /dev/null +++ b/buildSrc/src/main/groovy/net/minecraftforge/mcpconfig/tasks/PathArgumentProvider.groovy @@ -0,0 +1,18 @@ +package net.minecraftforge.mcpconfig.tasks + +import org.gradle.api.file.RegularFileProperty +import org.gradle.api.tasks.InputFile +import org.gradle.api.tasks.PathSensitive +import org.gradle.api.tasks.PathSensitivity +import org.gradle.process.CommandLineArgumentProvider + +abstract class ZipPathArgumentProvider implements CommandLineArgumentProvider { + @InputFile + @PathSensitive(PathSensitivity.RELATIVE) + abstract RegularFileProperty getFile() + + @Override + Iterable asArguments() { + [file.get().asFile.absolutePath] + } +}