name: "Discover and Detect Skins" description: "Find all skins and detect which ones changed since last tag or based on inputs" inputs: force_rebuild: description: "Force rebuild all skins" required: false default: "false" target_skins: description: "JSON array of skins to rebuild (e.g., '[\"skin1\", \"skin2\"]')" required: false default: "" outputs: changed_skins_file: description: "Path to file containing changed skins" value: ${{ steps.detect.outputs.changed_skins_file }} all_skins: description: "All discovered skins (JSON array)" value: ${{ steps.discover_all.outputs.all_skins }} runs: using: "composite" steps: - name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 0 fetch-tags: true - name: Discover all skins id: discover_all shell: bash run: | echo "Discovering all skins in $SKINS_DIR…" # Find all skins and create JSON, write to shared file all_skins_file="/tmp/all_skins_shared.json" find "$SKINS_DIR" -mindepth 1 -maxdepth 1 -type d -print0 \ | while IFS= read -r -d '' dir; do basename "$dir" done \ | jq -R . | jq -cs . > "$all_skins_file" json=$(cat "$all_skins_file") { echo "all_skins<> "$GITHUB_OUTPUT" echo "all_skins_file=$all_skins_file" >> "$GITHUB_OUTPUT" - name: Detect Changed Skin Directories id: detect shell: bash run: | set -e echo "[Detect Changed Skin Directories Started]" # Read from shared file instead of using GitHub Actions output all_skins_file="/tmp/all_skins_shared.json" temp_all_skins="/tmp/all_skins_raw_$RANDOM.txt" jq -r '.[]' "$all_skins_file" > "$temp_all_skins" mapfile -t all_skins < "$temp_all_skins" rm -f "$temp_all_skins" force_rebuild='${{ inputs.force_rebuild }}' target_skins='${{ inputs.target_skins }}' skins=() deleted_skins=() echo "→ Force rebuild flag: $force_rebuild" echo "→ Target skins input: $target_skins" if [[ "$force_rebuild" == "true" ]]; then echo "→ Force rebuild is enabled. Using ALL_SKINS_DIR for full list…" skins=("${all_skins[@]}") echo " ✓ Found ${#skins[@]} skin directories (from ALL_SKINS_DIR)" elif [[ -n "$target_skins" ]]; then echo "→ Target skins specified. Using target_skins input…" # Use a temporary file to safely handle special characters temp_target_file="/tmp/target_skins_$RANDOM.json" printf '%s' "$target_skins" > "$temp_target_file" temp_target_raw="/tmp/target_skins_raw_$RANDOM.txt" jq -r '.[]' "$temp_target_file" > "$temp_target_raw" mapfile -t skins < "$temp_target_raw" rm -f "$temp_target_file" "$temp_target_raw" echo " ✓ Found ${#skins[@]} skin(s) from target_skins input" else echo "→ No rebuild flags set. Finding latest git tag..." git tag --sort=-creatordate | head -n 1 > /tmp/latest_tag_$RANDOM.txt || true latest_tag="" if [ -s /tmp/latest_tag_$RANDOM.txt ]; then latest_tag="$(cat /tmp/latest_tag_$RANDOM.txt)" rm -f /tmp/latest_tag_$RANDOM.txt fi if [[ -n "$latest_tag" ]]; then echo "→ Latest tag found: $latest_tag" echo "→ Finding added/modified skins since $latest_tag…" temp_skins_am="/tmp/skins_am_$RANDOM.txt" git diff --name-only -z --diff-filter=AM "$latest_tag" HEAD \ | while IFS= read -r -d '' file; do [[ $file == Skins/* ]] && echo "${file#Skins/}" | cut -d/ -f1 done | sort -u > "$temp_skins_am" mapfile -t skins < "$temp_skins_am" rm -f "$temp_skins_am" echo " ✓ Found ${#skins[@]} added/modified skins" echo "→ Finding deleted skins since $latest_tag…" temp_skins_del="/tmp/skins_del_$RANDOM.txt" git diff --name-only -z --diff-filter=D "$latest_tag" HEAD \ | while IFS= read -r -d '' file; do [[ $file == Skins/* ]] && echo "${file#Skins/}" | cut -d/ -f1 done | sort -u > "$temp_skins_del" mapfile -t deleted_skins < "$temp_skins_del" rm -f "$temp_skins_del" if [ "${#deleted_skins[@]}" -gt 0 ]; then for d in "${deleted_skins[@]}"; do echo "→ Skin '$d' was deleted" done else echo " ✓ No skins deleted" fi else echo "→ No tag found. Falling back to ALL_SKINS_DIR for full list…" skins=("${all_skins[@]}") echo " ✓ Found ${#skins[@]} skin directories (from ALL_SKINS_DIR)" fi fi echo "" echo "[Cleaning Skin Names]" uniq_skins=() for skin in "${skins[@]}"; do skin="${skin#"${skin%%[![:space:]]*}"}" skin="${skin%"${skin##*[![:space:]]}"}" [[ -n "$skin" ]] && uniq_skins+=("$skin") done echo " ✓ ${#uniq_skins[@]} valid skin names after cleaning" echo "" echo "[Writing Changed Skins to File]" changed_skins_file="/tmp/changed_skins_$RANDOM.txt" if [ "${#uniq_skins[@]}" -eq 0 ]; then echo "→ No added/modified skins detected." echo "[]" > "$changed_skins_file" else printf '%s\n' "${uniq_skins[@]}" | jq -R . | jq -cs . > "$changed_skins_file" echo " ✓ Skins written to $changed_skins_file (JSON array)" fi { echo "changed_skins_file<> "$GITHUB_OUTPUT" echo "" echo "[Detect Changed Skin Directories Complete — ${#uniq_skins[@]} skins processed, ${#deleted_skins[@]} skins deleted]"