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