chore: Update create-theme workflow to include author information and image in theme submission

This commit is contained in:
Mauro Balades 2024-08-16 00:24:14 +02:00
parent 20922c7873
commit 367a302e9f
3 changed files with 30 additions and 4 deletions

View file

@ -24,9 +24,13 @@ body:
attributes: attributes:
label: Homepage label: Homepage
description: The URL of the theme's homepage or repository. description: The URL of the theme's homepage or repository.
placeholder: Theme Homepage placeholder: https://github.com/...
validations: - type: input
required: true id: image
attributes:
label: Image
description: "A URL to an image representing the theme. It can be a temporary image, it will be cloned to the theme library. Note: The image must be a PNG file. E.g. an imgur link."
placeholder: https://...
- type: textarea - type: textarea
id: styles id: styles
attributes: attributes:

View file

@ -31,6 +31,7 @@ jobs:
echo "THEME_NAME=${{ fromJson(steps.issue-parser.outputs.jsonString)['name'] }}" >> $GITHUB_ENV echo "THEME_NAME=${{ fromJson(steps.issue-parser.outputs.jsonString)['name'] }}" >> $GITHUB_ENV
echo "THEME_DESCRIPTION=${{ fromJson(steps.issue-parser.outputs.jsonString)['description'] }}" >> $GITHUB_ENV echo "THEME_DESCRIPTION=${{ fromJson(steps.issue-parser.outputs.jsonString)['description'] }}" >> $GITHUB_ENV
echo "THEME_HOMEPAGE=${{ fromJson(steps.issue-parser.outputs.jsonString)['homepage'] }}" >> $GITHUB_ENV echo "THEME_HOMEPAGE=${{ fromJson(steps.issue-parser.outputs.jsonString)['homepage'] }}" >> $GITHUB_ENV
echo "THEME_IMAGE=${{ fromJson(steps.issue-parser.outputs.jsonString)['image'] }}" >> $GITHUB_ENV
echo "THEME_AUTHOR=${{ github.event.issue.user.login }}" >> $GITHUB_ENV echo "THEME_AUTHOR=${{ github.event.issue.user.login }}" >> $GITHUB_ENV
- name: Write styles to file - name: Write styles to file
@ -56,6 +57,7 @@ jobs:
--name "${{ env.THEME_NAME }}" \ --name "${{ env.THEME_NAME }}" \
--description "${{ env.THEME_DESCRIPTION }}" \ --description "${{ env.THEME_DESCRIPTION }}" \
--author "${{ env.THEME_AUTHOR }}" \ --author "${{ env.THEME_AUTHOR }}" \
--image "${{ env.THEME_IMAGE }}" \
--homepage "${{ env.THEME_HOMEPAGE }}" 2> error.log --homepage "${{ env.THEME_HOMEPAGE }}" 2> error.log
- name: Export creation output - name: Export creation output
@ -103,7 +105,7 @@ jobs:
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
comment: | comment: |
# Thank you for your contribution! # Thank you for your contribution! :tada:
Your theme has been successfully submitted. The maintainers will review it and get back to you soon. Your theme has been successfully submitted. The maintainers will review it and get back to you soon.

View file

@ -4,9 +4,12 @@ import argparse
import json import json
import uuid import uuid
import sys import sys
import requests
import imghdr
STYLES_FILE = "chrome.css" STYLES_FILE = "chrome.css"
README_FILE = "readme.md" README_FILE = "readme.md"
IMAGE_FILE = "image.png"
TEMPLATE_STYLES_FILE = "./theme-styles.css" TEMPLATE_STYLES_FILE = "./theme-styles.css"
TEMPLATE_README_FILE = "./theme-readme.md" TEMPLATE_README_FILE = "./theme-readme.md"
@ -51,18 +54,32 @@ def validate_description(description):
print("Description must be less than 100 characters.", file=sys.stderr) print("Description must be less than 100 characters.", file=sys.stderr)
exit(1) exit(1)
def download_image(image_url, image_path):
response = requests.get(image_url)
if response.status_code != 200:
print("Image URL is invalid.", file=sys.stderr)
exit(1)
with open(image_path, 'wb') as f:
f.write(response.content)
# Check if the image is valid and a PNG
if imghdr.what(image_path) != 'png':
print("Image must be a PNG.", file=sys.stderr)
exit(1)
def main(): def main():
parser = argparse.ArgumentParser(description='Submit a theme to the theme repo.') parser = argparse.ArgumentParser(description='Submit a theme to the theme repo.')
parser.add_argument('--name', type=str, help='The theme to submit.') parser.add_argument('--name', type=str, help='The theme to submit.')
parser.add_argument('--description', type=str, help='The description of the theme.') parser.add_argument('--description', type=str, help='The description of the theme.')
parser.add_argument('--homepage', type=str, help='The homepage of the theme.') parser.add_argument('--homepage', type=str, help='The homepage of the theme.')
parser.add_argument('--author', type=str, help='The author of the theme.') parser.add_argument('--author', type=str, help='The author of the theme.')
parser.add_argument('--image', type=str, help='The image of the theme.')
args = parser.parse_args() args = parser.parse_args()
name = args.name name = args.name
description = args.description description = args.description
homepage = args.homepage homepage = args.homepage
author = args.author author = args.author
image = args.image
validate_name(name) validate_name(name)
validate_description(description) validate_description(description)
@ -85,6 +102,7 @@ Just joking, you can do whatever you want. You're the boss.
'homepage': homepage, 'homepage': homepage,
'style': get_static_asset(theme_id, STYLES_FILE), 'style': get_static_asset(theme_id, STYLES_FILE),
'readme': get_static_asset(theme_id, README_FILE), 'readme': get_static_asset(theme_id, README_FILE),
'image': get_static_asset(theme_id, IMAGE_FILE),
'author': author 'author': author
} }
@ -98,6 +116,8 @@ 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())
download_image(image, f"themes/{theme_id}/{IMAGE_FILE}")
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}")