make keymap generation reusable, automatically run when updating docs #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Generate keymap files | ||
on: | ||
workflow_call: | ||
inputs: | ||
lite_xl_version: | ||
description: 'Lite XL version' | ||
required: true | ||
default: 'v2.1.6' | ||
workflow_dispatch: | ||
inputs: | ||
lite_xl_version: | ||
description: 'Lite XL version' | ||
required: true | ||
default: 'v2.1.6' | ||
jobs: | ||
generate_keymap: | ||
name: Generate keymap | ||
strategy: matrix | ||
matrix: | ||
platform: | ||
- { runs_on: 'ubuntu-latest', suffix: '' } | ||
- { runs_on: 'macos-latest', suffix: '-macos' } | ||
runs-on: ${{ matrix.platform.runs_on }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Setup Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.11' | ||
- name: Install Lite XL (Linux) | ||
if: ${{ !startsWith(matrix.platform.runs_on, 'macos') }} | ||
run: | | ||
curl -sSL "https://github.com/lite-xl/lite-xl/releases/download/${{ inputs.lite_xl_version }}/lite-xl-${{ inputs.lite_xl_version }}-linux-x86_64-portable.tar.gz" | tar -xvzf - | ||
- name: Install Lite XL (macOS) | ||
if: ${{ startsWith(matrix.platform.runs_on, 'macos') }} | ||
run: | | ||
wget "https://github.com/lite-xl/lite-xl/releases/download/${{ inputs.lite_xl_version }}/lite-xl-${{ inputs.lite_xl_version }}-macos-x86_64.dmg" | ||
hdiutil mount -noverify "lite-xl-${{ inputs.lite_xl_version }}-macos-x86_64.dmg" | ||
- name: Install keymap-export | ||
run: | | ||
mkdir -p user/plugins | ||
wget -O user/plugins/keymap_export.lua "https://raw.githubusercontent.com/takase1121/lite-xl-plugins/PR/keymap_export/plugins/keymap_export.lua" | ||
- name: Set up environment variables | ||
run: | | ||
echo "LITE_USERDIR=$PWD/user" >> $GITHUB_ENV | ||
echo "SDL_VIDEODRIVER=dummy" >> $GITHUB_ENV | ||
echo "KEYMAP_EXPORT_TYPE=reverse_map" >> $GITHUB_ENV | ||
echo "KEYMAP_EXPORT_DESTINATION=$PWD/keymap-source.json" >> $GITHUB_ENV | ||
echo "KEYMAP_EXPORT_AUTOSTART=true" >> $GITHUB_ENV | ||
echo "KEYMAP_EXPORT_QUIT_AFTER_EXPORT=true" >> $GITHUB_ENV | ||
- name: Run Lite XL (Linux) | ||
if: ${{ !startsWith(matrix.platform.runs_on, 'macos') }} | ||
run: cd lite-xl && ./lite-xl | ||
- name: Run Lite XL (macOS) | ||
if: ${{ startsWith(matrix.platform.runs_on, 'macos') }} | ||
run: open -a "/Volumes/Lite XL/Lite XL.app" | ||
- name: Fix keymap | ||
run: ./fix-keymap.py keymap-source.json keymap${{ matrix.platform.suffix }}.json | ||
- name: Upload keymap.json | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: keymap${{ matrix.platform.suffix }} | ||
path: keymap${{ matrix.platform.suffix }}.json | ||
create_pr: | ||
name: Create PR | ||
runs-on: ubuntu-latest | ||
needs: generate_keymap | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Download artifacts | ||
uses: actions/download-artifact@v4 | ||
with: | ||
merge-multiple: true | ||
path: docs/assets | ||
- name: Create PR | ||
uses: peter-evans/create-pull-request@v6 | ||
with: | ||
title: Update keymap files | ||
body: | | ||
This is an automated PR that updates keymap.json and keymap-macos.json | ||
based on changes in Lite XL ${{ inputs.lite_xl_version }}. | ||
commit-message: Update keymap.json and keymap-macos.json with changes from ${{ inputs.lite_xl_version }} | ||
add-paths: | | ||
docs/assets/keymap*.json |