mirror of
https://github.com/NotAShelf/Basix.git
synced 2024-11-01 08:41:14 +00:00
generate json schemes in CI
This commit is contained in:
parent
e5a0d512ea
commit
94983b6981
2 changed files with 95 additions and 27 deletions
94
.github/workflows/convert-schemes.yaml
vendored
Normal file
94
.github/workflows/convert-schemes.yaml
vendored
Normal 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 }}
|
28
flake.nix
28
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
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue