Skip to content

Build FastDL Map Bundle #5

Build FastDL Map Bundle

Build FastDL Map Bundle #5

Workflow file for this run

name: Build FastDL Map Bundle
on:
push:
paths:
- "**/maps/**/*.bsp"
workflow_dispatch:
permissions:
contents: write
env:
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
added_paths_file="$GITHUB_WORKSPACE/.fastdl_new_paths"
: > "$added_paths_file"
map_files=()
while IFS= read -r -d '' map_file; do
map_files+=("$map_file")
done < <(find . -type f -path '*/maps/*.bsp' -print0)
if [ "${#map_files[@]}" -eq 0 ]; then
echo "No map files (*.bsp) found under any maps directory."
echo "has_new_outputs=false" >> "$GITHUB_OUTPUT"
rm -f "$added_paths_file"
exit 0
fi
for map_file in "${map_files[@]}"; do
rel_path="${map_file#./}"
target_path="${map_file}.bz2"
parts_dir="$target_path.parts"
if [ -f "$target_path" ] || [ -d "$parts_dir" ]; then
echo "Skipping $rel_path because FastDL output already exists."
continue
fi
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
mkdir -p "$parts_dir"
base_name="$(basename "$target_path")"
echo "Splitting $target_path (size $file_size bytes) into <= $SPLIT_CHUNK_SIZE chunks"
split -b "$SPLIT_CHUNK_SIZE" -d -a 3 "$target_path" "$parts_dir/$base_name.part."
rm "$target_path"
while IFS= read -r -d '' part_file; do
printf '%s\0' "${part_file#./}" >> "$added_paths_file"
done < <(find "$parts_dir" -type f -print0 | sort -z)
part_count=$(find "$parts_dir" -type f | wc -l | tr -d ' ')
echo "Split $rel_path.bz2 into $part_count part(s) under $parts_dir"
else
printf '%s\0' "${target_path#./}" >> "$added_paths_file"
fi
done
if [ -s "$added_paths_file" ]; then
echo "has_new_outputs=true" >> "$GITHUB_OUTPUT"
echo "paths_file=$added_paths_file" >> "$GITHUB_OUTPUT"
else
echo "has_new_outputs=false" >> "$GITHUB_OUTPUT"
rm -f "$added_paths_file"
fi
- name: Stage FastDL outputs
if: steps.compress.outputs.has_new_outputs == 'true'
run: |
set -euo pipefail
paths_file="${{ steps.compress.outputs.paths_file }}"
if [ -z "$paths_file" ] || [ ! -f "$paths_file" ]; then
echo "Expected list of FastDL outputs was not generated" >&2
exit 1
fi
xargs -0 git add < "$paths_file"
rm -f "$paths_file"
- name: Configure git user
if: steps.compress.outputs.has_new_outputs == '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.compress.outputs.has_new_outputs == 'true'
shell: bash
run: |
set -euo pipefail
git commit -m "chore: update FastDL map bundle"
- name: Push FastDL bundle
if: steps.compress.outputs.has_new_outputs == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_REPO: ${{ github.repository }}
run: |
set -euo pipefail
branch_ref="${GITHUB_REF#refs/heads/}"
git push "https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPO}.git" "HEAD:${branch_ref}"