Skip to content

Draw keymaps

Draw keymaps #25

Workflow file for this run

name: Draw keymaps
on:
workflow_dispatch: # can be triggered manually
push: # automatically run on changes to following paths
paths:
- "config/*.keymap"
- "config/keymap_drawer.yaml"
- "config/info.json"
env:
km_dr_version: main
km_dr_config: config/keymap_drawer.yaml
keyboard: glove80
output_folder: keymap-drawer
jobs:
draw:
runs-on: ubuntu-latest
steps:
- name: Install keymap-drawer (git) # TODO use actions/setup-python to cacne deps
run: python3 -m pip install "git+https://github.com/caksoylar/keymap-drawer.git@${{ env.km_dr_version }}"
- name: Install PyYaml
run: python3 -m pip install pyyaml
- name: Checkout
uses: actions/checkout@v3
with:
# So the reference to the parent commit is available when amending
# See:
# - https://github.com/stefanzweifel/git-auto-commit-action#using---amend-and---no-edit-as-commit-options
# - https://github.com/stefanzweifel/git-auto-commit-action/issues/159#issuecomment-845347950
# - https://github.com/actions/checkout
fetch-depth: ${{ (inputs.amend_commit == true && 2) || 1 }}
submodules: recursive
# TODO get keyboads & configs dynamically
- name: Parse
run: |
# TODO set generic vars in one place globally
KEYMAP="config/${{ env.keyboard }}.keymap"
CONFIG="${{ env.km_dr_config }}"
OUTPUT="${{ env.output_folder }}/${{ env.keyboard }}.yaml"
keymap -c "$CONFIG" parse -z "$KEYMAP" > "$OUTPUT"
- name: Draw keymap
run: |
KEYMAP="${{ env.output_folder }}/${{ env.keyboard }}.yaml"
INFO="config/info.json"
CONFIG="${{ env.km_dr_config }}"
OUTPUT="${{ env.output_folder }}/${{ env.keyboard }}.svg"
keymap -c "$CONFIG" draw "$KEYMAP" -j "$INFO" > "$OUTPUT"
- name: Draw layer keymap
run: |
# Ensure errors propagate when piping stdout
set -o pipefail
export KEYMAP="${{ env.output_folder }}/${{ env.keyboard }}.yaml"
export INFO="config/info.json"
export CONFIG="${{ env.km_dr_config }}"
# Function to draw the given layer's keymap
draw() {
LAYER="$1"
OUTPUT="${{ env.output_folder }}/${{ env.keyboard }}_${LAYER}.svg"
echo calling keymap for layer $LAYER
keymap -c "$CONFIG" draw "$KEYMAP" -j "$INFO" -s "$LAYER" > "$OUTPUT"
}
export -f draw # Ensure the draw function can be called by `parallel`'s subprocess
# Run `draw()` for each layer in the keymap. Up to 4 layers at a time...
python3 .github/workflows/layers.py "$KEYMAP" \
| parallel --jobs 4 draw
- name: Print # TODO actually commet changes...
run: |
echo "Output Folder is ${{ env.output_folder }}"
echo "Found the folloing files:"
ls "${{ env.output_folder }}"
git status