1
+ name : Generate README
2
+
3
+ on :
4
+ push :
5
+ paths :
6
+ - ' Icons/**'
7
+ - ' readmehead.md'
8
+ workflow_dispatch :
9
+
10
+ jobs :
11
+ generate-readme :
12
+ runs-on : ubuntu-latest
13
+ steps :
14
+ - uses : actions/checkout@v3
15
+
16
+ - name : Set up Python
17
+ uses : actions/setup-python@v4
18
+ with :
19
+ python-version : ' 3.x'
20
+
21
+ - name : Install dependencies
22
+ run : pip install PyGithub
23
+
24
+ - name : Generate README
25
+ env :
26
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
27
+ run : |
28
+ python - <<EOF
29
+ import os
30
+ import re
31
+ from github import Github
32
+
33
+ def get_icon_url(repo, path):
34
+ return f"https://github.com/{repo.full_name}/blob/main/{path}"
35
+
36
+ def generate_table(icons):
37
+ table = "| Icon | Name | Category |\n|------|------|----------|\n"
38
+ for icon in sorted(icons, key=lambda x: (x['category'], x['subcategory'], x['name'])):
39
+ table += f"| ![{icon['name']}]({icon['path']}) | [{icon['name']}]({icon['url']}) | {icon['category']}/{icon['subcategory']} |\n"
40
+ return table
41
+
42
+ # Initialize GitHub client
43
+ g = Github(os.environ['GITHUB_TOKEN'])
44
+ repo = g.get_repo(os.environ['GITHUB_REPOSITORY'])
45
+
46
+ # Get all icon files
47
+ icons = []
48
+ contents = repo.get_contents("Icons")
49
+ while contents:
50
+ file_content = contents.pop(0)
51
+ if file_content.type == "dir":
52
+ contents.extend(repo.get_contents(file_content.path))
53
+ else:
54
+ if file_content.name.endswith('.png') and '@4x' not in file_content.name:
55
+ match = re.match(r'(.+)=(.+)\.png', file_content.name)
56
+ if match:
57
+ subcategory, name = match.groups()
58
+ category = os.path.basename(os.path.dirname(file_content.path))
59
+ icons.append({
60
+ 'name': name,
61
+ 'path': file_content.path,
62
+ 'url': get_icon_url(repo, file_content.path),
63
+ 'category': category,
64
+ 'subcategory': subcategory
65
+ })
66
+
67
+ # Generate README content
68
+ with open('readmehead.md', 'r') as f:
69
+ readme_content = f.read()
70
+
71
+ readme_content += "\n\n## Icons\n\n"
72
+ readme_content += generate_table(icons)
73
+
74
+ # Update README.md
75
+ readme_file = repo.get_contents("README.md")
76
+ repo.update_file(
77
+ path="README.md",
78
+ message="Update README with latest icons",
79
+ content=readme_content,
80
+ sha=readme_file.sha
81
+ )
82
+
83
+ print("README.md has been updated successfully.")
84
+ EOF
85
+
86
+ - name : Commit changes
87
+ run : |
88
+ git config --local user.email "action@github.com"
89
+ git config --local user.name "GitHub Action"
90
+ git add README.md
91
+ git commit -m "Update README with latest icons" || echo "No changes to commit"
92
+ git push
0 commit comments