Draw keymaps #26
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 1 # Set to 2 if amending, or 1 if creating a new commit | |
submodules: recursive | |
# Ensure python packages get cached | |
- name: Setup python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.10 | |
cache: pip | |
- 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 | |
KEYMAP="config/${{ env.keyboard }}.keymap" | |
CONFIG="${{ env.km_dr_config }}" | |
OUTPUT="${{ env.output_folder }}/${{ env.keyboard }}.yaml" | |
echo "Parsing keymap for ${{ env.keyboard }}" | |
keymap -c "$CONFIG" parse -z "$KEYMAP" > "$OUTPUT" | |
- name: Draw keymap for all layers | |
run: | | |
KEYMAP="${{ env.output_folder }}/${{ env.keyboard }}.yaml" | |
INFO="config/info.json" | |
CONFIG="${{ env.km_dr_config }}" | |
OUTPUT="${{ env.output_folder }}/${{ env.keyboard }}.svg" | |
echo "Drawing all layers" | |
keymap -c "$CONFIG" draw "$KEYMAP" -j "$INFO" > "$OUTPUT" | |
- name: Draw seperate layer keymaps | |
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 "Drawing $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... | |
echo "Drawing layers in parallel" | |
python3 .github/workflows/layers.py "$KEYMAP" \ | |
| parallel --jobs 4 draw | |
- name: Commit changes | |
uses: stefanzweifel/git-auto-commit-action@v4 | |
with: | |
commit_message: '[Draw] ${{ github.event.head_commit.message }}' | |
file_pattern: ${{ env.output_folder }}/*.svg ${{ env.output_folder }}/*.yaml | |