1616jobs :
1717 update-readme :
1818 runs-on : ubuntu-latest
19-
19+ permissions :
20+ contents : write
21+
2022 steps :
2123 - uses : actions/checkout@v4
2224 with :
2325 fetch-depth : 0 # Fetch all history for all branches and tags
2426
2527 - name : Check for new themes
2628 id : check-themes
29+ env :
30+ GH_TOKEN : ${{ github.token }}
2731 run : |
28- # Get list of all current theme directories, sorted
29- current_themes=$(find Themes -maxdepth 1 -mindepth 1 -type d | sed 's|Themes/||' | sort)
30- echo "::debug::Current themes in directory:"
32+ normalize_name() {
33+ echo "$1" | sed "s/ /_/g; s/'//g; s/!//g"
34+ }
35+
36+ # Get normalized list of theme directories
37+ current_themes=$(find Themes -maxdepth 1 -mindepth 1 -type d | sed 's|Themes/||' | while IFS= read -r name; do normalize_name "$name"; done | sort)
38+ echo "::debug::Current themes (normalized):"
3139 echo "::debug::$current_themes"
32-
33- # Get list of themes from README, sorted
34- readme_themes=$(grep -o 'PackedThemes/[^/]*\.7z' README.md |
35- sed 's|PackedThemes/||' |
36- sed 's|\.7z$||' |
37- sed 's/%20/ /g' |
38- sort)
39- echo "::debug::Themes found in README:"
40- echo "::debug::$readme_themes"
41-
42- # Create temporary files for comparison
40+
41+ # Get list of themes from release assets
42+ release_themes=$(gh release view 1 --json assets -q '.assets[].name' 2>/dev/null | sed 's|\.7z$||' | sort)
43+ echo "::debug::Themes in release:"
44+ echo "::debug::$release_themes"
45+
4346 echo "$current_themes" > current_themes.txt
44- echo "$readme_themes" > readme_themes.txt
45-
46- # Compare the sorted lists and store differences
47- if ! diff current_themes.txt readme_themes.txt > theme_diff.txt; then
48- echo "::notice::Differences detected between directory and README:"
47+ echo "$release_themes" > release_themes.txt
48+
49+ if ! diff current_themes.txt release_themes.txt > theme_diff.txt; then
50+ echo "::notice::Differences detected between directory and release:"
4951 cat theme_diff.txt
5052 echo "theme_changed=1" >> "$GITHUB_OUTPUT"
5153 else
5254 echo "::notice::No differences detected"
5355 echo "theme_changed=0" >> "$GITHUB_OUTPUT"
5456 fi
55-
56- # Clean up temp files
57- rm current_themes.txt readme_themes.txt theme_diff.txt
57+
58+ rm current_themes.txt release_themes.txt theme_diff.txt
5859
5960 - name : Generate Theme Gallery
6061 if : github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_run' || steps.check-themes.outputs.theme_changed == '1'
6162 id : generate-gallery
63+ env :
64+ GH_TOKEN : ${{ github.token }}
6265 run : |
66+ normalize_name() {
67+ echo "$1" | sed "s/ /_/g; s/'//g; s/!//g"
68+ }
69+
70+ # Fetch release asset list once
71+ RELEASE_ASSETS=$(gh release view 1 --json assets -q '.assets[].name' 2>/dev/null || echo "")
72+
6373 # Create backup of current README
6474 cp README.md README.md.bak
65-
75+
6676 # Create temporary files
6777 TEMP_FILE=$(mktemp)
6878 GALLERY_CONTENT=$(mktemp)
69-
79+
7080 # Generate the new gallery content
7181 echo -e "## Theme Gallery\n" > "$GALLERY_CONTENT"
72-
82+
7383 # Initialize arrays for the grid
7484 declare -a themes=()
75-
85+
7686 # Process each theme folder
7787 for theme_dir in Themes/*/; do
7888 if [ -d "$theme_dir" ] && [ "$theme_dir" != "PackedThemes/" ]; then
7989 theme_name="${theme_dir#Themes/}"
8090 theme_name="${theme_name%/}"
8191 preview_path_gif="$theme_dir/preview.gif"
8292 preview_path_png="$theme_dir/preview.png"
83- packed_path="PackedThemes/$theme_name.7z"
8493 config_path="$theme_dir/config.json"
85-
86- if [ -f "$packed_path" ] && [ -f "$config_path" ] && { [ -f "$preview_path_gif" ] || [ -f "$preview_path_png" ]; }; then
94+ normalized_theme="$(normalize_name "$theme_name")"
95+
96+ if echo "$RELEASE_ASSETS" | grep -qF "${normalized_theme}.7z" && [ -f "$config_path" ] && { [ -f "$preview_path_gif" ] || [ -f "$preview_path_png" ]; }; then
8797 # Extract author and description from config.json
8898 author=$(jq -r '.author' "$config_path")
8999 description=$(jq -r '.description' "$config_path")
90-
100+
91101 # Determine which preview file to use
92102 if [ -f "$preview_path_gif" ]; then
93103 preview_path="$preview_path_gif"
94104 else
95105 preview_path="$preview_path_png"
96106 fi
97-
107+
98108 # Create properly encoded URLs
99109 preview_path=$(echo "$preview_path" | sed 's|^Themes/||')
100110 theme_name_encoded=$(echo "$theme_name" | sed -e 's/ /%20/g')
101-
111+
102112 preview_url="https://raw.githubusercontent.com/$GITHUB_REPOSITORY/main/Themes/${theme_name_encoded}/preview.png"
103113 preview_img="<img title=\"${theme_name}\" width=\"200px\" src=\"${preview_url}\" />"
104- download_url="https://raw.githubusercontent. com/$GITHUB_REPOSITORY/main/PackedThemes/${theme_name_encoded }.7z"
105-
106- # Clean up URLs (remove any double slashes except after https:)
114+ download_url="https://github. com/$GITHUB_REPOSITORY/releases/download/1/${normalized_theme }.7z"
115+
116+ # Clean up preview URL (remove any double slashes except after https:)
107117 preview_url=$(echo "$preview_url" | sed -e 's|//|/|g' -e 's|https:/|https://|')
108- download_url=$(echo "$download_url" | sed -e 's|//|/|g' -e 's|https:/|https://|')
109-
118+
110119 # Create theme cell content
111120 theme_cell="<td align=\"center\" valign=\"top\" width=\"33.33%\">
112121 <br/>
@@ -116,7 +125,7 @@ jobs:
116125 <small><i>$author</i></small><br/>
117126 <small>$description</small><br/>
118127 </td>"
119-
128+
120129 themes+=("$theme_cell")
121130 fi
122131 fi
0 commit comments