Build FastDL Map Bundle #1
This file contains hidden or 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: Build FastDL Map Bundle | |
| on: | |
| push: | |
| paths: | |
| - "**/maps/**/*.bsp" | |
| workflow_dispatch: | |
| env: | |
| OUTPUT_DIR: fastdl_bz2 | |
| SPLIT_THRESHOLD_BYTES: 26214400 # 25 MiB | |
| SPLIT_CHUNK_SIZE: 20m | |
| jobs: | |
| compress-maps: | |
| name: Compress maps to BZip2 | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| lfs: true | |
| fetch-depth: 0 | |
| - name: Compress map files | |
| id: compress | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| rm -rf "$OUTPUT_DIR" | |
| mkdir -p "$OUTPUT_DIR" | |
| split_manifest="$OUTPUT_DIR/SPLIT_MANIFEST.txt" | |
| rm -f "$split_manifest" | |
| map_count=$(find . -type f -path '*/maps/*.bsp' ! -path "./$OUTPUT_DIR/*" | wc -l | tr -d ' ') | |
| if [ "$map_count" = "0" ]; then | |
| echo "No map files (*.bsp) found under any maps directory." | |
| echo "has_maps=false" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| find . -type f -path '*/maps/*.bsp' ! -path "./$OUTPUT_DIR/*" -print0 | while IFS= read -r -d '' map_file; do | |
| rel_path="${map_file#./}" | |
| target_path="$OUTPUT_DIR/$rel_path.bz2" | |
| mkdir -p "$(dirname "$target_path")" | |
| bzip2 -ck "$map_file" > "$target_path" | |
| echo "Created $target_path" | |
| file_size=$(stat -c%s "$target_path") | |
| if [ "$file_size" -gt "$SPLIT_THRESHOLD_BYTES" ]; then | |
| echo "Splitting $target_path (size $file_size bytes) into <= $SPLIT_CHUNK_SIZE chunks" | |
| split -b "$SPLIT_CHUNK_SIZE" -d -a 3 "$target_path" "$target_path.part." | |
| rm "$target_path" | |
| if [ ! -f "$split_manifest" ]; then | |
| { | |
| echo "Some generated FastDL archives exceeded 25 MiB and were split into numbered parts." | |
| echo "Reassemble each entry with:" | |
| echo " cat <listed parts in order> > <original .bz2 path>" | |
| echo | |
| echo "Entries:" | |
| } > "$split_manifest" | |
| fi | |
| part_dir="$(dirname "$target_path")" | |
| part_base="$(basename "$target_path")" | |
| parts=() | |
| while IFS= read -r -d '' part_file; do | |
| parts+=("$part_file") | |
| done < <(find "$part_dir" -maxdepth 1 -type f -name "$part_base.part.*" -print0 | sort -z) | |
| echo "Original: $rel_path.bz2" >> "$split_manifest" | |
| echo "Parts:" >> "$split_manifest" | |
| for part_file in "${parts[@]}"; do | |
| part_rel="${part_file#./}" | |
| echo " - $part_rel" >> "$split_manifest" | |
| done | |
| echo "Reassemble: cat the parts above > $rel_path.bz2" >> "$split_manifest" | |
| echo >> "$split_manifest" | |
| echo "Split $rel_path.bz2 into ${#parts[@]} part(s)." | |
| fi | |
| done | |
| if [ -f "$split_manifest" ] && [ ! -s "$split_manifest" ]; then | |
| rm -f "$split_manifest" | |
| fi | |
| echo "has_maps=true" >> "$GITHUB_OUTPUT" | |
| - name: Detect FastDL changes | |
| id: diff | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| if git status --short -- "$OUTPUT_DIR" | grep -q .; then | |
| echo "has_changes=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "has_changes=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Configure git user | |
| if: steps.diff.outputs.has_changes == 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| - name: Commit FastDL bundle | |
| if: steps.diff.outputs.has_changes == 'true' | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| git add "$OUTPUT_DIR" | |
| git commit -m "chore: update FastDL map bundle" | |
| - name: Push FastDL bundle | |
| if: steps.diff.outputs.has_changes == 'true' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| set -euo pipefail | |
| branch_ref="${GITHUB_REF#refs/heads/}" | |
| git push origin "HEAD:${branch_ref}" |