Skip to content

Test some thumb combos #40

Test some thumb combos

Test some thumb combos #40

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
keymap_path: config/*.keymap
output_folder: img
jobs:
draw:
runs-on: ubuntu-latest
permissions:
contents: write # Allow CI to write commits to the repo
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 1 # Set to 2 if amending, or 1 if creating a new commit
submodules: recursive
- name: Install python dependencies
run: |
pip install "git+https://github.com/caksoylar/keymap-drawer.git@${{ env.km_dr_version }}"
pip install pyyaml
# 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: 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