mirror of
https://github.com/zen-browser/theme-store.git
synced 2025-07-07 17:05:31 +02:00
chore: Add preferences support to create-theme workflow
This commit is contained in:
parent
08316fba81
commit
34c19e2524
3 changed files with 65 additions and 3 deletions
13
.github/ISSUE_TEMPLATE/create-theme.yml
vendored
13
.github/ISSUE_TEMPLATE/create-theme.yml
vendored
|
@ -51,4 +51,15 @@ body:
|
||||||
label: Readme
|
label: Readme
|
||||||
description: The README file for the theme.
|
description: The README file for the theme.
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: preferences
|
||||||
|
attributes:
|
||||||
|
render: json
|
||||||
|
label: Preferences
|
||||||
|
description: The preferences for the theme in JSON format. Leave empty if there are no preferences.
|
||||||
|
placeholder: |
|
||||||
|
{
|
||||||
|
"uc.my-preference.enable-this": "Enable this feature for the theme",
|
||||||
|
"uc.my-preference.show-that": "Show that feature for the theme"
|
||||||
|
}
|
6
.github/workflows/create-theme.yml
vendored
6
.github/workflows/create-theme.yml
vendored
|
@ -46,6 +46,12 @@ jobs:
|
||||||
contents: ${{ fromJson(steps.issue-parser.outputs.jsonString)['readme'] }}
|
contents: ${{ fromJson(steps.issue-parser.outputs.jsonString)['readme'] }}
|
||||||
path: theme-readme.md
|
path: theme-readme.md
|
||||||
|
|
||||||
|
- name: Write preferences to file
|
||||||
|
uses: "DamianReeves/write-file-action@master"
|
||||||
|
with:
|
||||||
|
contents: ${{ fromJson(steps.issue-parser.outputs.jsonString)['preferences'] }}
|
||||||
|
path: theme-preferences.json
|
||||||
|
|
||||||
- name: Setup Git
|
- name: Setup Git
|
||||||
run: |
|
run: |
|
||||||
git config --global user.name "github-actions[bot]"
|
git config --global user.name "github-actions[bot]"
|
||||||
|
|
|
@ -10,9 +10,11 @@ import imghdr
|
||||||
STYLES_FILE = "chrome.css"
|
STYLES_FILE = "chrome.css"
|
||||||
README_FILE = "readme.md"
|
README_FILE = "readme.md"
|
||||||
IMAGE_FILE = "image.png"
|
IMAGE_FILE = "image.png"
|
||||||
|
PREFERENCES_FILE = "preferences.json"
|
||||||
|
|
||||||
TEMPLATE_STYLES_FILE = "./theme-styles.css"
|
TEMPLATE_STYLES_FILE = "./theme-styles.css"
|
||||||
TEMPLATE_README_FILE = "./theme-readme.md"
|
TEMPLATE_README_FILE = "./theme-readme.md"
|
||||||
|
TEMPLATE_PREFERENCES_FILE = "./theme-preferences.json"
|
||||||
|
|
||||||
def create_theme_id():
|
def create_theme_id():
|
||||||
return str(uuid.uuid4())
|
return str(uuid.uuid4())
|
||||||
|
@ -33,6 +35,40 @@ def get_readme():
|
||||||
content = content[len("```markdown"):]
|
content = content[len("```markdown"):]
|
||||||
content = content[:-len("```")]
|
content = content[:-len("```")]
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
def validate_preferences(preferences):
|
||||||
|
for key, value in preferences.items():
|
||||||
|
if not isinstance(key, str):
|
||||||
|
print("Preference key must be a string.", file=sys.stderr)
|
||||||
|
exit(1)
|
||||||
|
if not isinstance(value, str):
|
||||||
|
print("Preference description must be a string.", file=sys.stderr)
|
||||||
|
exit(1)
|
||||||
|
if len(key) == 0:
|
||||||
|
print("Preference key is required.", file=sys.stderr)
|
||||||
|
exit(1)
|
||||||
|
for char in key:
|
||||||
|
if not char.isalnum() and char != '.' and char != '-' and char != '_':
|
||||||
|
print("Preference key must only contain letters, numbers, periods, dashes, and underscores.", file=sys.stderr)
|
||||||
|
exit(1)
|
||||||
|
if len(value) == 0:
|
||||||
|
print("Preference description is required.", file=sys.stderr)
|
||||||
|
exit(1)
|
||||||
|
return preferences
|
||||||
|
|
||||||
|
def get_preferences():
|
||||||
|
with open(TEMPLATE_PREFERENCES_FILE, 'r') as f:
|
||||||
|
try:
|
||||||
|
content = f.read()
|
||||||
|
if content.strip() == "":
|
||||||
|
return {}
|
||||||
|
content = content[len("```json"):]
|
||||||
|
content = content[:-len("```")]
|
||||||
|
return validate_preferences(json.loads(content))
|
||||||
|
except json.JSONDecodeError as e:
|
||||||
|
print("Preferences file is invalid.", file=sys.stderr)
|
||||||
|
print(e, file=sys.stderr)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
def validate_name(name):
|
def validate_name(name):
|
||||||
if len(name) == 0:
|
if len(name) == 0:
|
||||||
|
@ -107,8 +143,6 @@ Just joking, you can do whatever you want. You're the boss.
|
||||||
}
|
}
|
||||||
|
|
||||||
os.makedirs(f"themes/{theme_id}")
|
os.makedirs(f"themes/{theme_id}")
|
||||||
with open(f"themes/{theme_id}/theme.json", 'w') as f:
|
|
||||||
json.dump(theme, f)
|
|
||||||
|
|
||||||
with open(f"themes/{theme_id}/{STYLES_FILE}", 'w') as f:
|
with open(f"themes/{theme_id}/{STYLES_FILE}", 'w') as f:
|
||||||
f.write(get_styles())
|
f.write(get_styles())
|
||||||
|
@ -116,8 +150,19 @@ Just joking, you can do whatever you want. You're the boss.
|
||||||
with open(f"themes/{theme_id}/{README_FILE}", 'w') as f:
|
with open(f"themes/{theme_id}/{README_FILE}", 'w') as f:
|
||||||
f.write(get_readme())
|
f.write(get_readme())
|
||||||
|
|
||||||
|
with open(f"themes/{theme_id}/{PREFERENCES_FILE}", 'w') as f:
|
||||||
|
prefs = get_preferences()
|
||||||
|
if len(prefs) > 0:
|
||||||
|
print("Detected preferences file. Please review the preferences below.")
|
||||||
|
print(prefs)
|
||||||
|
theme['preferences'] = get_static_asset(theme_id, PREFERENCES_FILE)
|
||||||
|
json.dump(prefs, f)
|
||||||
|
|
||||||
download_image(image, f"themes/{theme_id}/{IMAGE_FILE}")
|
download_image(image, f"themes/{theme_id}/{IMAGE_FILE}")
|
||||||
|
|
||||||
|
with open(f"themes/{theme_id}/theme.json", 'w') as f:
|
||||||
|
json.dump(theme, f)
|
||||||
|
|
||||||
print(f"Theme submitted with ID: {theme_id}")
|
print(f"Theme submitted with ID: {theme_id}")
|
||||||
for key, value in theme.items():
|
for key, value in theme.items():
|
||||||
print(f"\t{key}: {value}")
|
print(f"\t{key}: {value}")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue