This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Optimize resource pack | |
on: | |
push: | |
branches: | |
- "master" | |
jobs: | |
packsquash: | |
name: Optimize resource pack | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Clone repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # A non-shallow repository clone is required | |
- name: Set short git commit SHA | |
id: vars | |
run: | | |
calculatedSha=$(git rev-parse --short ${{ github.sha }}) | |
echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV | |
- name: Check for changes in core directory | |
id: core_changes | |
run: | | |
git diff-tree --no-commit-id --name-only -r ${{ github.sha }} | grep -q '^core/' && echo "CORE_CHANGED=true" >> $GITHUB_ENV || echo "CORE_CHANGED=false" >> $GITHUB_ENV | |
- name: Retrieve previous release core hash | |
id: get_previous_hash | |
run: | | |
curl -s \ | |
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
"https://api.github.com/repos/${{ github.repository }}/releases/tags/latest" | \ | |
jq -r '.body | capture("core: (?<core_sha>[a-f0-9]+)") | .core_sha // "N/A"' > previous_core_sha.txt | |
echo "PREVIOUS_CORE_SHA=$(cat previous_core_sha.txt)" >> $GITHUB_ENV | |
- name: Setup Stripzip | |
run: | | |
git clone https://github.com/KittyHawkCorp/stripzip.git szp && cd szp | |
make | |
mv stripzip .. | |
- name: Conditionally Run PackSquash | |
if: env.CORE_CHANGED == 'true' | |
uses: ComunidadAylas/PackSquash-action@v4 | |
with: | |
packsquash_version: latest | |
options: | | |
pack_directory = 'core' | |
recompress_compressed_files = true | |
zip_compression_iterations = 30 | |
zip_spec_conformance_level = 'balanced' | |
skip_pack_icon = false | |
output_file_path = 'core.zip' | |
['**/*?.png'] | |
image_data_compression_iterations = 15 | |
['**/{LICENSE,README.txt}'] | |
force_include = true | |
- name: ZIP Hud | |
run: cd hud && zip -r ../hud.zip . && cd .. | |
- name: ZIP Soundscapes | |
run: cd soundscapes && zip -r ../soundscapes.zip . && cd .. | |
- name: Clean ZIP Metadata | |
run: | | |
if [ -f core.zip ]; then ./stripzip core.zip; fi | |
./stripzip hud.zip | |
./stripzip soundscapes.zip | |
mkdir zips | |
- name: Hash files | |
run: | | |
if [ -f core.zip ]; then | |
calculatedCoreSha=($(sha1sum core.zip)) | |
echo "CORE_SHA=$calculatedCoreSha" >> $GITHUB_ENV | |
mv core.zip zips | |
else | |
echo "CORE_SHA=${{ env.PREVIOUS_CORE_SHA }}" >> $GITHUB_ENV | |
fi | |
calculatedHudSha=($(sha1sum hud.zip)) | |
echo "HUD_SHA=$calculatedHudSha" >> $GITHUB_ENV | |
calculatedSoundscapesSha=($(sha1sum soundscapes.zip)) | |
echo "SOUNDSCAPES_SHA=$calculatedSoundscapesSha" >> $GITHUB_ENV | |
mv hud.zip zips | |
mv soundscapes.zip zips | |
- name: Get date | |
run: | | |
currentDate=$(date) | |
echo "DATE=$currentDate" >> $GITHUB_ENV | |
- name: Upload to latest release | |
uses: svenstaro/upload-release-action@v2 | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
file: zips/* | |
file_glob: true | |
tag: refs/tags/latest | |
overwrite: true | |
body: | | |
soundscapes: ${{ env.SOUNDSCAPES_SHA }} | |
core: ${{ env.CORE_SHA }} | |
hud: ${{ env.HUD_SHA }} | |
date: ${{ env.DATE }} |