Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
add: dispatch to build workflow and using different temp file on buil…
Browse files Browse the repository at this point in the history
…d.py
  • Loading branch information
iruzo committed May 24, 2024
1 parent 58471b5 commit 38169d8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 36 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: "Generate test artifacts"

on:
workflow_dispatch:
pull_request:
types: [opened, reopened, synchronize]

Expand Down
58 changes: 22 additions & 36 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ class Suffix:
IS_DARK = Suffix(true_value="-Dark", test=lambda ctx: ctx.flavor.dark)
IS_LIGHT = Suffix(true_value="-Light", test=lambda ctx: not ctx.flavor.dark)
IS_WINDOW_NORMAL = Suffix(true_value="-Normal", test=lambda ctx: ctx.tweaks.has('normal'))
DARK_LIGHT = Suffix(
true_value="-Dark", false_value="-Light", test=lambda ctx: ctx.flavor.dark
)

DARK_LIGHT = Suffix(true_value="-Dark", false_value="-Light", test=lambda ctx: ctx.flavor.dark)

@dataclass
class BuildContext:
Expand All @@ -63,6 +60,7 @@ class BuildContext:
accent: Color
size: Literal["standard"] | Literal["compact"]
tweaks: Tweaks
temp_tweaks_file: str # Add a temporary tweaks file attribute

def output_dir(self) -> str:
return f"{self.build_root}/{self.build_id()}"
Expand Down Expand Up @@ -165,16 +163,6 @@ def build(ctx: BuildContext):
f"{SRC_DIR}/main/metacity-1/metacity-theme-3{ctx.apply_suffix(IS_WINDOW_NORMAL)}.xml",
f"{output_dir}/metacity-1/metacity-theme-3.xml",
)
# FIXME: Symlinks aren't working as intended
# FIXME: Do we need them?
# os.symlink(
# f"{output_dir}/metacity-1/metacity-theme-3.xml",
# f"{output_dir}/metacity-1/metacity-theme-2.xml",
# )
# os.symlink(
# f"{output_dir}/metacity-1/metacity-theme-3.xml",
# f"{output_dir}/metacity-1/metacity-theme-1.xml",
# )

os.makedirs(f"{output_dir}/xfwm4", exist_ok=True)
shutil.copyfile(
Expand Down Expand Up @@ -207,10 +195,8 @@ def build(ctx: BuildContext):
f"{SRC_DIR}/main/plank/theme-Dark-Catppuccin/", f"{output_dir}/plank"
)


def init_tweaks_temp():
shutil.copyfile(f"{SRC_DIR}/sass/_tweaks.scss", f"{SRC_DIR}/sass/_tweaks-temp.scss")

def init_tweaks_temp(temp_file):
shutil.copyfile(f"{SRC_DIR}/sass/_tweaks.scss", temp_file)

def subst_text(path, _from, to):
with open(path, "r+") as f:
Expand All @@ -223,20 +209,20 @@ def subst_text(path, _from, to):
GS_VERSION = "46-0"


def gnome_shell_version():
def gnome_shell_version(temp_file):
shutil.copyfile(
f"{SRC_DIR}/sass/gnome-shell/_common.scss",
f"{SRC_DIR}/sass/gnome-shell/_common-temp.scss",
temp_file,
)
subst_text(
f"{SRC_DIR}/sass/gnome-shell/_common-temp.scss",
temp_file,
"@import 'widgets-40-0';",
f"@import 'widgets-{GS_VERSION}';",
)

if GS_VERSION == "3-28":
subst_text(
f"{SRC_DIR}/sass/gnome-shell/_common-temp.scss",
temp_file,
"@import 'extensions-40-0';",
f"@import 'extensions-{GS_VERSION}';",
)
Expand Down Expand Up @@ -265,37 +251,36 @@ def translate_accent(ctp_accent: Color):
return ctp_to_colloid[ctp_accent.identifier]


def write_tweak(key, default, value):
def write_tweak(key, default, value, temp_file):
subst_text(
f"{SRC_DIR}/sass/_tweaks-temp.scss", f"\\${key}: {default}", f"${key}: {value}"
temp_file, f"\\${key}: {default}", f"${key}: {value}"
)


def apply_tweaks(ctx: BuildContext):
write_tweak("theme", "'default'", f"'{translate_accent(ctx.accent)}'")
write_tweak("theme", "'default'", f"'{translate_accent(ctx.accent)}'", ctx.temp_tweaks_file)

if ctx.size == "compact":
write_tweak("compact", "'false'", "'true'")
write_tweak("compact", "'false'", "'true'", ctx.temp_tweaks_file)

subst_text(
f"{SRC_DIR}/sass/_tweaks-temp.scss",
ctx.temp_tweaks_file,
"@import 'color-palette-default';",
f"@import 'color-palette-catppuccin-{ctx.flavor.identifier}';",
)
write_tweak("colorscheme", "'default'", "'catppuccin'")
write_tweak("colorscheme", "'default'", "'catppuccin'", ctx.temp_tweaks_file)

if ctx.tweaks.has("black"):
write_tweak("blackness", "'false'", "'true'")
write_tweak("blackness", "'false'", "'true'", ctx.temp_tweaks_file)

if ctx.tweaks.has("rimless"):
write_tweak("rimless", "'false'", "'true'")
write_tweak("rimless", "'false'", "'true'", ctx.temp_tweaks_file)

if ctx.tweaks.has("normal"):
write_tweak("window_button", "'mac'", "'normal'")
write_tweak("window_button", "'mac'", "'normal'", ctx.temp_tweaks_file)

if ctx.tweaks.has("float"):
write_tweak("float", "'false'", "'true'")

write_tweak("float", "'false'", "'true'", ctx.temp_tweaks_file)

def make_assets(ctx: BuildContext):
output_dir = ctx.output_dir()
Expand Down Expand Up @@ -482,7 +467,6 @@ def apply_colloid_patches():
return

logger.info("Applying patches...")
# Change into colloid
for patch in [
"plank-dark.patch",
"plank-light.patch",
Expand Down Expand Up @@ -601,6 +585,7 @@ def parse_args():


def process_accent(args, palette, accent):
temp_file = f"{SRC_DIR}/sass/_tweaks-temp-{accent.identifier}.scss"
tweaks = Tweaks(tweaks=args.tweaks)

if args.zip:
Expand All @@ -616,12 +601,13 @@ def process_accent(args, palette, accent):
size=args.size,
tweaks=tweaks,
output_format=output_format,
temp_tweaks_file=temp_file, # Pass the temporary file to context
)

logger.info("Building temp tweaks file")
init_tweaks_temp()
init_tweaks_temp(temp_file)
logger.info("Inserting gnome-shell imports")
gnome_shell_version()
gnome_shell_version(temp_file)
logger.info("Building main theme")
build_theme(ctx)
logger.info(f"Completed {palette.identifier} with {accent.identifier}")
Expand Down

0 comments on commit 38169d8

Please sign in to comment.