Skip to content

Increased save file length to avoid overwrites #26

Increased save file length to avoid overwrites

Increased save file length to avoid overwrites #26

name: Check file size
on:
pull_request:
branches: [main]
# to run this workflow manually from the Actions tab
workflow_dispatch:
permissions:
contents: read
jobs:
check-file-size:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Fail if changed files exceed 10MB
env:
FILE_SIZE_LIMIT_BYTES: "10485760" # 10MB (HF Spaces sync limit)
run: |
set -euo pipefail
echo "Checking changed files against limit: ${FILE_SIZE_LIMIT_BYTES} bytes"
BASE_SHA="${{ github.event.pull_request.base.sha }}"
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
echo "Base: ${BASE_SHA}"
echo "Head: ${HEAD_SHA}"
git diff --name-only "${BASE_SHA}" "${HEAD_SHA}" > changed_files.txt
echo "Changed files:"
cat changed_files.txt
failed=0
while IFS= read -r file; do
[ -z "${file}" ] && continue
if [ ! -f "${file}" ]; then
# Deleted files or non-file paths can appear; ignore.
continue
fi
size=$(wc -c < "${file}" | tr -d ' ')
if [ "${size}" -gt "${FILE_SIZE_LIMIT_BYTES}" ]; then
echo "::error file=${file}::File is too large (${size} bytes) > ${FILE_SIZE_LIMIT_BYTES} bytes"
failed=1
fi
done < changed_files.txt
if [ "${failed}" -ne 0 ]; then
echo "One or more changed files exceed the size limit."
exit 1
fi
echo "OK: no changed files exceed the size limit."