From 94983b69810abaf3a79b8fa3e7af02b98d7f560f Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sat, 11 May 2024 03:37:07 +0300 Subject: [PATCH] generate json schemes in CI --- .github/workflows/convert-schemes.yaml | 94 ++++++++++++++++++++++++++ flake.nix | 28 +------- 2 files changed, 95 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/convert-schemes.yaml diff --git a/.github/workflows/convert-schemes.yaml b/.github/workflows/convert-schemes.yaml new file mode 100644 index 0000000..5ddc95f --- /dev/null +++ b/.github/workflows/convert-schemes.yaml @@ -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 }} diff --git a/flake.nix b/flake.nix index cc08a60..82f28c8 100644 --- a/flake.nix +++ b/flake.nix @@ -13,37 +13,11 @@ outputs = inputs @ {flake-parts, ...}: flake-parts.lib.mkFlake {inherit inputs;} { systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"]; - perSystem = { - 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. + perSystem = {pkgs, ...}: { # Example if we could make it a list: # builtins.mapAttrs (_: p: builtins.fromJSON (builtins.readFile p)) (import ./list.nix) packages = { 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 - ''; }; }; };