Skip to content

Commit

Permalink
refactor(ci): use flake to build SVGs
Browse files Browse the repository at this point in the history
  • Loading branch information
MattSturgeon committed Mar 26, 2024
1 parent 9550b3c commit d5dc20f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 77 deletions.
71 changes: 10 additions & 61 deletions .github/workflows/draw-keymaps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,72 +21,21 @@ 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:
Expand Down
16 changes: 0 additions & 16 deletions .github/workflows/layers.py

This file was deleted.

16 changes: 16 additions & 0 deletions drawer/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
}: let
in {
perSystem = {
config,
pkgs,
system,
...
}: let
inherit (inputs.poetry2nix.lib.mkPoetry2Nix {inherit pkgs;}) mkPoetryApplication;
exe = lib.getExe config.packages.keymap-drawer;
in {
packages = {
keymap-drawer = mkPoetryApplication {
Expand All @@ -21,4 +23,18 @@ in {
};
};
};

devshells.default.commands = [
{
name = "draw";
command = /*bash*/ ''
set +e
echo "Running draw command"
${exe} --help
'';
help = "Draw SVG images of the keymap";
}
];
};
}

0 comments on commit d5dc20f

Please sign in to comment.