Add qmk ci-validate-aliases (#22205)

This commit is contained in:
Nick Brassel 2023-10-06 10:34:23 +11:00 committed by GitHub
parent 92873cc14f
commit 127560ae22
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 97 additions and 55 deletions

View file

@ -74,31 +74,10 @@ jobs:
fi fi
exit $exit_code exit $exit_code
- name: Verify at most one added keyboard - name: Verify keyboard aliases
if: always() if: always()
shell: 'bash {0}' shell: 'bash {0}'
run: | run: |
git reset --hard git reset --hard
git clean -xfd git clean -xfd
qmk ci-validate-aliases
# Get the keyboard list and count for the target branch
git checkout -f ${{ github.base_ref }}
git pull --ff-only
QMK_KEYBOARDS_BASE=$(qmk list-keyboards)
QMK_KEYBOARDS_BASE_COUNT=$(qmk list-keyboards | wc -l)
# Get the keyboard list and count for the PR
git checkout -f ${{ github.head_ref }}
git merge --no-commit --squash ${{ github.base_ref }}
QMK_KEYBOARDS_PR=$(qmk list-keyboards)
QMK_KEYBOARDS_PR_COUNT=$(qmk list-keyboards | wc -l)
echo "::group::Keyboards changes in this PR"
diff -d -U 0 <(echo "$QMK_KEYBOARDS_BASE") <(echo "$QMK_KEYBOARDS_PR") | grep -vE '^(---|\+\+\+|@@)' | sed -e 's@^-@Removed: @g' -e 's@^+@ Added: @g'
echo "::endgroup::"
if [[ $QMK_KEYBOARDS_PR_COUNT -gt $(($QMK_KEYBOARDS_BASE_COUNT + 1)) ]]; then
echo "More than one keyboard added in this PR -- see the PR Checklist."
echo "::error::More than one keyboard added in this PR -- see the PR Checklist."
exit 1
fi

View file

@ -4,6 +4,13 @@
// "target": "<keyboard_folder>" // "target": "<keyboard_folder>"
// } // }
// //
/* This list of aliases is for testing purposes -- ensures "linked list" recursive traversal works correctly. */
"_test_a": { "target": "_test_b" },
"_test_b": { "target": "_test_c" },
"_test_c": { "target": "planck/rev6" },
/* The main list of aliases for moved keyboards within QMK. */
"2_milk": { "2_milk": {
"target": "spaceman/2_milk" "target": "spaceman/2_milk"
}, },
@ -35,7 +42,7 @@
"target": "amjkeyboard/amjpad" "target": "amjkeyboard/amjpad"
}, },
"angel64": { "angel64": {
"target": "angel64/alpha" "target": "kakunpc/angel64/alpha"
}, },
"ashpil/modelm_usbc": { "ashpil/modelm_usbc": {
"target": "ibm/model_m/ashpil_usbc" "target": "ibm/model_m/ashpil_usbc"
@ -47,10 +54,10 @@
"target": "viktus/at101_bh" "target": "viktus/at101_bh"
}, },
"atom47/rev2": { "atom47/rev2": {
"target": "maartenwut/atom47/rev2" "target": "evyd13/atom47/rev2"
}, },
"atom47/rev3": { "atom47/rev3": {
"target": "maartenwut/atom47/rev3" "target": "evyd13/atom47/rev3"
}, },
"bakeneko60": { "bakeneko60": {
"target": "kkatano/bakeneko60" "target": "kkatano/bakeneko60"
@ -65,7 +72,7 @@
"target": "bear_face/v1" "target": "bear_face/v1"
}, },
"bm16a": { "bm16a": {
"target": "kprepublic/bm16a" "target": "kprepublic/bm16a/v1"
}, },
"bm16s": { "bm16s": {
"target": "kprepublic/bm16s" "target": "kprepublic/bm16s"
@ -77,16 +84,16 @@
"target": "kprepublic/bm43a" "target": "kprepublic/bm43a"
}, },
"bm60poker": { "bm60poker": {
"target": "kprepublic/bm60poker" "target": "kprepublic/bm60hsrgb_poker/rev1"
}, },
"bm60rgb": { "bm60rgb": {
"target": "kprepublic/bm60rgb" "target": "kprepublic/bm60hsrgb/rev1"
}, },
"bm60rgb_iso": { "bm60rgb_iso": {
"target": "kprepublic/bm60rgb_iso" "target": "kprepublic/bm60hsrgb_iso/rev1"
}, },
"bm68rgb": { "bm68rgb": {
"target": "kprepublic/bm68rgb" "target": "kprepublic/bm68hsrgb/rev1"
}, },
"bpiphany/pegasushoof": { "bpiphany/pegasushoof": {
"target": "bpiphany/pegasushoof/2013" "target": "bpiphany/pegasushoof/2013"
@ -140,7 +147,10 @@
"target": "jagdpietr/drakon" "target": "jagdpietr/drakon"
}, },
"durgod/k320": { "durgod/k320": {
"target": "durgod/k3x0/k320" "target": "durgod/k320/base"
},
"durgod/k3x0/k320": {
"target": "durgod/k320/base"
}, },
"durgod/hades": { "durgod/hades": {
"target": "durgod/dgk6x/hades_ansi" "target": "durgod/dgk6x/hades_ansi"
@ -269,7 +279,7 @@
"target": "idb/idb_60" "target": "idb/idb_60"
}, },
"idobo": { "idobo": {
"target": "idobao/id75" "target": "idobao/id75/v1"
}, },
"jacky_studio/piggy60": { "jacky_studio/piggy60": {
"target": "jacky_studio/piggy60/rev1" "target": "jacky_studio/piggy60/rev1"
@ -401,7 +411,7 @@
"target": "mechlovin/adelais/rgb_led/rev1" "target": "mechlovin/adelais/rgb_led/rev1"
}, },
"mechlovin/adelais/standard_led": { "mechlovin/adelais/standard_led": {
"target": "mechlovin/adelais/standard_led/rev2" "target": "mechlovin/adelais/standard_led/arm/rev2"
}, },
"mechlovin/delphine": { "mechlovin/delphine": {
"target": "mechlovin/delphine/mono_led" "target": "mechlovin/delphine/mono_led"
@ -455,10 +465,10 @@
"target": "pabile/p20/ver1" "target": "pabile/p20/ver1"
}, },
"pancake/feather": { "pancake/feather": {
"target": "spaceman/pancake/feather" "target": "spaceman/pancake/rev1/feather"
}, },
"pancake/promicro": { "pancake/promicro": {
"target": "spaceman/pancake/promicro" "target": "spaceman/pancake/rev1/promicro"
}, },
"peiorisboards/ixora": { "peiorisboards/ixora": {
"target": "coarse/ixora" "target": "coarse/ixora"
@ -467,7 +477,7 @@
"target": "dm9records/plaid" "target": "dm9records/plaid"
}, },
"plain60": { "plain60": {
"target": "maartenwut/plain60" "target": "evyd13/plain60"
}, },
"ploopyco/trackball": { "ploopyco/trackball": {
"target": "ploopyco/trackball/rev1_005" "target": "ploopyco/trackball/rev1_005"
@ -503,10 +513,10 @@
"target": "wilba_tech/rama_works_u80_a" "target": "wilba_tech/rama_works_u80_a"
}, },
"ramonimbao/herringbone": { "ramonimbao/herringbone": {
"target": "ramonimbao/herringbone/v1" "target": "rmi_kb/herringbone/v1"
}, },
"ramonimbao/mona": { "ramonimbao/mona": {
"target": "ramonimbao/mona/v1" "target": "rmi_kb/mona/v1"
}, },
"rgbkb/pan": { "rgbkb/pan": {
"target": "rgbkb/pan/rev1/32a" "target": "rgbkb/pan/rev1/32a"
@ -542,10 +552,10 @@
"target": "tkw/stoutgat/v1" "target": "tkw/stoutgat/v1"
}, },
"suihankey": { "suihankey": {
"target": "suihankey/split/alpha" "target": "kakunpc/suihankey/split/alpha"
}, },
"ta65": { "ta65": {
"target": "maartenwut/ta65" "target": "evyd13/ta65"
}, },
"tartan": { "tartan": {
"target": "dm9records/tartan" "target": "dm9records/tartan"
@ -563,13 +573,13 @@
"target": "matthewdias/txuu" "target": "matthewdias/txuu"
}, },
"underscore33": { "underscore33": {
"target": "underscore33/rev1" "target": "tominabox1/underscore33/rev1"
}, },
"vinta": { "vinta": {
"target": "coarse/vinta" "target": "coarse/vinta"
}, },
"wasdat": { "wasdat": {
"target": "maartenwut/wasdat" "target": "evyd13/wasdat"
}, },
"westfoxtrot/cypher": { "westfoxtrot/cypher": {
"target": "westfoxtrot/cypher/rev1" "target": "westfoxtrot/cypher/rev1"
@ -581,10 +591,10 @@
"target": "xiudi/xd002" "target": "xiudi/xd002"
}, },
"xd004": { "xd004": {
"target": "xiudi/xd004" "target": "xiudi/xd004/v1"
}, },
"xd60": { "xd60": {
"target": "xiudi/xd60" "target": "xiudi/xd60/rev2"
}, },
"xd68": { "xd68": {
"target": "xiudi/xd68" "target": "xiudi/xd68"
@ -831,7 +841,7 @@
"target": "kagizaraya/halberd" "target": "kagizaraya/halberd"
}, },
"handwired/hillside/0_1": { "handwired/hillside/0_1": {
"target": "handwired/hillside/48" "target": "hillside/48/0_1"
}, },
"hecomi/alpha": { "hecomi/alpha": {
"target": "takashiski/hecomi/alpha" "target": "takashiski/hecomi/alpha"
@ -843,10 +853,10 @@
"target": "bpiphany/hid_liber" "target": "bpiphany/hid_liber"
}, },
"id67/default_rgb": { "id67/default_rgb": {
"target": "idobao/id67/default_rgb" "target": "idobao/id67"
}, },
"id67/rgb": { "id67/rgb": {
"target": "idobao/id67/rgb" "target": "idobao/id67"
}, },
"id80": { "id80": {
"target": "idobao/id80/v2/ansi" "target": "idobao/id80/v2/ansi"
@ -1236,7 +1246,7 @@
"target": "marksard/treadstone48/rev2" "target": "marksard/treadstone48/rev2"
}, },
"tronguylabs/m122_3270": { "tronguylabs/m122_3270": {
"target": "ibm/model_m_122/m122_3270" "target": "ibm/model_m_122/m122_3270/teensy"
}, },
"ua62": { "ua62": {
"target": "nacly/ua62" "target": "nacly/ua62"
@ -1290,7 +1300,7 @@
"target": "ydkb/yd68" "target": "ydkb/yd68"
}, },
"ymd75": { "ymd75": {
"target": "ymdk/ymd75" "target": "ymdk/ymd75/rev1"
}, },
"ymd96": { "ymd96": {
"target": "ymdk/ymd96" "target": "ymdk/ymd96"

View file

@ -31,6 +31,7 @@ safe_commands = [
] ]
subcommands = [ subcommands = [
'qmk.cli.ci.validate_aliases',
'qmk.cli.bux', 'qmk.cli.bux',
'qmk.cli.c2json', 'qmk.cli.c2json',
'qmk.cli.cd', 'qmk.cli.cd',

View file

View file

@ -0,0 +1,46 @@
"""Validates the list of keyboard aliases.
"""
from pathlib import Path
from milc import cli
from qmk.json_schema import json_load
from qmk.keyboard import resolve_keyboard, keyboard_folder
def _safe_keyboard_folder(target):
try:
return keyboard_folder(target) # throws ValueError if it's invalid
except Exception:
return None
def _target_keyboard_exists(target):
# If there's no target, then we can't build it.
if not target:
return False
# If the target directory existed but there was no rules.mk or rules.mk was incorrectly parsed, then we can't build it.
if not resolve_keyboard(target):
return False
# If the target directory exists but it itself has an invalid alias or invalid rules.mk, then we can't build it either.
if not _safe_keyboard_folder(target):
return False
# As far as we can tell, we can build it!
return True
@cli.subcommand('Validates the list of keyboard aliases.', hidden=True)
def ci_validate_aliases(cli):
aliases = json_load(Path('data/mappings/keyboard_aliases.hjson'))
success = True
for alias in aliases.keys():
target = aliases[alias].get('target', None)
if not _target_keyboard_exists(target):
cli.log.error(f'Keyboard alias {alias} has a target that doesn\'t exist: {target}')
success = False
return success

View file

@ -212,13 +212,16 @@ def parse_configurator_json(configurator_file):
cli.log.error(f'Invalid JSON keymap: {configurator_file} : {e.message}') cli.log.error(f'Invalid JSON keymap: {configurator_file} : {e.message}')
exit(1) exit(1)
orig_keyboard = user_keymap['keyboard'] keyboard = user_keymap['keyboard']
aliases = json_load(Path('data/mappings/keyboard_aliases.hjson')) aliases = json_load(Path('data/mappings/keyboard_aliases.hjson'))
if orig_keyboard in aliases: while keyboard in aliases:
if 'target' in aliases[orig_keyboard]: last_keyboard = keyboard
user_keymap['keyboard'] = aliases[orig_keyboard]['target'] keyboard = aliases[keyboard].get('target', keyboard)
if keyboard == last_keyboard:
break
user_keymap['keyboard'] = keyboard
return user_keymap return user_keymap

View file

@ -92,8 +92,11 @@ def keyboard_folder(keyboard):
""" """
aliases = json_load(Path('data/mappings/keyboard_aliases.hjson')) aliases = json_load(Path('data/mappings/keyboard_aliases.hjson'))
if keyboard in aliases: while keyboard in aliases:
last_keyboard = keyboard
keyboard = aliases[keyboard].get('target', keyboard) keyboard = aliases[keyboard].get('target', keyboard)
if keyboard == last_keyboard:
break
rules_mk_file = Path(base_path, keyboard, 'rules.mk') rules_mk_file = Path(base_path, keyboard, 'rules.mk')