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

@@ -1,95 +1,119 @@
name: "Cleanup Extra Files" name: "Cleanup Extra Files"
description: "Remove leftover or outdated assets from repository" description: "Remove leftover or outdated assets from repository"
inputs: inputs:
all_skins: all_skins:
description: "JSON array of all skins" description: "JSON array of all skins"
required: true required: true
runs: runs:
using: "composite" using: "composite"
steps: steps:
- name: Cleanup Extra Files - name: Cleanup Extra Files
shell: bash shell: bash
run: | run: |
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" exit 1
exit 1 fi
fi
readarray -t skins < <(jq -r '.[]' "$all_skins_file")
readarray -t skins < <(jq -r '.[]' "$all_skins_file")
[ -f how-to-use.md ] && rm -f -- how-to-use.md
[ -f how-to-use.md ] && rm -f -- how-to-use.md [ -f src/replay.osr ] && rm -f -- src/replay.osr
[ -f src/replay.osr ] && rm -f -- src/replay.osr [ -d src/default-skin ] && rm -rf -- src/default-skin
[ -d src/default-skin ] && rm -rf -- src/default-skin
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=()
prune_dir() { skins_clean=()
local root="$1"
local skin="$2" for s in "${skins[@]}"; do
local expected="$3" skins_raw+=("$s")
skins_clean+=("$(sanitize_filename "$s")")
for f in "$root"/*; do done
[ -f "$f" ] || continue
name="$(basename "$f")" is_known_skin() {
if printf '%s\n' "${skins[@]}" | grep -Fxq -- "$name"; then local name="$1"
continue for i in "${!skins_raw[@]}"; do
fi if [[ "$name" == "${skins_raw[$i]}" ]] || [[ "$name" == "${skins_clean[$i]}" ]]; then
echo " → Removing unexpected root file: $f" return 0
rm -f -- "$f" fi
done done
return 1
dir="$root/$skin" }
[ -d "$dir" ] || return
for f in "$dir"/*; do prune_dir() {
[ -e "$f" ] || continue local root="$1"
if [[ "$(basename "$f")" != "$expected" ]]; then local skin_raw="$2"
echo " → Removing unexpected file: $f" local expected="$3"
rm -f -- "$f"
fi for f in "$root"/*; do
done [ -f "$f" ] || continue
} basename_f="$(basename "$f")"
for root in "$REPO_SCREENSHOT_DIR" "$REPO_RANKING_PANEL_DIR" "$REPO_MOD_ICONS_DIR" "$REPO_THUMBNAIL_DIR" "$OSK_PATH" "$DOC_DIR"; do if printf '%s\n' "${skins_raw[@]}" | grep -Fxq -- "$basename_f"; then
[ -d "$root" ] || continue continue
for dir in "$root"/*; do fi
[ -d "$dir" ] || continue
name="$(basename "$dir")" echo " → Removing unexpected root file: $f"
if ! printf '%s\n' "${skins[@]}" | grep -Fxq -- "$name"; then rm -f -- "$f"
echo " → Skin '$name' deleted—removing directory $dir" done
rm -rf -- "$dir"
fi local folder="$root/$skin_raw"
done [ -d "$folder" ] || return
done
for f in "$folder"/*; do
for skin in "${skins[@]}"; do [ -e "$f" ] || continue
header=$(sanitize_filename "$skin") if [[ "$(basename "$f")" != "$expected" ]]; then
ini=$(find -- "$DANSER_SKINS_DIR/$skin" -maxdepth 1 -type f -iname "skin.ini" -print -quit || true) echo " → Removing unexpected file: $f"
if [[ -f "$ini" ]]; then rm -f -- "$f"
raw=$(grep -i '^[[:space:]]*Name:' "$ini" | head -n1 || true) fi
raw="${raw#*:}" done
raw="$(echo "$raw" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')" }
tmp_header=$(sanitize_filename "$raw")
[[ -n "$tmp_header" ]] && header="$tmp_header" for root in "$REPO_SCREENSHOT_DIR" "$REPO_RANKING_PANEL_DIR" "$REPO_MOD_ICONS_DIR" "$REPO_THUMBNAIL_DIR" "$OSK_PATH" "$DOC_DIR"; do
fi [ -d "$root" ] || continue
for dir in "$root"/*; do
prune_dir "$REPO_SCREENSHOT_DIR" "$skin" "$header.mp4" [ -d "$dir" ] || continue
prune_dir "$REPO_RANKING_PANEL_DIR" "$skin" "$header.webp" name="$(basename "$dir")"
prune_dir "$REPO_MOD_ICONS_DIR" "$skin" "$header.webp"
prune_dir "$REPO_THUMBNAIL_DIR" "$skin" "$header.webp" if ! is_known_skin "$name"; then
prune_dir "$OSK_PATH" "$skin" "$header.osk" echo " → Skin '$name' deleted—removing directory $dir"
prune_dir "$DOC_DIR" "$skin" "$header.md" rm -rf -- "$dir" || true
done fi
done
echo "[Cleanup Extra Files Complete]" done
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="$(sanitize_filename "$raw")"
[[ -n "$tmp" ]] && header="$tmp"
fi
prune_dir "$REPO_SCREENSHOT_DIR" "$skin" "$header.mp4"
prune_dir "$REPO_RANKING_PANEL_DIR" "$skin" "$header.webp"
prune_dir "$REPO_MOD_ICONS_DIR" "$skin" "$header.webp"
prune_dir "$REPO_THUMBNAIL_DIR" "$skin" "$header.webp"
prune_dir "$OSK_PATH" "$skin" "$header.osk"
prune_dir "$DOC_DIR" "$skin" "$header.md"
done
echo "[Cleanup Extra Files Complete]"