Update .gitea/workflows/ci.yml

This commit is contained in:
2025-06-08 14:16:26 +02:00
parent 3c5cfb957c
commit 34c1d98fef

View File

@@ -8,6 +8,11 @@ on:
- '.gitea/workflows/ci.yml'
- 'Skins/**/*'
workflow_dispatch:
inputs:
force_rebuild:
description: 'Force rebuild all skins'
required: false
default: 'false'
env:
DANSER_PATH: "/app/danser/danser-cli"
@@ -50,19 +55,24 @@ jobs:
token: ${{ secrets.TOKEN }}
- name: Git LFS Pull
shell: bash
run: |
echo "Pulling Git LFS files..."
git lfs pull
echo "LFS files pulled."
- name: Extract Repository path
shell: bash
run: |
FULL_WORKSPACE_PATH="${{ github.workspace }}"
USER_REPOSITORY="${FULL_WORKSPACE_PATH#/workspace/}"
echo "Extracting repository path..."
USER_REPOSITORY="${{ github.workspace }}"
USER_REPOSITORY="${USER_REPOSITORY#/workspace/}"
USER_REPOSITORY="${USER_REPOSITORY%/}"
echo "Repository path extracted: $USER_REPOSITORY"
echo "USER_REPOSITORY=$USER_REPOSITORY" >> $GITHUB_ENV
- name: Set XDG_RUNTIME_DIR
shell: bash
run: |
echo "Setting XDG_RUNTIME_DIR..."
mkdir -p /tmp/xdg_runtime_dir
@@ -71,26 +81,84 @@ jobs:
echo "XDG_RUNTIME_DIR set."
- name: Create directories for assets
shell: bash
run: |
echo "Creating asset directories..."
mkdir -p "$REPO_SCREENSHOT_DIR"
mkdir -p "$REPO_MOD_ICONS_DIR"
mkdir -p "$REPO_RANKING_PANEL_DIR"
mkdir -p "$OSK_PATH"
echo "Asset directories created successfully."
echo "Creating directories for assets..."
mkdir -p "$REPO_SCREENSHOT_DIR" "$REPO_MOD_ICONS_DIR" "$REPO_RANKING_PANEL_DIR" "$OSK_PATH"
echo "Directories created."
- name: Detect Changed Skin Directories
shell: bash
run: |
echo "[Detect Changed Skin Directories Started]"
echo "→ Fetching tags from git..."
git fetch --tags
force_rebuild="${{ github.event.inputs.force_rebuild }}"
skins=()
echo "→ Force rebuild flag: $force_rebuild"
if [ "$force_rebuild" = "true" ]; then
echo "→ Force rebuild is enabled. Finding all skin directories..."
mapfile -t skins < <(find Skins -mindepth 1 -maxdepth 1 -type d | sed 's|^Skins/||' | sort)
echo " ✓ Found ${#skins[@]} skin directories"
else
echo "→ Force rebuild is disabled. Finding latest git tag..."
latest_tag=$(git tag --sort=-creatordate | head -n 1 || true)
if [ -n "$latest_tag" ]; then
echo "→ Latest tag found: $latest_tag"
echo "→ Finding skins changed since $latest_tag..."
mapfile -t skins < <(
git diff --name-only "$latest_tag" HEAD |
grep '^Skins/' | sed -E 's#^Skins/([^/]+).*#\1#' | sort -u
)
echo " ✓ Found ${#skins[@]} changed skins"
else
echo "→ No tag found. Falling back to finding all skin directories..."
mapfile -t skins < <(find Skins -mindepth 1 -maxdepth 1 -type d | sed 's|^Skins/||' | sort)
echo " ✓ Found ${#skins[@]} skin directories"
fi
fi
echo ""
echo "[Cleaning Skin Names]"
uniq_skins=()
for skin in "${skins[@]}"; do
skin="${skin#"${skin%%[![:space:]]*}"}" # Trim leading whitespace
skin="${skin%"${skin##*[![:space:]]}"}" # Trim trailing whitespace
if [ -n "$skin" ]; then
uniq_skins+=("$skin")
fi
done
echo " ✓ ${#uniq_skins[@]} valid skin names after cleaning"
echo ""
if [ "${#uniq_skins[@]}" -eq 0 ]; then
echo "→ No changed skins detected."
echo "CHANGED_SKINS_FILE=" >> "$GITHUB_ENV"
else
echo "[Writing Changed Skins to File]"
changed_skins_file=$(mktemp)
printf "%s\n" "${uniq_skins[@]}" > "$changed_skins_file"
echo " ✓ Skins written to $changed_skins_file"
echo "CHANGED_SKINS_FILE=$changed_skins_file" >> "$GITHUB_ENV"
fi
echo ""
echo "[Detect Changed Skin Directories Complete — ${#uniq_skins[@]} skins processed]"
- name: Create New Tag
shell: bash
run: |
echo "Computing new tag..."
git fetch --tags >/dev/null 2>&1
git fetch --tags
latest_tag=$(git describe --tags $(git rev-list --tags --max-count=1) 2>/dev/null || echo "")
if [ -z "$latest_tag" ]; then
new_tag="v1.0.0"
else
version=${latest_tag#v}
major=$(echo "$version" | cut -d. -f1)
minor=$(echo "$version" | cut -d. -f2)
patch=$(echo "$version" | cut -d. -f3)
IFS='.' read -r major minor patch <<< "${latest_tag#v}"
minor=$((minor + 1))
patch=0
new_tag="v${major}.${minor}.${patch}"
@@ -99,6 +167,7 @@ jobs:
echo "Computed new tag: $new_tag"
- name: Move Skin files to Danser Skins directory
shell: bash
run: |
echo "Moving Skin files to Danser Skins directory..."
mkdir -p "$DANSER_SKINS_DIR"
@@ -106,251 +175,298 @@ jobs:
echo "Skin files moved."
- name: Generate Danser videos and screenshots
shell: bash
run: |
echo "[Danser Job Started]"
SKIN_COUNT=$(find "$DANSER_SKINS_DIR" -mindepth 1 -maxdepth 1 -type d | wc -l)
if [ -z "${CHANGED_SKINS_FILE:-}" ] || [ ! -s "$CHANGED_SKINS_FILE" ]; then
echo "No skins changed. Skipping generation."
exit 0
fi
mapfile -t skins < "$CHANGED_SKINS_FILE"
if [ "${#skins[@]}" -eq 0 ]; then
echo "No skins changed after reading file. Skipping generation."
exit 0
fi
SKIN_COUNT=${#skins[@]}
INDEX=1
for skin in "$DANSER_SKINS_DIR"/*/; do
if [ -d "$skin" ]; then
SKIN_NAME=$(basename "$skin")
echo ""
echo "[$INDEX/$SKIN_COUNT] Skin: $SKIN_NAME"
for skin_path in "${skins[@]}"; do
[ -z "$skin_path" ] && continue
LOGFILE="/tmp/danser_log_$SKIN_NAME.txt"
FFMPEG_LOG="/tmp/ffmpeg_log_$SKIN_NAME.txt"
echo " → Generating video..."
if ! xvfb-run -a "$DANSER_DIR/danser-cli" -replay "$REPLAY_PATH" -record -skip -start=215 -end=230 -noupdatecheck -out="$SKIN_NAME" -skin "$SKIN_NAME" >"$LOGFILE" 2>&1; then
echo " ✖ Video generation failed for $SKIN_NAME. Log output:"
cat "$LOGFILE"
exit 1
fi
echo " → Taking screenshot..."
if ! xvfb-run -a "$DANSER_DIR/danser-cli" -replay "$REPLAY_PATH" -skip -noupdatecheck -ss 243 -out="$SKIN_NAME" -skin "$SKIN_NAME" >>"$LOGFILE" 2>&1; then
echo " ✖ Screenshot generation failed for $SKIN_NAME. Log output:"
cat "$LOGFILE"
exit 1
fi
if [ -f "$DANSER_VIDEO_DIR/$SKIN_NAME.mp4" ]; then
echo " → Converting to GIF..."
if ! ffmpeg -y -hwaccel cuda -ss 4 -t 10 -i "$DANSER_VIDEO_DIR/$SKIN_NAME.mp4" \
-filter_complex "[0:v] fps=24,scale=720:-1:flags=lanczos,palettegen [p]; \
[0:v] fps=24,scale=720:-1:flags=lanczos [x]; \
[x][p] paletteuse" \
-c:v gif "$DANSER_VIDEO_DIR/$SKIN_NAME.gif" >"$FFMPEG_LOG" 2>&1; then
echo " ✖ FFmpeg conversion failed for $SKIN_NAME. Log output:"
cat "$FFMPEG_LOG"
exit 1
fi
mv "$DANSER_VIDEO_DIR/$SKIN_NAME.gif" "$REPO_SCREENSHOT_DIR/$SKIN_NAME.gif"
fi
if [ -f "$DANSER_SCREENSHOT_DIR/$SKIN_NAME.png" ]; then
mv "$DANSER_SCREENSHOT_DIR/$SKIN_NAME.png" "$REPO_RANKING_PANEL_DIR/$SKIN_NAME.png"
fi
echo " ✓ Completed"
INDEX=$((INDEX + 1))
SKIN_DIR="$DANSER_SKINS_DIR/$skin_path"
if [ ! -d "$SKIN_DIR" ]; then
echo "Skipping missing skin directory: $SKIN_DIR"
continue
fi
SKIN_NAME=$(echo "$skin_path" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
echo ""
echo "[$INDEX/$SKIN_COUNT] Skin: $SKIN_NAME"
LOGFILE="/tmp/danser_log_$INDEX.txt"
FFMPEG_LOG="/tmp/ffmpeg_log_$INDEX.txt"
echo " → Generating video..."
if ! xvfb-run -a "$DANSER_DIR/danser-cli" \
-replay "$REPLAY_PATH" \
-record -skip -start=215 -end=230 -noupdatecheck \
-out="$SKIN_NAME" -skin="$SKIN_NAME" >"$LOGFILE" 2>&1; then
echo " ✖ Video generation failed for $SKIN_NAME. Log output:"
cat "$LOGFILE"
continue
fi
echo " → Taking screenshot..."
if ! xvfb-run -a "$DANSER_DIR/danser-cli" \
-replay "$REPLAY_PATH" -skip -noupdatecheck -ss 243 \
-out="$SKIN_NAME" -skin="$SKIN_NAME" >>"$LOGFILE" 2>&1; then
echo " ✖ Screenshot generation failed for $SKIN_NAME. Log output:"
cat "$LOGFILE"
continue
fi
if [ -f "$DANSER_VIDEO_DIR/$SKIN_NAME.mp4" ]; then
echo " → Converting to GIF..."
if ! ffmpeg -y -hwaccel cuda -ss 4 -t 10 -i "$DANSER_VIDEO_DIR/$SKIN_NAME.mp4" \
-filter_complex "[0:v] fps=24,scale=720:-1:flags=lanczos,palettegen [p]; [0:v] fps=24,scale=720:-1:flags=lanczos [x]; [x][p] paletteuse" \
-c:v gif "$DANSER_VIDEO_DIR/$SKIN_NAME.gif" >"$FFMPEG_LOG" 2>&1; then
echo " ✖ FFmpeg conversion failed for $SKIN_NAME. Log output:"
cat "$FFMPEG_LOG"
continue
fi
mv "$DANSER_VIDEO_DIR/$SKIN_NAME.gif" "$REPO_SCREENSHOT_DIR/$SKIN_NAME.gif"
else
echo " ✖ Video file not found for $SKIN_NAME."
fi
if [ -f "$DANSER_SCREENSHOT_DIR/$SKIN_NAME.png" ]; then
mv "$DANSER_SCREENSHOT_DIR/$SKIN_NAME.png" "$REPO_RANKING_PANEL_DIR/$SKIN_NAME.png"
else
echo " ✖ Screenshot file not found for $SKIN_NAME."
fi
echo " ✓ Completed"
INDEX=$((INDEX + 1))
done
echo ""
echo "[Danser Job Finished — $SKIN_COUNT skins processed]"
- name: Rename Generated Assets Based on skin.ini
shell: bash
run: |
echo "[Asset Renaming Started]"
if [ -z "${CHANGED_SKINS_FILE:-}" ] || [ ! -s "$CHANGED_SKINS_FILE" ]; then
echo "No skins changed. Skipping asset renaming."
exit 0
fi
sanitize_filename() {
echo "$1" | \
sed -e 's#[\\/:\*\?"<>|]#-#g' -e 's#%#_#g' | \
tr -s ' ' | \
sed 's/^[[:space:]]*//;s/[[:space:]]*$//'
}
mapfile -t changed_skins < "$CHANGED_SKINS_FILE"
skin_dirs=()
for skin in "${changed_skins[@]}"; do
[ -d "$DANSER_SKINS_DIR/$skin" ] && skin_dirs+=("$DANSER_SKINS_DIR/$skin/")
done
SKIN_COUNT=${#skin_dirs[@]}
INDEX=1
SKIN_COUNT=$(find "$DANSER_SKINS_DIR" -mindepth 1 -maxdepth 1 -type d | wc -l)
for skin_path in "$DANSER_SKINS_DIR"/*/; do
if [ -d "$skin_path" ]; then
SKIN_NAME=$(basename "$skin_path")
if [ "$SKIN_COUNT" -eq 0 ]; then
echo "No valid skin directories to process. Skipping."
exit 0
fi
echo ""
echo "[$INDEX/$SKIN_COUNT] Skin: $SKIN_NAME"
for skin_path in "${skin_dirs[@]}"; do
[ -d "$skin_path" ] || continue
SKIN_NAME=$(basename "$skin_path")
ini_file=$(find "$skin_path" -maxdepth 1 -iname "skin.ini" | head -n1)
skin_header="$SKIN_NAME"
echo ""
echo "[$INDEX/$SKIN_COUNT] Skin: $SKIN_NAME"
skin_header="$SKIN_NAME"
if ini_file=$(find "$skin_path" -maxdepth 1 -iname "skin.ini" | head -n 1); then
if [ -f "$ini_file" ]; then
name_line=$(grep -i '^[[:space:]]*name:' "$ini_file" | head -n1)
name_line=$(grep -i '^[[:space:]]*name:' "$ini_file" | head -n 1)
if [ -n "$name_line" ]; then
new_name=$(echo "$name_line" | cut -d ':' -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
new_name=$(sanitize_filename "$new_name")
[ -n "$new_name" ] && skin_header="$new_name"
fi
fi
original_gif="$REPO_SCREENSHOT_DIR/$SKIN_NAME.gif"
renamed_gif="$REPO_SCREENSHOT_DIR/$skin_header.gif"
if [ -f "$original_gif" ] && [ "$original_gif" != "$renamed_gif" ]; then
mv -f "$original_gif" "$renamed_gif"
echo " ✓ Renamed GIF"
else
echo " → No GIF to rename or already named correctly"
fi
original_png="$REPO_RANKING_PANEL_DIR/$SKIN_NAME.png"
renamed_png="$REPO_RANKING_PANEL_DIR/$skin_header.png"
if [ -f "$original_png" ] && [ "$original_png" != "$renamed_png" ]; then
mv -f "$original_png" "$renamed_png"
echo " ✓ Renamed PNG"
else
echo " → No PNG to rename or already named correctly"
fi
echo " ✓ Completed"
INDEX=$((INDEX + 1))
fi
if [ -f "$REPO_SCREENSHOT_DIR/$SKIN_NAME.gif" ] && [ "$SKIN_NAME" != "$skin_header" ]; then
mv -f "$REPO_SCREENSHOT_DIR/$SKIN_NAME.gif" "$REPO_SCREENSHOT_DIR/$skin_header.gif"
echo " ✓ Renamed GIF"
else
echo " → No GIF to rename or already named correctly"
fi
if [ -f "$REPO_RANKING_PANEL_DIR/$SKIN_NAME.png" ] && [ "$SKIN_NAME" != "$skin_header" ]; then
mv -f "$REPO_RANKING_PANEL_DIR/$SKIN_NAME.png" "$REPO_RANKING_PANEL_DIR/$skin_header.png"
echo " ✓ Renamed Screenshot"
else
echo " → No Screenshot to rename or already named correctly"
fi
echo " ✓ Completed"
INDEX=$((INDEX + 1))
done
echo ""
echo "[Asset Renaming Complete — $SKIN_COUNT skins processed]"
- name: Generate Mod Icons
shell: bash
run: |
echo "[Mod Icon Generation Started]"
ICONS_JSON_FILE="${{ github.workspace }}/.gitea/workflows/icons.json"
sanitize_filename() {
echo "$1" | \
sed -e 's#[\\/:\*\?"<>|]#-#g' -e 's#%#_#g' | \
tr -s ' ' | \
sed 's/^[[:space:]]*//;s/[[:space:]]*$//'
}
if [ -z "$CHANGED_SKINS_FILE" ] || [ ! -s "$CHANGED_SKINS_FILE" ]; then
echo "No skins changed. Skipping mod icon generation."
exit 0
fi
ICONS_JSON_FILE="${{ github.workspace }}/.gitea/workflows/icons.json"
group1_icons=$(jq -r '.group1 | join(" ")' "$ICONS_JSON_FILE")
group2_icons=$(jq -r '.group2 | join(" ")' "$ICONS_JSON_FILE")
group3_icons=$(jq -r '.group3 | join(" ")' "$ICONS_JSON_FILE")
SKIN_COUNT=$(find "$DANSER_SKINS_DIR" -mindepth 1 -maxdepth 1 -type d | wc -l)
mapfile -t skins < "$CHANGED_SKINS_FILE"
BLANK_IMAGE="blank.png"
magick -size "160x160" xc:none "$BLANK_IMAGE"
SKIN_COUNT=${#skins[@]}
INDEX=1
for skin_path in "$DANSER_SKINS_DIR"/*/; do
if [ -d "$skin_path" ]; then
SKIN_NAME=$(basename "$skin_path")
echo ""
echo "[$INDEX/$SKIN_COUNT] Skin: $SKIN_NAME"
for skin_path in "${skins[@]}"; do
[ -z "$skin_path" ] && continue
SKIN_DIR="$DANSER_SKINS_DIR/$skin_path"
[ -d "$SKIN_DIR" ] || continue
ini_file=$(find "$skin_path" -maxdepth 1 -iname "skin.ini" | head -n1)
skin_header="$SKIN_NAME"
skin_header=$(basename "$SKIN_DIR")
if ini_file=$(find "$SKIN_DIR" -maxdepth 1 -iname "skin.ini" | head -n 1); then
if [ -f "$ini_file" ]; then
name_line=$(grep -i '^[[:space:]]*name:' "$ini_file" | head -n1)
name_line=$(grep -i '^[[:space:]]*name:' "$ini_file" | head -n 1)
if [ -n "$name_line" ]; then
new_name=$(echo "$name_line" | cut -d ':' -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
if [ -n "$new_name" ]; then
skin_header="$new_name"
fi
new_name=$(sanitize_filename "$new_name")
[ -n "$new_name" ] && skin_header="$new_name"
fi
fi
ICON_FOLDER="$skin_path"
OUTPUT="${REPO_MOD_ICONS_DIR}/${skin_header}-mod-icons.png"
TILE_SIZE=160
PADDING=10
MAX_ICONS=7
BLANK_IMAGE="blank.png"
magick -size "${TILE_SIZE}x${TILE_SIZE}" xc:none "$BLANK_IMAGE"
row_images=""
row_index=1
for group_list in "$group1_icons" "$group2_icons" "$group3_icons"; do
montage_files=""
count=0
for icon in $group_list; do
icon_path="${ICON_FOLDER}/selection-mod-${icon}@2x.png"
if [ -f "$icon_path" ]; then
montage_files="$montage_files \"$icon_path\""
count=$((count + 1))
elif [ -f "$DEFAULT_SKIN_DIR/selection-mod-${icon}@2x.png" ]; then
montage_files="$montage_files \"$DEFAULT_SKIN_DIR/selection-mod-${icon}@2x.png\""
count=$((count + 1))
fi
done
missing=$(( MAX_ICONS - count ))
if [ "$missing" -lt 0 ]; then
missing=0
fi
i=0
while [ "$i" -lt "$missing" ]; do
montage_files="$montage_files \"$BLANK_IMAGE\""
i=$((i + 1))
done
row_file="row_${row_index}.png"
eval "magick montage $montage_files -tile \"${MAX_ICONS}x1\" -geometry \"${TILE_SIZE}x${TILE_SIZE}+${PADDING}+${PADDING}\" -background none \"$row_file\""
row_images="$row_images \"$row_file\""
row_index=$((row_index + 1))
done
num_rows=0
for _ in $row_images; do
num_rows=$((num_rows + 1))
done
eval "magick montage $row_images -tile \"1x${num_rows}\" -geometry \"+${PADDING}+${PADDING}\" -background none \"$OUTPUT\""
rm "$BLANK_IMAGE"
rm row_*.png
echo " ✓ Completed"
INDEX=$((INDEX + 1))
fi
echo ""
echo "[$INDEX/$SKIN_COUNT] Skin: $skin_header"
ICON_FOLDER="$SKIN_DIR"
OUTPUT="${REPO_MOD_ICONS_DIR}/${skin_header}-mod-icons.png"
row_images=()
row_index=1
for group_list in "$group1_icons" "$group2_icons" "$group3_icons"; do
montage_files=()
for icon in $group_list; do
if [ -f "${ICON_FOLDER}/selection-mod-${icon}@2x.png" ]; then
montage_files+=("${ICON_FOLDER}/selection-mod-${icon}@2x.png")
elif [ -f "${DEFAULT_SKIN_DIR}/selection-mod-${icon}@2x.png" ]; then
montage_files+=("${DEFAULT_SKIN_DIR}/selection-mod-${icon}@2x.png")
fi
done
while [ "${#montage_files[@]}" -lt 7 ]; do
montage_files+=("$BLANK_IMAGE")
done
magick montage "${montage_files[@]}" -tile "7x1" -geometry "160x160+10+10" -background none "row_${row_index}.png"
row_images+=("row_${row_index}.png")
row_index=$((row_index + 1))
done
magick montage "${row_images[@]}" -tile "1x${#row_images[@]}" -geometry "+10+10" -background none "$OUTPUT"
rm row_*.png
echo " ✓ Mod Icons Generated"
INDEX=$((INDEX + 1))
done
rm "$BLANK_IMAGE"
echo ""
echo "[Mod Icon Generation Finished — $SKIN_COUNT skins processed]"
- name: Create OSK files
shell: bash
run: |
echo "[OSK Creation Job Started]"
SKIN_COUNT=$(find "$DANSER_SKINS_DIR" -mindepth 1 -maxdepth 1 -type d | wc -l)
INDEX=1
sanitize_filename() {
echo "$1" | \
sed -e 's#[\\/:\*\?"<>|]#-#g' -e 's#%#_#g' | \
tr -s ' ' | \
sed 's/^[[:space:]]*//;s/[[:space:]]*$//'
}
if [ -z "${CHANGED_SKINS_FILE:-}" ] || [ ! -s "$CHANGED_SKINS_FILE" ]; then
echo "No skins to process. Skipping OSK file generation."
exit 0
fi
mapfile -t skins < "$CHANGED_SKINS_FILE"
FIXED_TIMESTAMP="2025-01-01 00:00:00"
find "$DANSER_SKINS_DIR" -mindepth 1 -maxdepth 1 -type d | sort | while IFS= read -r skin; do
SKIN_FOLDER=$(basename "$skin")
echo ""
echo "[$INDEX/$SKIN_COUNT] Processing skin folder: $SKIN_FOLDER"
SKIN_COUNT=${#skins[@]}
INDEX=1
ini_file=$(find "$skin" -maxdepth 1 -iname "skin.ini" | head -n1)
if [ -f "$ini_file" ]; then
name_line=$(grep -i '^[[:space:]]*name:' "$ini_file" | head -n1)
if [ -n "$name_line" ]; then
new_name=$(echo "$name_line" | cut -d ':' -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
if [ -n "$new_name" ]; then
SKIN_FOLDER="$new_name"
for skin_path in "${skins[@]}"; do
SKIN_DIR="$DANSER_SKINS_DIR/$skin_path"
[ -d "$SKIN_DIR" ] || continue
skin_header="$skin_path"
if ini_file=$(find "$SKIN_DIR" -maxdepth 1 -iname "skin.ini" | head -n 1); then
if [ -f "$ini_file" ]; then
name_line=$(grep -i '^[[:space:]]*name:' "$ini_file" | head -n 1)
if [ -n "$name_line" ]; then
new_name=$(echo "$name_line" | cut -d ':' -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
new_name=$(sanitize_filename "$new_name")
[ -n "$new_name" ] && skin_header="$new_name"
fi
fi
else
echo " → No skin.ini found, using folder name."
fi
osk_file="${OSK_PATH}/${SKIN_FOLDER}.osk"
skin_header=$(printf '%s' "$skin_header" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
if ! (cd "$skin" && find . -type f -exec touch -d "$FIXED_TIMESTAMP" {} +); then
echo " ✖ Failed to normalize timestamps in $skin"
exit 1
fi
echo ""
echo "[$INDEX/$SKIN_COUNT] Processing skin: $skin_header"
if (
cd "$skin" && \
find . -type f | sort | zip -rq -D -X -9 --compression-method deflate "$osk_file" -@
); then
echo " ✓ OSK file created successfully."
else
echo " ✖ Failed to create OSK file: $osk_file"
exit 1
fi
(cd "$SKIN_DIR" && find . -type f -exec touch -d "$FIXED_TIMESTAMP" {} +)
(cd "$SKIN_DIR" && find . -type f | sort | zip -rq -D -X -9 --compression-method deflate "$OSK_PATH/${skin_header}.osk" -@)
echo " ✓ OSK file created successfully."
INDEX=$((INDEX + 1))
done
@@ -358,14 +474,24 @@ jobs:
echo "[OSK Creation Job Finished — $SKIN_COUNT skins processed]"
- name: Generate README
shell: bash
run: |
echo "Starting README generation..."
sanitize_filename() {
echo "$1" | \
sed -e 's#[\\/:\*\?"<>|]#-#g' -e 's#%#_#g' | \
tr -s ' ' | \
sed 's/^[[:space:]]*//;s/[[:space:]]*$//'
}
SKINS_JSON_FILE="${{ github.workspace }}/.gitea/workflows/skins.json"
DESC_FILE=$(mktemp)
echo "Step 1: Extracting descriptions from skins.json..."
jq -r '.descriptions | to_entries[] | "\(.key)=\(.value)"' "$SKINS_JSON_FILE" > "$DESC_FILE"
echo "Step 2: Starting to build README..."
echo "---" > "$README_PATH"
echo "gitea: none" >> "$README_PATH"
echo "include_toc: true" >> "$README_PATH"
@@ -377,45 +503,54 @@ jobs:
echo "osuid: $OSU_ID" >> "$README_PATH"
echo "-->" >> "$README_PATH"
echo "" >> "$README_PATH"
echo "## Go back to [osc/skins](https://git.sulejmani.xyz/osc/skins)" >> "$README_PATH"
echo "" >> "$README_PATH"
get_desc() {
key=$1
escaped_key=$(printf '%s\n' "$key" | sed 's/[\/&]/\\&/g')
grep "^${escaped_key}=" "$DESC_FILE" | cut -d '=' -f2-
grep "^${key}=" "$DESC_FILE" 2>/dev/null | cut -d '=' -f2-
}
ORDER_FILE=$(mktemp)
JSON_SKINS_TMP=$(mktemp)
SEEN_HEADERS_FILE=$(mktemp)
echo "Step 3: Extracting order from skins.json..."
jq -r '.order[]' "$SKINS_JSON_FILE" > "$ORDER_FILE"
cp "$ORDER_FILE" "$JSON_SKINS_TMP"
echo "Step 4: Processing ordered skins..."
while IFS= read -r skin; do
echo " Processing skin (order): $skin"
dir="$DANSER_SKINS_DIR/$skin"
if [ ! -d "$dir" ]; then
echo "Skipping missing skin directory: $skin"
echo " Skipping missing directory: $dir"
continue
fi
ini_file=$(find "$dir" -maxdepth 1 -iname "skin.ini" | head -n 1)
ini_file=$(find "$dir" -maxdepth 1 -iname "skin.ini" | head -n 1 || true)
skin_header="$skin"
if [ -f "$ini_file" ]; then
name_line=$(grep -i '^[[:space:]]*name:' "$ini_file" | head -n 1)
if [ -n "$name_line" ]; then
skin_header=$(echo "$name_line" | cut -d ':' -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
name_line=$(grep -i '^[[:space:]]*name:' "$ini_file" | head -n 1 || true)
if [ -n "${name_line:-}" ]; then
new_name=$(echo "$name_line" | cut -d ':' -f2- | sed 's/^[[:space:]]*//')
new_name=$(sanitize_filename "$new_name")
[ -n "$new_name" ] && skin_header="$new_name"
fi
fi
skin_header=$(printf '%s' "$skin_header" | tr -d '\r\n' | sed -e 's/[[:space:]]*$//')
if grep -Fxq "$skin_header" "$SEEN_HEADERS_FILE"; then
echo "Skipping duplicate skin header from JSON order: $skin_header"
echo " Already seen skin header: $skin_header"
continue
fi
echo "$skin_header" >> "$SEEN_HEADERS_FILE"
escaped_img=$(echo "$skin_header.gif" | sed 's/ /%20/g')
escaped_osk=$(echo "$skin_header.osk" | sed 's/ /%20/g')
escaped_img=$(printf "%s" "$skin_header.gif" | sed 's/ /%20/g')
escaped_osk=$(printf "%s" "$skin_header.osk" | sed 's/ /%20/g')
echo " Writing skin: $skin_header"
echo "## [$skin_header]($REGISTRY_URL/$USER_REPOSITORY/media/tag/$new_tag/export/$escaped_osk)" >> "$README_PATH"
echo "" >> "$README_PATH"
@@ -427,7 +562,7 @@ jobs:
if [ -f "$ini_file" ]; then
author_line=$(grep -i '^[[:space:]]*Author:' "$ini_file" | head -n 1 || true)
if [ -n "$author_line" ]; then
if [ -n "${author_line:-}" ]; then
author=$(echo "$author_line" | cut -d ':' -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
if [ -n "$author" ]; then
echo "**Author:** $author" >> "$README_PATH"
@@ -440,50 +575,59 @@ jobs:
echo "" >> "$README_PATH"
if [ -f "media/panel/${skin_header}.png" ]; then
escaped_panel=$(echo "${skin_header}.png" | sed 's/ /%20/g')
escaped_panel=$(printf "%s" "${skin_header}.png" | sed 's/ /%20/g')
echo "![$skin_header Ranking Panel](media/panel/$escaped_panel)" >> "$README_PATH"
echo "" >> "$README_PATH"
fi
mod_icon_file="${skin_header}-mod-icons.png"
if [ -f "media/icons/$mod_icon_file" ]; then
escaped_mod=$(echo "$mod_icon_file" | sed 's/ /%20/g')
escaped_mod=$(printf "%s" "$mod_icon_file" | sed 's/ /%20/g')
echo "![$skin_header Mods](media/icons/$escaped_mod)" >> "$README_PATH"
echo "" >> "$README_PATH"
fi
done < "$ORDER_FILE"
echo "Step 5: Processing extra skins..."
find "$DANSER_SKINS_DIR" -mindepth 1 -maxdepth 1 -type d | while IFS= read -r dir; do
skin=$(basename "$dir")
echo " Processing extra skin: $skin"
ini_file=$(find "$dir" -maxdepth 1 -iname "skin.ini" | head -n 1)
ini_file=$(find "$dir" -maxdepth 1 -iname "skin.ini" | head -n 1 || true)
skin_header="$skin"
if [ -f "$ini_file" ]; then
name_line=$(grep -i '^[[:space:]]*name:' "$ini_file" | head -n 1)
if [ -n "$name_line" ]; then
skin_header=$(echo "$name_line" | cut -d ':' -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
name_line=$(grep -i '^[[:space:]]*name:' "$ini_file" | head -n 1 || true)
if [ -n "${name_line:-}" ]; then
new_name=$(echo "$name_line" | cut -d ':' -f2- | sed 's/^[[:space:]]*//')
new_name=$(sanitize_filename "$new_name")
[ -n "$new_name" ] && skin_header="$new_name"
fi
fi
skin_header=$(printf '%s' "$skin_header" | tr -d '\r\n' | sed -e 's/[[:space:]]*$//')
if grep -Fxq "$skin_header" "$SEEN_HEADERS_FILE"; then
echo " Already seen (extra): $skin_header"
continue
fi
if grep -Fxq "$skin" "$JSON_SKINS_TMP"; then
echo " Already ordered (extra): $skin"
continue
fi
echo "$skin_header" >> "$SEEN_HEADERS_FILE"
escaped_img=$(echo "$skin_header.gif" | sed 's/ /%20/g')
escaped_osk=$(echo "$skin_header.osk" | sed 's/ /%20/g')
escaped_img=$(printf "%s" "$skin_header.gif" | sed 's/ /%20/g')
escaped_osk=$(printf "%s" "$skin_header.osk" | sed 's/ /%20/g')
echo " Writing extra skin: $skin_header"
echo "## [$skin_header]($REGISTRY_URL/$USER_REPOSITORY/media/tag/$new_tag/export/$escaped_osk)" >> "$README_PATH"
echo "" >> "$README_PATH"
if [ -f "$ini_file" ]; then
author_line=$(grep -i '^[[:space:]]*Author:' "$ini_file" | head -n 1 || true)
if [ -n "$author_line" ]; then
if [ -n "${author_line:-}" ]; then
author=$(echo "$author_line" | cut -d ':' -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
if [ -n "$author" ]; then
echo "**Author:** $author" >> "$README_PATH"
@@ -496,65 +640,68 @@ jobs:
echo "" >> "$README_PATH"
if [ -f "media/panel/${skin_header}.png" ]; then
escaped_panel=$(echo "${skin_header}.png" | sed 's/ /%20/g')
escaped_panel=$(printf "%s" "${skin_header}.png" | sed 's/ /%20/g')
echo "![$skin_header Ranking Panel](media/panel/$escaped_panel)" >> "$README_PATH"
echo "" >> "$README_PATH"
fi
mod_icon_file="${skin_header}-mod-icons.png"
if [ -f "media/icons/$mod_icon_file" ]; then
escaped_mod=$(echo "$mod_icon_file" | sed 's/ /%20/g')
escaped_mod=$(printf "%s" "$mod_icon_file" | sed 's/ /%20/g')
echo "![$skin_header Mods](media/icons/$escaped_mod)" >> "$README_PATH"
echo "" >> "$README_PATH"
fi
done
rm "$DESC_FILE" "$ORDER_FILE" "$JSON_SKINS_TMP" "$SEEN_HEADERS_FILE"
echo "Step 7: Writing Build History section..."
echo "# Build History" >> "$README_PATH"
echo "" >> "$README_PATH"
echo "| Version | Date |" >> "$README_PATH"
echo "| ------- | ---- |" >> "$README_PATH"
echo " Getting latest commit date..."
current_commit_date=$(TZ="Europe/Zurich" date -d "$(git log -1 --format=%cI)" "+%d.%m.%Y %H:%M:%S")
echo " Latest commit date: $current_commit_date"
echo "| [\`$new_tag (Current)\`](https://git.sulejmani.xyz/arlind/skins/src/tag/$new_tag/README.md) | $current_commit_date |" >> "$README_PATH"
git tag --sort=-v:refname | grep -v "^$new_tag$" | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | while read -r tag; do
tag_date=$(git log -1 --format=%ci "$tag")
formatted_date=$(TZ="Europe/Zurich" date -d "$tag_date" "+%d.%m.%Y %H:%M:%S")
echo "| [\`$tag\`](https://git.sulejmani.xyz/arlind/skins/src/tag/$tag/README.md) | $formatted_date |" >> "$README_PATH"
done
echo " Checking for old tags..."
old_tags=$(git tag --sort=-v:refname | grep -v "^$new_tag$" | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' || true)
echo "README generation completed."
if [ -n "$old_tags" ]; then
echo " Found old tags:"
echo "$old_tags" | while read -r tag; do
echo " Processing tag: $tag"
tag_date=$(git log -1 --format=%ci "$tag")
formatted_date=$(TZ="Europe/Zurich" date -d "$tag_date" "+%d.%m.%Y %H:%M:%S")
echo "| [\`$tag\`](https://git.sulejmani.xyz/arlind/skins/src/tag/$tag/README.md) | $formatted_date |" >> "$README_PATH"
done
else
echo " No old tags found. Skipping old tags section."
fi
echo "README generation completed successfully."
- name: Configure Git
shell: bash
run: |
echo "Configuring git user and LFS..."
git config user.email "arlind@sulej.ch"
git config user.name "ci-bot"
git config lfs.https://${{ vars.CONTAINER_REGISTRY }}/arlind/skins.git/info/lfs.locksverify true
echo "Git configured."
- name: Add and Commit changes
shell: bash
run: |
git config advice.addIgnoredFile false
echo "Staging files for commit..."
git add README.md media/gameplay/* media/panel/* media/icons/* export/*
echo "Committing changes..."
git commit -m "[ci skip] push back from pipeline" -q || echo "No changes to commit"
echo "Commit step completed."
- name: Push changes and create tag
shell: bash
run: |
echo "Checking branch and pushing changes..."
if [ "${GITHUB_REF}" = "refs/heads/main" ]; then
echo "On main branch: pushing to origin main..."
git push origin HEAD:main || echo "No changes to push"
echo "Creating and pushing tag $new_tag..."
git tag "$new_tag"
git push origin "$new_tag"
else
echo "On branch ${GITHUB_REF_NAME}: pushing to origin ${GITHUB_REF_NAME}..."
git push origin HEAD:"${GITHUB_REF_NAME}" || echo "No changes to push"
fi
echo "Push step completed."