Initial DD keycode regen workflow (#19400)

This commit is contained in:
Joel Challis 2023-01-01 00:46:17 +00:00 committed by GitHub
parent 422fd8aed8
commit 5a3594366f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 85 additions and 73 deletions

33
.github/workflows/regen.yml vendored Normal file
View file

@ -0,0 +1,33 @@
name: PR Regenerate Files
permissions:
contents: read
on:
pull_request:
paths:
- 'data/constants/**'
- 'lib/python/**'
jobs:
regen:
runs-on: ubuntu-latest
container: qmkfm/qmk_cli
steps:
- uses: actions/checkout@v3
- name: Run qmk generators
run: |
util/regen.sh
git diff
- name: Fail when regeneration required
run: |
git diff
for file in $(git diff --name-only); do
echo "File '${file}' Requires Regeneration"
echo "::error file=${file}::Requires Regeneration"
done
test -z "$(git diff --name-only)"

43
.github/workflows/regen_push.yml vendored Normal file
View file

@ -0,0 +1,43 @@
name: Regenerate Files
permissions:
contents: write
on:
push:
branches:
- master
- develop
jobs:
regen:
runs-on: ubuntu-latest
container: qmkfm/qmk_cli
steps:
- uses: actions/checkout@v3
- name: Run qmk generators
run: |
util/regen.sh
git diff
- uses: rlespinasse/github-slug-action@v3.x
- name: Become QMK Bot
run: |
git config user.name 'QMK Bot'
git config user.email 'hello@qmk.fm'
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
if: ${{ github.repository == 'qmk/qmk_firmware'}}
with:
token: ${{ secrets.QMK_BOT_TOKEN }}
delete-branch: true
branch: bugfix/format_${{ env.GITHUB_REF_SLUG }}
author: QMK Bot <hello@qmk.fm>
committer: QMK Bot <hello@qmk.fm>
commit-message: Regenerate Files
title: '[CI] Regenerate Files'

View file

@ -1,65 +0,0 @@
from pathlib import Path
langs = set()
files = Path('quantum/keymap_extras/').glob('keymap_*.h')
for file in files:
langs.add(file.stem.replace('keymap_', ''))
for lang in langs:
try:
file = Path(f'quantum/keymap_extras/keymap_{lang}.h')
print(f'Reading:{file}')
collect = None
out = []
out += ['{']
out += [' "aliases": {']
lines = file.read_text(encoding='utf-8').split('\n')
for line in lines:
if line.startswith("// Row"):
# print(line)
continue
elif line.startswith("/*******************************************************************************"):
raise Exception(f'Skipping:{file}')
elif '/*' in line:
collect = [line]
elif '*/' in line:
collect += [line]
if 'copyright' in collect[0].lower():
collect = None
continue
out += collect
collect = None
elif collect:
collect += [line]
elif '#define' in line:
define = line.split()
while len(define) < 5:
define.append("")
if define[4] == "(backslash)":
define[4] = '\\\\'
define[4] = " ".join(define[4:]).strip()
define[4] = define[4].replace('"', '\\"')
if define[4]:
out += [f' "{define[2]}": {{']
out += [f' "key": "{define[1]}",']
out += [f' "label": "{define[4]}",']
out += [f' }}']
else:
out += [f' "{define[2]}": {{']
out += [f' "key": "{define[1]}"']
out += [f' }}']
out += [' }']
out += ['}']
dump = Path(f'data/constants/keycodes/extras/keycodes_{lang}_0.0.1.hjson')
print(f'Writing:{dump}')
dump.write_text("\n".join(out), encoding='utf-8')
except Exception as e:
print(e)

View file

@ -1,8 +0,0 @@
#!/bin/bash
for lang in $(find data/constants/keycodes/extras/ -type f -printf "%f\n" | sed "s/keycodes_//g" | sed "s/_[0-9].*//"); do
data=$(qmk generate-keycode-extras --version latest --lang $lang)
if [ "$?" == "0" ]; then
echo "$data" > quantum/keymap_extras/keymap_$lang.h
fi
done

9
util/regen.sh Executable file
View file

@ -0,0 +1,9 @@
#!/bin/bash
set -e
qmk generate-rgb-breathe-table -o quantum/rgblight/rgblight_breathe_table.h
qmk generate-keycodes --version latest -o quantum/keycodes.h
for lang in $(find data/constants/keycodes/extras/ -type f -printf "%f\n" | sed "s/keycodes_\(.*\)_[0-9].*/\1/"); do
qmk generate-keycode-extras --version latest --lang $lang -o quantum/keymap_extras/keymap_$lang.h
done