From c55ffec5b217fa91712dc8d0b1f0e623249a5197 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Mon, 25 Mar 2024 23:18:39 +0000 Subject: [PATCH] refactor(ci): use flake to build SVGs --- .github/workflows/draw-keymaps.yml | 72 +++++------------------------- .github/workflows/layers.py | 16 ------- 2 files changed, 12 insertions(+), 76 deletions(-) delete mode 100644 .github/workflows/layers.py diff --git a/.github/workflows/draw-keymaps.yml b/.github/workflows/draw-keymaps.yml index aa03e4c..0f20ac1 100644 --- a/.github/workflows/draw-keymaps.yml +++ b/.github/workflows/draw-keymaps.yml @@ -21,72 +21,24 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: - fetch-depth: 1 # Set to 2 if amending, or 1 if creating a new commit + # Set to 2 if amending, or 1 if creating a new commit + fetch-depth: 1 submodules: recursive - - name: Install python dependencies - run: | - pip install "git+https://github.com/caksoylar/keymap-drawer.git@${{ env.km_dr_version }}" - pip install pyyaml + - name: Install nix + uses: DeterminateSystems/nix-installer-action@main + - name: Setup nix cache + uses: DeterminateSystems/magic-nix-cache-action@main - # TODO get keyboads & configs dynamically - - name: Parse keymap - run: | - # TODO set generic vars in one place globally - CONFIG="${{ env.km_dr_config }}" + - name: Draw keymaps + run: nix build .#keymap-drawer-svgs - for KEYMAP in ${{ env.keymap_path }}; do - KEYBOARD=$(basename -s .keymap "$KEYMAP") - OUTPUT="${{ env.output_folder }}/${KEYBOARD}.yaml" - - # TODO consider running through `parallel`? - echo "Parsing keymap for $KEYBOARD" - keymap -c "$CONFIG" parse -z "$KEYMAP" > "$OUTPUT" - done - - - name: Draw keymap for all layers - run: | - CONFIG="${{ env.km_dr_config }}" - - # FIXME can glob false positeves, e.g. previous keymaps - for KEYMAP in ${{ env.output_folder }}/*.yaml; do - KEYBOARD=$(basename -s .yaml "$KEYMAP") - OUTPUT="${{ env.output_folder }}/${KEYBOARD}.svg" - - echo "Drawing all layers for $KEYBOARD" - keymap -c "$CONFIG" draw "$KEYMAP" > "$OUTPUT" - done - - - - name: Draw seperate layer keymaps - run: | - # Ensure errors propagate when piping stdout - set -o pipefail - - export CONFIG="${{ env.km_dr_config }}" - - # Function to draw the given layer's keymap - draw() { - KEYMAP="$1" - LAYER="$2" - KEYBOARD=$(basename -s .yaml "$KEYMAP") - OUTPUT="${{ env.output_folder }}/${KEYBOARD}_${LAYER}.svg" - - echo "Drawing $LAYER layer for $KEYBOARD" - keymap -c "$CONFIG" draw "$KEYMAP" -s "$LAYER" > "$OUTPUT" - } - export -f draw # Ensure the draw function can be called by `parallel`'s subprocess - - # FIXME can glob false positeves, e.g. previous keymaps - for KEYMAP in ${{ env.output_folder }}/*.yaml; do - # 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 "$KEYMAP" - done + - name: Copy SVGs into repo + run: cp result/* img + # TODO print to $GITHUB_STEP_SUMMARY - name: Commit changes uses: stefanzweifel/git-auto-commit-action@v4 with: diff --git a/.github/workflows/layers.py b/.github/workflows/layers.py deleted file mode 100644 index 8efc8fc..0000000 --- a/.github/workflows/layers.py +++ /dev/null @@ -1,16 +0,0 @@ -from sys import argv -import yaml - -if len(argv) < 2: - print(f'Usage: python {argv[0]} FILINAME') - exit(1) - -FILINAME = argv[1] - -with open(FILINAME, 'r') as file: - doc = yaml.safe_load(file) - if not 'layers' in doc: - print('Invalid file') - exit(2) - for layer in doc['layers'].keys(): - print(layer)