Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate keymap-drawer into flake #9

Merged
merged 5 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Install nix
uses: DeterminateSystems/nix-installer-action@main
uses: cachix/install-nix-action@v25
- name: Setup nix cache
uses: DeterminateSystems/magic-nix-cache-action@main
- name: Build Glove80 firmware
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Install nix
uses: DeterminateSystems/nix-installer-action@main
uses: cachix/install-nix-action@v25
- name: Setup nix cache
uses: DeterminateSystems/magic-nix-cache-action@main
- name: Run flake checker
Expand Down
79 changes: 12 additions & 67 deletions .github/workflows/draw-keymaps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ on:
push: # automatically run on changes to following paths
paths:
- "**.lock"
- "drawer/**"
- "config/**"
env:
km_dr_version: main
km_dr_config: config/keymap_drawer.yaml
keymap_path: config/*.keymap
output_folder: img

jobs:
draw:
Expand All @@ -21,75 +17,24 @@ jobs:
steps:

- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 1 # Set to 2 if amending, or 1 if creating a new commit
# Set to 2 if amending, or 1 if creating a new commit
fetch-depth: 1
submodules: recursive

- name: Install python dependencies
run: |
pip install "git+https://github.com/caksoylar/keymap-drawer.git@${{ env.km_dr_version }}"
pip install pyyaml
- name: Install nix
uses: cachix/install-nix-action@v25
- name: Setup nix cache
uses: DeterminateSystems/magic-nix-cache-action@main

# TODO get keyboads & configs dynamically
- name: Parse keymap
run: |
# TODO set generic vars in one place globally
CONFIG="${{ env.km_dr_config }}"

for KEYMAP in ${{ env.keymap_path }}; do
KEYBOARD=$(basename -s .keymap "$KEYMAP")
OUTPUT="${{ env.output_folder }}/${KEYBOARD}.yaml"

# TODO consider running through `parallel`?
echo "Parsing keymap for $KEYBOARD"
keymap -c "$CONFIG" parse -z "$KEYMAP" > "$OUTPUT"
done

- name: Draw keymap for all layers
run: |
CONFIG="${{ env.km_dr_config }}"

# FIXME can glob false positeves, e.g. previous keymaps
for KEYMAP in ${{ env.output_folder }}/*.yaml; do
KEYBOARD=$(basename -s .yaml "$KEYMAP")
OUTPUT="${{ env.output_folder }}/${KEYBOARD}.svg"

echo "Drawing all layers for $KEYBOARD"
keymap -c "$CONFIG" draw "$KEYMAP" > "$OUTPUT"
done


- name: Draw seperate layer keymaps
run: |
# Ensure errors propagate when piping stdout
set -o pipefail

export CONFIG="${{ env.km_dr_config }}"

# Function to draw the given layer's keymap
draw() {
KEYMAP="$1"
LAYER="$2"
KEYBOARD=$(basename -s .yaml "$KEYMAP")
OUTPUT="${{ env.output_folder }}/${KEYBOARD}_${LAYER}.svg"

echo "Drawing $LAYER layer for $KEYBOARD"
keymap -c "$CONFIG" draw "$KEYMAP" -s "$LAYER" > "$OUTPUT"
}
export -f draw # Ensure the draw function can be called by `parallel`'s subprocess

# FIXME can glob false positeves, e.g. previous keymaps
for KEYMAP in ${{ env.output_folder }}/*.yaml; do
# Run `draw()` for each layer in the keymap. Up to 4 layers at a time...
echo "Drawing layers in parallel"
python3 .github/workflows/layers.py "$KEYMAP" \
| parallel --jobs 4 draw "$KEYMAP"
done
- name: Draw keymaps
run: nix run . -- draw

# TODO print to $GITHUB_STEP_SUMMARY
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "[Draw] ${{ github.event.head_commit.message || '(Manually triggered)' }}"
file_pattern: ${{ env.output_folder }}/*.svg ${{ env.output_folder }}/*.yaml
file_pattern: img/**

16 changes: 0 additions & 16 deletions .github/workflows/layers.py

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main
uses: cachix/install-nix-action@v25
- name: Update flake.lock
id: update
uses: DeterminateSystems/update-flake-lock@main
Expand Down
66 changes: 66 additions & 0 deletions drawer/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
inputs,
lib,
...
}: let
in {
perSystem = {
config,
pkgs,
system,
...
}: let
inherit (inputs.poetry2nix.lib.mkPoetry2Nix {inherit pkgs;}) mkPoetryApplication;

exe = lib.getExe config.packages.keymap-drawer;
yq = lib.getExe pkgs.yq-go;
in {
packages = {
keymap-drawer = mkPoetryApplication {
projectDir = inputs.keymap-drawer;
preferWheels = true;
meta = {
mainProgram = "keymap";
homepage = "https://github.com/caksoylar/keymap-drawer";
};
};
};

devshells.default.commands = [
{
name = "draw";
command = /*bash*/ ''
set +e

out="$PRJ_ROOT"/img
keymap_dir="$PRJ_ROOT"/config
cmd="${exe} --config $keymap_dir/keymap_drawer.yaml"

echo "Removing previous images"
rm "$out"/*

for file in "$keymap_dir"/*.keymap
do
name="$(basename --suffix=".keymap" "$file")"
config="$out/$name.yaml"
echo "Found $name keymap"

echo "- Parsing keymap-drawer"
$cmd parse --zmk-keymap "$file" > "$config"

echo "- Drawing all layers"
$cmd draw "$config" > "$out"/"$name".svg

layers=$(${yq} '.layers | keys | .[]' "$config")
for layer in $layers
do
echo "- Drawing $layer layer"
$cmd draw "$config" --select-layers "$layer" > "$out"/"$name"_"$layer".svg
done
done
'';
help = "Draw SVG images of the keymap";
}
];
};
}
133 changes: 132 additions & 1 deletion flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading