Skip to content

Commit 560d3ce

Browse files
committed
Update actions to avoid tabs on themes
1 parent 2e302e0 commit 560d3ce

File tree

3 files changed

+46
-30
lines changed

3 files changed

+46
-30
lines changed

.github/workflows/actions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
python-version: '3.x'
2020

2121
- name: 🏅 Install Python dependencies
22-
run: pip install -r requirements.txt
22+
run: pip install -r requirements.txt --root-user-action=ignore
2323

2424
- name: 🏅 Run Python scripts
2525
run: python tools/pipe-generateJson.py

tools/pipe-generateJson.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@
1717
# Iterate over all .yml files in the source directory
1818
for filepath in source_path.glob("*.yml"):
1919
with open(filepath, "r") as f:
20-
data = yaml.safe_load(f)
20+
content = f.read()
2121

22-
# Concatenate all values into a single string for hashing
22+
# Replace tabs with 4 spaces
23+
content = content.replace("\t", " ")
24+
25+
# Load the corrected YAML file
26+
data = yaml.safe_load(content)
27+
28+
# Concatenate all values into a single string to generate a hash
2329
values = ''.join(str(value) for value in data.values())
2430

2531
# Generate SHA-256 hash

tools/pipe-generateShFiles.py

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,47 @@
66
import yaml
77

88
folder_path = "./themes"
9-
dest_path = './installs'
9+
dest_path = "./installs"
1010
themes = []
1111

12-
# List files and directories in the folder
13-
folder_contents = os.listdir(dest_path)
12+
# Ensure the destination directory exists
13+
os.makedirs(dest_path, exist_ok=True)
1414

15-
# Delete each file in the folder
16-
for item in folder_contents:
15+
# Remove all files in the destination directory
16+
for item in os.listdir(dest_path):
1717
item_path = os.path.join(dest_path, item)
1818
if os.path.isfile(item_path):
1919
os.remove(item_path)
2020

21+
# Process YAML files
2122
for filename in os.listdir(folder_path):
2223
if filename.endswith(".yml"):
23-
with open(os.path.join(folder_path, filename), "r") as f:
24-
data = yaml.safe_load(f)
25-
theme = {f"{key}": data[key] for key in data if key.startswith("color")}
26-
theme.update({
27-
"name": data["name"],
28-
"foreground": data["foreground"],
29-
"background": data["background"],
30-
"cursorColor": data["cursor"]
31-
})
32-
themes.append(theme)
24+
file_path = os.path.join(folder_path, filename)
3325

34-
themes = sorted(themes, key=lambda x: x["name"])
26+
# Read and clean YAML content
27+
with open(file_path, "r") as f:
28+
content = f.read()
29+
30+
# Replace tabs with 4 spaces to avoid YAML parsing errors
31+
content = content.replace("\t", " ")
32+
33+
# Load the cleaned YAML
34+
data = yaml.safe_load(content)
3535

36-
colors_data = {"themes": themes}
36+
# Build the theme dictionary
37+
theme = {f"{key}": data[key] for key in data if key.startswith("color")}
38+
theme.update({
39+
"name": data["name"],
40+
"foreground": data["foreground"],
41+
"background": data["background"],
42+
"cursorColor": data["cursor"]
43+
})
44+
themes.append(theme)
3745

46+
# Sort themes by name
47+
themes = sorted(themes, key=lambda x: x["name"])
3848

39-
# create a template string for the shell script
49+
# Shell script template
4050
template = """\
4151
#!/usr/bin/env bash
4252
@@ -91,18 +101,18 @@
91101
fi
92102
"""
93103

94-
# loop over the color schemes and create a new shell script for each one
95-
for scheme in colors_data['themes']:
96-
# convert the scheme name to lowercase, replace spaces with dashes, remove accents, and replace non-alphanumeric characters with underscores
104+
# Generate .sh files for each color scheme
105+
for scheme in themes:
106+
# Convert theme name to a valid filename
97107
filename = re.sub(r'[^a-zA-Z0-9]+', '-', unidecode(scheme['name']).lower().replace(' ', '-'))
98108
filename = re.sub(r'[-]+', '-', filename).strip('-')
99109
filename = f"{dest_path}/{filename}.sh"
110+
100111
with open(filename, 'w') as f:
101112
f.write(template.format(**scheme))
102113

103-
# Find all files with ".sh" extension in the folder
104-
files = [f for f in os.listdir(dest_path) if os.path.isfile(os.path.join(dest_path, f)) and f.endswith('.sh')]
105-
106-
# Change permissions on each file
107-
for f in files:
108-
subprocess.run(['chmod', '775', os.path.join(dest_path, f)])
114+
# Change permissions for generated scripts
115+
for f in os.listdir(dest_path):
116+
file_path = os.path.join(dest_path, f)
117+
if os.path.isfile(file_path) and f.endswith('.sh'):
118+
subprocess.run(['chmod', '775', file_path])

0 commit comments

Comments
 (0)