Skip to content

migrate menhir to keyboard.json format #234

migrate menhir to keyboard.json format

migrate menhir to keyboard.json format #234

Workflow file for this run

name: keymaps
on:
push:
branches: [main, staging, trying]
pull_request:
branches: [main]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install mise
uses: jdx/mise-action@v3
- name: Lint shell scripts
run: mise run lint
matrix:
runs-on: ubuntu-latest
outputs:
keyboards: ${{ steps.set-matrix.outputs.keyboards }}
steps:
- uses: actions/checkout@v4
- name: Generate build matrix
id: set-matrix
run: |
# Parse keymaps file into JSON array of {keyboard, keymap, artifact_name} objects
# then batch them into groups of 16
keyboards=$(grep -v '^#' keymaps | grep -v '^//' | grep -v '^$' | while read -r line; do
kb=$(echo "$line" | awk '{print $1}')
km=$(echo "$line" | awk '{print $2}')
km="${km:-patcoll}"
artifact_name=$(echo "${kb}-${km}" | tr '/' '_')
echo "{\"keyboard\":\"$kb\",\"keymap\":\"$km\",\"artifact_name\":\"$artifact_name\"}"
done | jq -s -c '
# Split into batches of 16
[range(0; length; 16) as $i | {
batch_id: ($i / 16 | floor),
batch_name: (.[$i:$i+16] | map("\(.keyboard):\(.keymap)") | join(", ")),
keyboards: .[$i:$i+16]
}]
')
echo "keyboards=$keyboards" >> "$GITHUB_OUTPUT"
setup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install mise
uses: jdx/mise-action@v3
- name: Cache QMK firmware
id: cache-qmk
uses: actions/cache@v4
with:
path: working_area/qmk_firmware
key: qmk-${{ hashFiles('mise-tasks/setup') }}
- name: Cache pip packages
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: pip-qmk-${{ hashFiles('mise-tasks/setup') }}
- name: Install QMK CLI
if: steps.cache-qmk.outputs.cache-hit != 'true'
run: python3 -m pip install qmk
- name: Setup QMK
if: steps.cache-qmk.outputs.cache-hit != 'true'
run: mise run setup
- name: Cache QMK build dependencies
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: build-essential clang-format diffutils gcc git unzip wget zip python3-pip binutils-avr gcc-avr avr-libc binutils-arm-none-eabi gcc-arm-none-eabi libnewlib-arm-none-eabi avrdude dfu-programmer dfu-util teensy-loader-cli libhidapi-hidraw0 libusb-dev picolibc-riscv64-unknown-elf gcc-riscv64-unknown-elf binutils-riscv64-unknown-elf
version: 1.0
execute_install_scripts: true
- name: Install QMK build dependencies
if: steps.cache-qmk.outputs.cache-hit != 'true'
run: |
cd ${{ github.workspace }}/working_area/qmk_firmware
sudo util/qmk_install.sh -y
build:
name: build (${{ matrix.batch_id }}, ${{ matrix.batch_name }})
needs: [lint, matrix, setup]
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 8
matrix:
include: ${{ fromJson(needs.matrix.outputs.keyboards) }}
steps:
- uses: actions/checkout@v4
- name: Install mise
uses: jdx/mise-action@v3
- name: Restore QMK firmware cache
uses: actions/cache@v4
with:
path: working_area/qmk_firmware
key: qmk-${{ hashFiles('mise-tasks/setup') }}
fail-on-cache-miss: true
- name: Restore QMK build dependencies
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: build-essential clang-format diffutils gcc git unzip wget zip python3-pip binutils-avr gcc-avr avr-libc binutils-arm-none-eabi gcc-arm-none-eabi libnewlib-arm-none-eabi avrdude dfu-programmer dfu-util teensy-loader-cli libhidapi-hidraw0 libusb-dev picolibc-riscv64-unknown-elf gcc-riscv64-unknown-elf binutils-riscv64-unknown-elf
version: 1.0
execute_install_scripts: true
- name: Restore pip cache
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: pip-qmk-${{ hashFiles('mise-tasks/setup') }}
- name: Install QMK CLI
run: python3 -m pip install qmk
- name: Install QMK build dependencies
run: |
cd ${{ github.workspace }}/working_area/qmk_firmware
sudo util/qmk_install.sh -y
- name: Sync and build keyboards
env:
KEYBOARDS_JSON: ${{ toJson(matrix.keyboards) }}
run: |
failed=0
echo "$KEYBOARDS_JSON" | jq -c '.[]' | while read -r item; do
keyboard=$(echo "$item" | jq -r '.keyboard')
keymap=$(echo "$item" | jq -r '.keymap')
echo "::group::Building $keyboard:$keymap"
if ! mise run sync "$keyboard" || ! mise run qmk compile -kb "$keyboard" -km "$keymap"; then
echo "::error::Failed to build $keyboard:$keymap"
echo "1" > /tmp/build_failed
fi
echo "::endgroup::"
done
if [ -f /tmp/build_failed ]; then
exit 1
fi
- uses: actions/upload-artifact@v4
if: always()
with:
name: firmware-batch-${{ matrix.batch_id }}
path: |
${{ github.workspace }}/*.bin
${{ github.workspace }}/*.hex
${{ github.workspace }}/*.uf2
collect:
needs: [build]
if: always()
runs-on: ubuntu-latest
outputs:
files: ${{ steps.list.outputs.files }}
steps:
- uses: actions/download-artifact@v4
with:
pattern: firmware-batch-*
path: firmware
merge-multiple: true
- name: List firmware files
id: list
run: |
files=$(ls firmware/ 2>/dev/null | jq -R -s -c 'split("\n") | map(select(length > 0))')
echo "files=$files" >> "$GITHUB_OUTPUT"
echo "Found files: $files"
- uses: actions/upload-artifact@v4
with:
name: firmware
path: firmware/*
- name: Delete batch artifacts
uses: geekyeggo/delete-artifact@v5
with:
name: firmware-batch-*
upload-individual:
needs: [collect]
if: always() && needs.collect.outputs.files != '[]'
runs-on: ubuntu-latest
strategy:
matrix:
file: ${{ fromJson(needs.collect.outputs.files) }}
steps:
- uses: actions/download-artifact@v4
with:
name: firmware
- name: Get artifact name
id: name
run: echo "name=$(echo '${{ matrix.file }}' | sed 's/\.[^.]*$//')" >> "$GITHUB_OUTPUT"
- uses: actions/upload-artifact@v4
with:
name: ${{ steps.name.outputs.name }}
path: ${{ matrix.file }}
cleanup:
needs: [upload-individual]
if: always()
runs-on: ubuntu-latest
steps:
- name: Delete firmware artifact
uses: geekyeggo/delete-artifact@v5
with:
name: firmware