Skip to content

Commit

Permalink
Run a ZIP optimizer to get ~10% of ZIP size reduction
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Dec 10, 2024
1 parent 571927e commit 406872d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
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: 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
15 changes: 14 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,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)
Expand Down
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

0 comments on commit 406872d

Please sign in to comment.