forked from caksoylar/keymap-drawer
-
Notifications
You must be signed in to change notification settings - Fork 0
128 lines (116 loc) · 5.34 KB
/
draw-zmk.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# Reusable workflow for drawing and committing an automated keymap diagram
# for ZMK config repos using https://github.com/caksoylar/keymap-drawer
name: Draw ZMK keymaps
on:
workflow_call:
inputs:
keymap_patterns:
description: "Path specification for keymaps to be parsed"
default: "config/*.keymap"
required: false
type: string
config_path:
description: "Path to the keymap-drawer configuration file, ignored if non-existent"
default: "keymap_drawer.config.yaml"
required: false
type: string
output_folder:
description: "Output folder for SVG and YAML files"
default: "keymap-drawer"
required: false
type: string
parse_args:
description: "Map of keyboard names to extra `keymap parse` args, e.g. `corne:'--layer-names Def Lwr Rse Fun'`"
default: ""
required: false
type: string
draw_args:
description: "Map of keyboard names to extra `keymap draw` args, e.g. `corne:'-k corne_rotated -l LAYOUT_split_3x5_3'`"
default: ""
required: false
type: string
commit_message:
description: "Commit message for updated images. Ignored if `amend_commit` is `true`."
default: "keymap-drawer render"
required: false
type: string
amend_commit:
description: "Whether to amend the last commit instead of creating a new one. Make sure you understand the implications of rewriting the branch history if you use this option!"
default: false
required: false
type: boolean
install_branch:
description: "Install keymap-drawer from a git branch, use empty for pypi release (default)"
default: ""
required: false
type: string
jobs:
draw:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
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
- name: Install keymap-drawer (pypi)
if: inputs.install_branch == ''
run: python3 -m pip install keymap-drawer
- name: Install keymap-drawer (git)
if: inputs.install_branch != ''
run: python3 -m pip install "git+https://github.com/caksoylar/keymap-drawer.git@${{ inputs.install_branch }}"
- name: Draw keymaps
run: |
get_args() {
local keyboard=$2
eval set -- "$1"
for arg; do
local key=${arg%%:*}
local val=${arg#*:}
if [ "$key" = "$keyboard" ]; then
echo "$val"
break
fi
done
}
mkdir -p "${{ inputs.output_folder }}"
config_path="${{ inputs.config_path }}"
[ -e "$config_path" ] && config_arg=(-c "$config_path") || config_arg=()
for keymap_file in ${{ inputs.keymap_patterns }}; do
keyboard=$(basename -s .keymap "$keymap_file")
echo "INFO: drawing for $keyboard"
parse_args=$(get_args "${{ inputs.parse_args }}" "$keyboard")
echo "INFO: got extra parse args: $parse_args"
draw_args=$(get_args "${{ inputs.draw_args }}" "$keyboard")
echo "INFO: got extra draw args: $draw_args"
if [ -f "config/${keyboard}.json" ]; then
echo "INFO: found config/${keyboard}.json";
draw_args+=" -j config/${keyboard}.json"
fi
keymap "${config_arg[@]}" parse -z "$keymap_file" $parse_args >"${{ inputs.output_folder }}/$keyboard.yaml" \
&& keymap "${config_arg[@]}" draw "${{ inputs.output_folder }}/$keyboard.yaml" $draw_args >"${{ inputs.output_folder }}/$keyboard.svg" \
|| echo "ERROR: parsing or drawing failed for $keyboard!"
done
- name: Get last commit message
id: last_commit_message
if: inputs.amend_commit == true
run: |
echo "msg=$(git log -1 --pretty=%s)" >> $GITHUB_OUTPUT
- name: Commit updated images
uses: stefanzweifel/git-auto-commit-action@v5
with:
file_pattern: "${{ inputs.output_folder }}/*.svg ${{ inputs.output_folder }}/*.yaml"
# So the previous commit is amended instead of creating a new one when desired
# 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
commit_message: "${{ (inputs.amend_commit == true && steps.last_commit_message.outputs.msg) || inputs.commit_message }}"
commit_options: "${{ (inputs.amend_commit == true && '--amend --no-edit') || '' }}"
push_options: "${{ (inputs.amend_commit == true && '--force-with-lease') || '' }}"
skip_fetch: ${{ inputs.amend_commit == true }}