Update .gitea/actions/cleanup/action.yml

This commit is contained in:
2025-11-22 23:05:57 +01:00
parent 49b9f522a3
commit f7cf5ed5c9

View File

@@ -15,7 +15,6 @@ runs:
set -euo pipefail
echo "[Cleanup Extra Files Started]"
# Read from shared file to avoid GitHub Actions template expansion issues
all_skins_file="/tmp/all_skins_shared.json"
if [ ! -f "$all_skins_file" ]; then
echo "Error: $all_skins_file not found"
@@ -31,28 +30,49 @@ runs:
sanitize_filename() {
echo "$1" | \
tr -d '\000-\037' | \
sed -e 's#[\\/:\*\?"<>|]#-#g' | \
sed -e 's#[][\/:*?"<>|]#-#g' | \
sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'
}
skins_raw=()
skins_clean=()
for s in "${skins[@]}"; do
skins_raw+=("$s")
skins_clean+=("$(sanitize_filename "$s")")
done
is_known_skin() {
local name="$1"
for i in "${!skins_raw[@]}"; do
if [[ "$name" == "${skins_raw[$i]}" ]] || [[ "$name" == "${skins_clean[$i]}" ]]; then
return 0
fi
done
return 1
}
prune_dir() {
local root="$1"
local skin="$2"
local skin_raw="$2"
local expected="$3"
for f in "$root"/*; do
[ -f "$f" ] || continue
name="$(basename "$f")"
if printf '%s\n' "${skins[@]}" | grep -Fxq -- "$name"; then
basename_f="$(basename "$f")"
if printf '%s\n' "${skins_raw[@]}" | grep -Fxq -- "$basename_f"; then
continue
fi
echo " → Removing unexpected root file: $f"
rm -f -- "$f"
done
dir="$root/$skin"
[ -d "$dir" ] || return
for f in "$dir"/*; do
local folder="$root/$skin_raw"
[ -d "$folder" ] || return
for f in "$folder"/*; do
[ -e "$f" ] || continue
if [[ "$(basename "$f")" != "$expected" ]]; then
echo " → Removing unexpected file: $f"
@@ -66,22 +86,26 @@ runs:
for dir in "$root"/*; do
[ -d "$dir" ] || continue
name="$(basename "$dir")"
if ! printf '%s\n' "${skins[@]}" | grep -Fxq -- "$name"; then
if ! is_known_skin "$name"; then
echo " → Skin '$name' deleted—removing directory $dir"
rm -rf -- "$dir"
rm -rf -- "$dir" || true
fi
done
done
for skin in "${skins[@]}"; do
header=$(sanitize_filename "$skin")
ini=$(find -- "$DANSER_SKINS_DIR/$skin" -maxdepth 1 -type f -iname "skin.ini" -print -quit || true)
for idx in "${!skins_raw[@]}"; do
skin="${skins_raw[$idx]}"
header="${skins_clean[$idx]}"
ini=$(find "$DANSER_SKINS_DIR/$skin" -maxdepth 1 -type f -iname "skin.ini" -print -quit || true)
if [[ -f "$ini" ]]; then
raw=$(grep -i '^[[:space:]]*Name:' "$ini" | head -n1 || true)
raw="${raw#*:}"
raw="$(echo "$raw" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
tmp_header=$(sanitize_filename "$raw")
[[ -n "$tmp_header" ]] && header="$tmp_header"
raw="$(echo "$raw" | sed 's/^[[:space:]]*//; s/[[:space:]]*$//')"
tmp="$(sanitize_filename "$raw")"
[[ -n "$tmp" ]] && header="$tmp"
fi
prune_dir "$REPO_SCREENSHOT_DIR" "$skin" "$header.mp4"