Update .gitea/actions/generate-docs/action.yml

This commit is contained in:
Arlind
2025-10-03 21:29:35 +02:00
parent c1a5162536
commit b10f1fe7d6

View File

@@ -1,271 +1,275 @@
name: "Generate Documentation" name: "Generate Documentation"
description: "Generate README index and per-skin markdown pages" description: "Generate README index and per-skin markdown pages"
inputs: inputs:
new_tag: new_tag:
description: "The new tag for this build" description: "The new tag for this build"
required: true required: true
readme_path: readme_path:
description: "Path to write README.md" description: "Path to write README.md"
required: true required: true
doc_dir: doc_dir:
description: "Directory to write per-skin markdown pages" description: "Directory to write per-skin markdown pages"
required: true required: true
user_repository:
runs: description: "Path of the repository (relative inside container)"
using: "composite" required: true
steps:
- name: Generate README
shell: bash runs:
run: | using: "composite"
echo "Generating README index…" steps:
- name: Generate README
sanitize_filename() { shell: bash
echo "$1" | \ run: |
tr -d '\000-\037' | \ echo "Generating README index…"
sed -e 's#[\\/:\*\?"<>|]#-#g' | \
sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' sanitize_filename() {
} echo "$1" | \
tr -d '\000-\037' | \
url_encode_path() { sed -e 's#[\\/:\*\?"<>|]#-#g' | \
local IFS='/' sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'
local parts=($1) }
local encoded=""
for part in "${parts[@]}"; do url_encode_path() {
[ -n "$encoded" ] && encoded+="/" local IFS='/'
encoded+=$(printf '%s' "$part" | jq -sRr @uri) local parts=($1)
done local encoded=""
echo "$encoded" for part in "${parts[@]}"; do
} [ -n "$encoded" ] && encoded+="/"
encoded+=$(printf '%s' "$part" | jq -sRr @uri)
SKINS_JSON_FILE="${{ github.workspace }}/.gitea/workflows/skins.json" done
DESC_FILE=$(mktemp) echo "$encoded"
}
echo "---" > "${{ inputs.readme_path }}"
echo "gitea: none" >> "${{ inputs.readme_path }}" SKINS_JSON_FILE="${{ github.workspace }}/.gitea/workflows/skins.json"
echo "include_toc: true" >> "${{ inputs.readme_path }}" DESC_FILE=$(mktemp)
echo "---" >> "${{ inputs.readme_path }}"
echo "" >> "${{ inputs.readme_path }}" echo "---" > "${{ inputs.readme_path }}"
echo "# Skins" >> "${{ inputs.readme_path }}" echo "gitea: none" >> "${{ inputs.readme_path }}"
echo "" >> "${{ inputs.readme_path }}" echo "include_toc: true" >> "${{ inputs.readme_path }}"
echo "<!--" >> "${{ inputs.readme_path }}" echo "---" >> "${{ inputs.readme_path }}"
echo "osuid: $OSU_ID" >> "${{ inputs.readme_path }}" echo "" >> "${{ inputs.readme_path }}"
echo "-->" >> "${{ inputs.readme_path }}" echo "# Skins" >> "${{ inputs.readme_path }}"
echo "" >> "${{ inputs.readme_path }}" echo "" >> "${{ inputs.readme_path }}"
echo "**Go back to [osc/skins]($REGISTRY_URL/osc/skins)**" >> "${{ inputs.readme_path }}" echo "<!--" >> "${{ inputs.readme_path }}"
echo "" >> "${{ inputs.readme_path }}" echo "osuid: $OSU_ID" >> "${{ inputs.readme_path }}"
echo "**Click on the Skin name to download it, or click on the thumbnail to see more about the skin, including a video preview, screenshots, and mod icons.**" >> "${{ inputs.readme_path }}" echo "-->" >> "${{ inputs.readme_path }}"
echo "" >> "${{ inputs.readme_path }}" echo "" >> "${{ inputs.readme_path }}"
echo "**Go back to [osc/skins]($REGISTRY_URL/osc/skins)**" >> "${{ inputs.readme_path }}"
jq -r '.descriptions | to_entries[] | "\(.key)=\(.value)"' "$SKINS_JSON_FILE" > "$DESC_FILE" echo "" >> "${{ inputs.readme_path }}"
jq -r '.order[]?' "$SKINS_JSON_FILE" > order.txt echo "**Click on the Skin name to download it, or click on the thumbnail to see more about the skin, including a video preview, screenshots, and mod icons.**" >> "${{ inputs.readme_path }}"
echo "" >> "${{ inputs.readme_path }}"
get_desc() {
grep -F -m1 -- "$1=" "$DESC_FILE" 2>/dev/null | cut -d '=' -f2- || true jq -r '.descriptions | to_entries[] | "\(.key)=\(.value)"' "$SKINS_JSON_FILE" > "$DESC_FILE"
} jq -r '.order[]?' "$SKINS_JSON_FILE" > order.txt
declare -A ordered get_desc() {
while IFS= read -r skin; do grep -F -m1 -- "$1=" "$DESC_FILE" 2>/dev/null | cut -d '=' -f2- || true
[ "$skin" = "default-skin" ] && continue }
ordered["$skin"]=1
dir="$DANSER_SKINS_DIR/$skin" declare -A ordered
[ ! -d "$dir" ] && continue while IFS= read -r skin; do
[ "$skin" = "default-skin" ] && continue
ini_file=$(find "$dir" -maxdepth 1 -iname "skin.ini" | head -n1 || true) ordered["$skin"]=1
skin_header="$skin" dir="$DANSER_SKINS_DIR/$skin"
[ ! -d "$dir" ] && continue
if [ -f "$ini_file" ]; then
name_line=$(grep -a -i -m1 'Name[[:space:]]*:' "$ini_file" || true) ini_file=$(find "$dir" -maxdepth 1 -iname "skin.ini" | head -n1 || true)
if [ -n "$name_line" ]; then skin_header="$skin"
val="${name_line#*:}"
val="$(echo "$val" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')" if [ -f "$ini_file" ]; then
[ -n "$val" ] && skin_header=$(sanitize_filename "$val") name_line=$(grep -a -i -m1 'Name[[:space:]]*:' "$ini_file" || true)
fi if [ -n "$name_line" ]; then
else val="${name_line#*:}"
continue val="$(echo "$val" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
fi [ -n "$val" ] && skin_header=$(sanitize_filename "$val")
fi
raw_path="$(printf "%s/%s" "$skin" "$skin_header" | sed 's/^ *//;s/ *$//')" else
base_path=$(url_encode_path "$raw_path") continue
fi
echo "## [$skin_header]($REGISTRY_URL/$USER_REPOSITORY/media/tag/${{ inputs.new_tag }}/export/${base_path}.osk)" >> "${{ inputs.readme_path }}"
echo "" >> "${{ inputs.readme_path }}" raw_path="$(printf "%s/%s" "$skin" "$skin_header" | sed 's/^ *//;s/ *$//')"
base_path=$(url_encode_path "$raw_path")
desc=$(get_desc "$skin")
[ -n "$desc" ] && { echo "$desc" >> "${{ inputs.readme_path }}"; echo "" >> "${{ inputs.readme_path }}"; } echo "## [$skin_header]($REGISTRY_URL/${{ inputs.user_repository }}/media/tag/${{ inputs.new_tag }}/export/${base_path}.osk)" >> "${{ inputs.readme_path }}"
echo "" >> "${{ inputs.readme_path }}"
if [ -f "$ini_file" ]; then
author_line=$(grep -i '^[[:space:]]*Author:' "$ini_file" | head -n1 || true) desc=$(get_desc "$skin")
if [ -n "$author_line" ]; then [ -n "$desc" ] && { echo "$desc" >> "${{ inputs.readme_path }}"; echo "" >> "${{ inputs.readme_path }}"; }
author=$(echo "$author_line" | cut -d ':' -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
[ -n "$author" ] && { echo "**Author:** $author" >> "${{ inputs.readme_path }}"; echo "" >> "${{ inputs.readme_path }}"; } if [ -f "$ini_file" ]; then
fi author_line=$(grep -i '^[[:space:]]*Author:' "$ini_file" | head -n1 || true)
fi if [ -n "$author_line" ]; then
author=$(echo "$author_line" | cut -d ':' -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
echo "[![$skin_header Thumbnail](media/thumbnail/${base_path}.webp)](/docs/${base_path}.md)" >> "${{ inputs.readme_path }}" [ -n "$author" ] && { echo "**Author:** $author" >> "${{ inputs.readme_path }}"; echo "" >> "${{ inputs.readme_path }}"; }
echo "" >> "${{ inputs.readme_path }}" fi
done < order.txt fi
for dir in "$DANSER_SKINS_DIR"/*; do echo "[![$skin_header Thumbnail](media/thumbnail/${base_path}.webp)](/docs/${base_path}.md)" >> "${{ inputs.readme_path }}"
[ -d "$dir" ] || continue echo "" >> "${{ inputs.readme_path }}"
skin="$(basename "$dir")" done < order.txt
[ "$skin" = "default-skin" ] && continue
[[ -n "${ordered[$skin]}" ]] && continue for dir in "$DANSER_SKINS_DIR"/*; do
[ -d "$dir" ] || continue
ini_file=$(find "$dir" -maxdepth 1 -iname "skin.ini" | head -n1 || true) skin="$(basename "$dir")"
skin_header="$skin" [ "$skin" = "default-skin" ] && continue
[[ -n "${ordered[$skin]}" ]] && continue
if [ -f "$ini_file" ]; then
name_line=$(grep -a -i -m1 'Name[[:space:]]*:' "$ini_file" || true) ini_file=$(find "$dir" -maxdepth 1 -iname "skin.ini" | head -n1 || true)
if [ -n "$name_line" ]; then skin_header="$skin"
val="${name_line#*:}"
val="$(echo "$val" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')" if [ -f "$ini_file" ]; then
[ -n "$val" ] && skin_header=$(sanitize_filename "$val") name_line=$(grep -a -i -m1 'Name[[:space:]]*:' "$ini_file" || true)
fi if [ -n "$name_line" ]; then
else val="${name_line#*:}"
continue val="$(echo "$val" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
fi [ -n "$val" ] && skin_header=$(sanitize_filename "$val")
fi
raw_path="$(printf "%s/%s" "$skin" "$skin_header" | sed 's/^ *//;s/ *$//')" else
base_path=$(url_encode_path "$raw_path") continue
fi
echo "## [$skin_header]($REGISTRY_URL/$USER_REPOSITORY/media/tag/${{ inputs.new_tag }}/export/${base_path}.osk)" >> "${{ inputs.readme_path }}"
echo "" >> "${{ inputs.readme_path }}" raw_path="$(printf "%s/%s" "$skin" "$skin_header" | sed 's/^ *//;s/ *$//')"
base_path=$(url_encode_path "$raw_path")
if [ -f "$ini_file" ]; then
author_line=$(grep -i '^[[:space:]]*Author:' "$ini_file" | head -n1 || true) echo "## [$skin_header]($REGISTRY_URL/${{ inputs.user_repository }}/media/tag/${{ inputs.new_tag }}/export/${base_path}.osk)" >> "${{ inputs.readme_path }}"
if [ -n "$author_line" ]; then echo "" >> "${{ inputs.readme_path }}"
author=$(echo "$author_line" | cut -d ':' -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
[ -n "$author" ] && { echo "**Author:** $author" >> "${{ inputs.readme_path }}"; echo "" >> "${{ inputs.readme_path }}"; } if [ -f "$ini_file" ]; then
fi author_line=$(grep -i '^[[:space:]]*Author:' "$ini_file" | head -n1 || true)
fi if [ -n "$author_line" ]; then
author=$(echo "$author_line" | cut -d ':' -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
echo "[![$skin_header Thumbnail](media/thumbnail/${base_path}.webp)](/docs/${base_path}.md)" >> "${{ inputs.readme_path }}" [ -n "$author" ] && { echo "**Author:** $author" >> "${{ inputs.readme_path }}"; echo "" >> "${{ inputs.readme_path }}"; }
echo "" >> "${{ inputs.readme_path }}" fi
done fi
echo "# Build History" >> "${{ inputs.readme_path }}" echo "[![$skin_header Thumbnail](media/thumbnail/${base_path}.webp)](/docs/${base_path}.md)" >> "${{ inputs.readme_path }}"
echo "" >> "${{ inputs.readme_path }}" echo "" >> "${{ inputs.readme_path }}"
echo "| Version | Date |" >> "${{ inputs.readme_path }}" done
echo "| ------- | ---- |" >> "${{ inputs.readme_path }}"
echo "# Build History" >> "${{ inputs.readme_path }}"
current_commit_date=$(TZ="Europe/Zurich" date -d "$(git log -1 --format=%cI)" "+%d.%m.%Y %H:%M:%S") echo "" >> "${{ inputs.readme_path }}"
echo "| [\`${{ inputs.new_tag }} (Current)\`]($REGISTRY_URL/$USER_REPOSITORY/src/tag/${{ inputs.new_tag }}/README.md) | $current_commit_date |" >> "${{ inputs.readme_path }}" echo "| Version | Date |" >> "${{ inputs.readme_path }}"
echo "| ------- | ---- |" >> "${{ inputs.readme_path }}"
old_tags=$(git tag --sort=-v:refname | grep -v "^${{ inputs.new_tag }}$" | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' || true)
if [ -n "$old_tags" ]; then current_commit_date=$(TZ="Europe/Zurich" date -d "$(git log -1 --format=%cI)" "+%d.%m.%Y %H:%M:%S")
echo "$old_tags" | while read -r tag; do echo "| [\`${{ inputs.new_tag }} (Current)\`]($REGISTRY_URL/${{ inputs.user_repository }}/src/tag/${{ inputs.new_tag }}/README.md) | $current_commit_date |" >> "${{ inputs.readme_path }}"
tag_date=$(git log -1 --format=%ci "$tag")
formatted_date=$(TZ="Europe/Zurich" date -d "$tag_date" "+%d.%m.%Y %H:%M:%S") old_tags=$(git tag --sort=-v:refname | grep -v "^${{ inputs.new_tag }}$" | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' || true)
echo "| [\`$tag\`]($REGISTRY_URL/$USER_REPOSITORY/src/tag/$tag/README.md) | $formatted_date |" >> "${{ inputs.readme_path }}" if [ -n "$old_tags" ]; then
done echo "$old_tags" | while read -r tag; do
fi tag_date=$(git log -1 --format=%ci "$tag")
formatted_date=$(TZ="Europe/Zurich" date -d "$tag_date" "+%d.%m.%Y %H:%M:%S")
echo "README index generated successfully." echo "| [\`$tag\`]($REGISTRY_URL/${{ inputs.user_repository }}/src/tag/$tag/README.md) | $formatted_date |" >> "${{ inputs.readme_path }}"
done
- name: Generate Per-Skin Pages fi
shell: bash
run: | echo "README index generated successfully."
echo "Generating detailed per-skin markdown pages…"
- name: Generate Per-Skin Pages
sanitize_filename() { shell: bash
echo "$1" | \ run: |
tr -d '\000-\037' | \ echo "Generating detailed per-skin markdown pages…"
sed -e 's#[\\/:\*\?"<>|]#-#g' | \
sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' sanitize_filename() {
} echo "$1" | \
tr -d '\000-\037' | \
url_encode_path() { sed -e 's#[\\/:\*\?"<>|]#-#g' | \
local IFS='/' sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'
local parts=($1) }
local encoded=""
for part in "${parts[@]}"; do url_encode_path() {
[ -n "$encoded" ] && encoded+="/" local IFS='/'
encoded+=$(printf '%s' "$part" | jq -sRr @uri) local parts=($1)
done local encoded=""
echo "$encoded" for part in "${parts[@]}"; do
} [ -n "$encoded" ] && encoded+="/"
encoded+=$(printf '%s' "$part" | jq -sRr @uri)
mkdir -p "${{ inputs.doc_dir }}" done
echo "$encoded"
for dir in "$DANSER_SKINS_DIR"/*; do }
[ -d "$dir" ] || continue
mkdir -p "${{ inputs.doc_dir }}"
skin=$(basename "$dir")
[ "$skin" = "default-skin" ] && continue for dir in "$DANSER_SKINS_DIR"/*; do
ini_file=$(find "$dir" -maxdepth 1 -iname "skin.ini" | head -n1 || true) [ -d "$dir" ] || continue
skin_header="$skin"
skin=$(basename "$dir")
if [ -f "$ini_file" ]; then [ "$skin" = "default-skin" ] && continue
line=$(grep -i '^[[:space:]]*Name:' "$ini_file" | head -n1 || true) ini_file=$(find "$dir" -maxdepth 1 -iname "skin.ini" | head -n1 || true)
if [ -n "$line" ]; then skin_header="$skin"
val="${line#*:}"
val="$(echo "$val" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')" if [ -f "$ini_file" ]; then
if [ -n "$val" ]; then line=$(grep -i '^[[:space:]]*Name:' "$ini_file" | head -n1 || true)
skin_header=$(sanitize_filename "$val") if [ -n "$line" ]; then
fi val="${line#*:}"
fi val="$(echo "$val" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
fi if [ -n "$val" ]; then
skin_header=$(sanitize_filename "$val")
raw_path="${skin}/${skin_header}" fi
base_path=$(url_encode_path "$raw_path") fi
osk_url="$REGISTRY_URL/$USER_REPOSITORY/media/tag/${{ inputs.new_tag }}/export/${base_path}.osk" fi
md_file_path="${{ inputs.doc_dir }}/${raw_path}.md"
raw_path="${skin}/${skin_header}"
mkdir -p "$(dirname "$md_file_path")" base_path=$(url_encode_path "$raw_path")
osk_url="$REGISTRY_URL/${{ inputs.user_repository }}/media/tag/${{ inputs.new_tag }}/export/${base_path}.osk"
video_url="$REGISTRY_URL/$USER_REPOSITORY/media/tag/${{ inputs.new_tag }}/media/gameplay/${base_path}.mp4" md_file_path="${{ inputs.doc_dir }}/${raw_path}.md"
author="" mkdir -p "$(dirname "$md_file_path")"
if [ -f "$ini_file" ]; then
author_line=$(grep -i '^[[:space:]]*Author:' "$ini_file" | head -n1 || true) video_url="$REGISTRY_URL/${{ inputs.user_repository }}/media/tag/${{ inputs.new_tag }}/media/gameplay/${base_path}.mp4"
if [ -n "$author_line" ]; then
author=$(echo "$author_line" | cut -d ':' -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') author=""
fi if [ -f "$ini_file" ]; then
fi author_line=$(grep -i '^[[:space:]]*Author:' "$ini_file" | head -n1 || true)
if [ -n "$author_line" ]; then
{ author=$(echo "$author_line" | cut -d ':' -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
echo "# [$skin_header]($osk_url)" fi
echo "" fi
[ -n "$author" ] && echo "**Author:** $author"
[ -n "$author" ] && echo "" {
echo "# [$skin_header]($osk_url)"
echo "## Hitsounds" echo ""
echo "<video controls autoplay loop muted playsinline src=\"$video_url\" type=\"video/mp4\">" [ -n "$author" ] && echo "**Author:** $author"
echo "</video>" [ -n "$author" ] && echo ""
echo ""
echo "## Hitsounds"
echo "## Ranking Panel" echo "<video controls autoplay loop muted playsinline src=\"$video_url\" type=\"video/mp4\">"
echo "![](/media/panel/${base_path}.webp)" echo "</video>"
echo "" echo ""
echo "## Mod Icons" echo "## Ranking Panel"
echo "![](/media/icons/${base_path}-mod-icons.webp)" echo "![](/media/panel/${base_path}.webp)"
echo ""
echo ""
echo "## Build History" echo "## Mod Icons"
echo "" echo "![](/media/icons/${base_path}-mod-icons.webp)"
echo "| Version | Date |"
echo "| ------- | ---- |" echo ""
echo "## Build History"
current_commit_date=$(TZ="Europe/Zurich" date -d "$(git log -1 --format=%cI)" "+%d.%m.%Y %H:%M:%S") echo ""
echo "| [\`${{ inputs.new_tag }} (Current)\`]($REGISTRY_URL/$USER_REPOSITORY/src/tag/${{ inputs.new_tag }}/docs/${base_path}.md) | $current_commit_date |" echo "| Version | Date |"
echo "| ------- | ---- |"
old_tags=$(git tag --sort=-v:refname | grep -v "^${{ inputs.new_tag }}$" | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' || true)
if [ -n "$old_tags" ]; then current_commit_date=$(TZ="Europe/Zurich" date -d "$(git log -1 --format=%cI)" "+%d.%m.%Y %H:%M:%S")
echo "$old_tags" | while read -r tag; do echo "| [\`${{ inputs.new_tag }} (Current)\`]($REGISTRY_URL/${{ inputs.user_repository }}/src/tag/${{ inputs.new_tag }}/docs/${base_path}.md) | $current_commit_date |"
raw_osk_path="export/${skin}/${skin_header}.osk"
if git ls-tree -r --name-only "$tag" | grep -Fx -- "$raw_osk_path" >/dev/null; then old_tags=$(git tag --sort=-v:refname | grep -v "^${{ inputs.new_tag }}$" | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' || true)
tag_date=$(git log -1 --format=%ci "$tag") if [ -n "$old_tags" ]; then
formatted_date=$(TZ="Europe/Zurich" date -d "$tag_date" "+%d.%m.%Y %H:%M:%S") echo "$old_tags" | while read -r tag; do
echo "| [\`$tag\`]($REGISTRY_URL/$USER_REPOSITORY/src/tag/$tag/docs/${base_path}.md) | $formatted_date |" raw_osk_path="export/${skin}/${skin_header}.osk"
fi if git ls-tree -r --name-only "$tag" | grep -Fx -- "$raw_osk_path" >/dev/null; then
done tag_date=$(git log -1 --format=%ci "$tag")
fi formatted_date=$(TZ="Europe/Zurich" date -d "$tag_date" "+%d.%m.%Y %H:%M:%S")
echo "| [\`$tag\`]($REGISTRY_URL/${{ inputs.user_repository }}/src/tag/$tag/docs/${base_path}.md) | $formatted_date |"
} > "$md_file_path" fi
done
echo " → Wrote $md_file_path" fi
done
} > "$md_file_path"
echo "Per-skin markdown pages complete."
echo " → Wrote $md_file_path"
done
echo "Per-skin markdown pages complete."