generate json schemes in CI

This commit is contained in:
raf 2024-05-11 03:37:07 +03:00
parent e5a0d512ea
commit 94983b6981
No known key found for this signature in database
GPG key ID: 02D1DD3FA08B6B29
2 changed files with 95 additions and 27 deletions

94
.github/workflows/convert-schemes.yaml vendored Normal file
View file

@ -0,0 +1,94 @@
name: Convert YAML to JSON
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
nix:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: "Checkout"
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: "Install nix"
uses: cachix/install-nix-action@master
with:
install_url: https://nixos.org/nix/install
extra_nix_config: |
experimental-features = nix-command flakes
allow-import-from-derivation = false
- name: "Nix Magic Cache"
uses: DeterminateSystems/magic-nix-cache-action@main
- name: Run conversion script
run: |
tmpdir=$(mktemp -d)
if [ -d "$tmpdir" ]; then
echo "Cloning original schemes directory"
git clone https://github.com/tinted-theming/schemes.git "$tmpdir"/yaml
else
echo "Failed to create temp directory" >&2
exit 1
fi
yaml_dir_base16="$tmpdir"/yaml/base16
yaml_dir_base24="$tmpdir"/yaml/base24
json_dir_base16="$tmpdir"/json/base16
json_dir_base24="$tmpdir"/json/base24
# ensure JSON directories exist
mkdir -p "$json_dir_base16"
mkdir -p "$json_dir_base24"
# convert YAML to JSON
convert_yaml_to_json() {
echo "Converting"
local yaml_file="$1"
local json_file="$2"
nix run --builders "" --substituters "https://cache.nixos.org" .#convert-scheme -- "$yaml_file" "$json_file"
}
# convert YAML files in base16 directory
for yaml_file in "$yaml_dir_base16"/*.yaml; do
base_name=$(basename "$yaml_file" .yaml)
convert_yaml_to_json "$yaml_file" "$json_dir_base16/$base_name.json"
done
# convert YAML files in base24 directory
for yaml_file in "$yaml_dir_base24"/*.yaml; do
base_name=$(basename "$yaml_file" .yaml)
convert_yaml_to_json "$yaml_file" "$json_dir_base24/$base_name.json"
done
# move converted JSON files to current directory
mkdir -p json/{base16,base24}
mv "$json_dir_base16"/*.json json/base16
mv "$json_dir_base24"/*.json json/base24
# Cleanup
rm -rf "$tmpdir"
- name: Commit files
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add *.json
git commit -m "CI: update JSON schemes" || echo "No changes to commit"
- name: Push changes
if: success()
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

View file

@ -13,37 +13,11 @@
outputs = inputs @ {flake-parts, ...}: outputs = inputs @ {flake-parts, ...}:
flake-parts.lib.mkFlake {inherit inputs;} { flake-parts.lib.mkFlake {inherit inputs;} {
systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"]; systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"];
perSystem = { perSystem = {pkgs, ...}: {
self',
config,
pkgs,
lib,
...
}: let
inherit (builtins) filter map toString;
inherit (lib.filesystem) listFilesRecursive;
inherit (lib.strings) hasSuffix concatStringsSep;
listAllSchemes = path: filter (hasSuffix ".yaml") (map toString (listFilesRecursive path));
in {
# for some fucking reason all tinted-theming themes are in yaml. you know what's wrong with that?
# fromJSON cannot read it! That iss because yaml is a stupid fucking format and nobody should use it
# But since the idiots at tinted-theming decided to use it (of course they would) we have to read each
# yaml file and then convert it to JSON. Why? so that we can FUCKING PARSE IT.
# FIXME: this actually does nothing. Because listFilesRecursive simply returns a list of strings.
# We would like to organize each theme in a {name = "path"} format so that we can parse the output
# e.g. from a list and expose each palette as an attribute set.
# Example if we could make it a list: # Example if we could make it a list:
# builtins.mapAttrs (_: p: builtins.fromJSON (builtins.readFile p)) (import ./list.nix) # builtins.mapAttrs (_: p: builtins.fromJSON (builtins.readFile p)) (import ./list.nix)
packages = { packages = {
convert-scheme = pkgs.callPackage ./packages/convert-scheme/package.nix {}; convert-scheme = pkgs.callPackage ./packages/convert-scheme/package.nix {};
convert-all-schemes = pkgs.runCommandLocal "convert-all-schemes" {} ''
mkdir $out
for scheme in ${concatStringsSep " " (listAllSchemes inputs.schemes)}
do
${self'.packages.convert-scheme + /bin/convert-scheme} "$scheme" ${placeholder "out"}/"$scheme"
done
'';
}; };
}; };
}; };