Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run a ZIP optimizer to get ~10% of ZIP size reduction #14

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: sudo apt install advancecomp
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
Expand All @@ -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
Expand Down
18 changes: 17 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -815,6 +816,21 @@ 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"
argumentProviders.add(
objects.newInstance(ZipPathArgumentProvider).tap {
file = makeZip.flatMap(AbstractArchiveTask::getArchiveFile)
}
)
}
if (optimize_zip) {
makeZip.configure { finalizedBy optimizeZip }
}

def componentMaker = objects.newInstance(ComponentMaker)
def neoformComponent = componentMaker.componentFactory.adhoc('neoform')
components.add(neoformComponent)
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> asArguments() {
[file.get().asFile.absolutePath]
}
}
5 changes: 4 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.configuration-cache=true
org.gradle.configuration-cache=true

# Run ZIP optimizations using advzip, which requires the tool to be installed
optimize_zip=false
Loading