logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

newbs_building_firmware_workflow.md (8449B)


  1. # Building QMK with GitHub Userspace
  2. This is an intermediate QMK tutorial to setup an out-of-tree build environment with a personal GitHub repository. It avoids using a fork of the QMK firmware to store and build your keymap within its source tree. Keymap files will instead be stored in your own personal GitHub repository, in [Userspace](feature_userspace) format, and built with an action workflow. Unlike the [default tutorial](newbs), this guide requires some familiarity with using Git.
  3. ::: tip Is This Guide For Me?
  4. This is a lean setup to avoid space-consuming local build environment in your computer. Troubleshooting compile-time errors will be slower with commit uploads to GitHub for the compiler workflow.
  5. :::
  6. ## Prerequisites
  7. The following are required to get started:
  8. * [GitHub Account](https://github.com/new)
  9. * A working account is required to setup and host your repository for GitHub Actions to build QMK firmware.
  10. * [Text editor](newbs_learn_more_resources#text-editor-resources)
  11. * You’ll need a program that can edit and save plain text files. The default editor that comes with many OS's does not save plain text files, so you'll need to make sure that whatever editor you chose does.
  12. * [Toolbox](https://github.com/qmk/qmk_toolbox)
  13. * A graphical program for Windows and macOS that allows you to both program and debug your custom keyboard.
  14. ## Environment Setup
  15. ::: tip
  16. If you are familiar with using [github.dev](https://docs.github.com/en/codespaces/the-githubdev-web-based-editor), you can skip to [step 2](#_2-create-github-repository) and commit the code files that follows directly on GitHub using the web-based VSCode editor.
  17. :::
  18. ### 1. Install Git
  19. A working Git client is required for your local operating system to commit and push changes to GitHub.
  20. ::::tabs
  21. === Windows
  22. QMK maintains a bundle of MSYS2, the CLI and all necessary dependencies including Git. Install [QMK MSYS](https://msys.qmk.fm/) with the latest release [here](https://github.com/qmk/qmk_distro_msys/releases/latest). Git will be part of the bundle.
  23. === macOS
  24. Install Homebrew following the instructions on https://brew.sh. Git will be part of the bundle.
  25. === Linux/WSL
  26. It's very likely that you already have Git installed. If not, use one of the following commands:
  27. * Debian / Ubuntu / Devuan: `sudo apt install -y git`
  28. * Fedora / Red Hat / CentOS: `sudo yum -y install git`
  29. * Arch / Manjaro: `sudo pacman --needed --noconfirm -S git`
  30. * Void: `sudo xbps-install -y git`
  31. * Solus: `sudo eopkg -y install git`
  32. * Sabayon: `sudo equo install dev-vcs/git`
  33. * Gentoo: `sudo emerge dev-vcs/git`
  34. ::::
  35. ### 2. GitHub authentication
  36. If your GitHub account is not configured for [authenticated Git operations](https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/), you will need to setup at least one of the following:
  37. * [Personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token)
  38. * [Connecting with SSH](https://docs.github.com/en/authentication/connecting-to-github-with-ssh)
  39. ### 3. Create a repository
  40. You will need a personal GitHub repository to host your QMK code. Follow [this guide](https://docs.github.com/en/get-started/quickstart/create-a-repo#create-a-repository) to create one named `qmk_keymap`. Do not proceed to commit any files just yet.
  41. ## Initial Code Commit
  42. ### Create template files
  43. Run the following commands in your computer to create a folder with a few template files:
  44. ```
  45. mkdir -p ~/qmk_keymap/.github/workflows
  46. touch ~/qmk_keymap/.github/workflows/build.yml
  47. touch ~/qmk_keymap/config.h
  48. echo "SRC += source.c" > ~/qmk_keymap/rules.mk
  49. echo "#include QMK_KEYBOARD_H" > ~/qmk_keymap/source.c
  50. ```
  51. ::: tip
  52. For Windows user running MSYS, those commands will create the folder `qmk_keymap/` and its content in the `C:\Users\<windows_username>\qmk_keymap\` path location.
  53. :::
  54. ### Add a JSON keymap
  55. Visit the [QMK Configurator](https://config.qmk.fm/#/) to create a keymap file:
  56. 1. Select your keyboard from the drop-down list (and choose a layout if required).
  57. 2. Use your GitHub username for the **Keymap Name** field.
  58. 3. Customise the key layout according to your preference.
  59. 4. Select download next to **KEYMAP.JSON** and save the JSON file into the `~/qmk_keymap/` folder.
  60. ::: warning
  61. **Important:** Make sure that the GitHub username you use in step 2 is correct. If it is not, the build process will fail to locate your files in the right folder.
  62. :::
  63. ### Add a GitHub Action workflow
  64. Open the file `~/qmk_keymap/.github/workflows/build.yml` with your favorite [text editor](newbs_learn_more_resources#text-editor-resources), paste the following workflow content, and save it:
  65. ```yml
  66. name: Build QMK firmware
  67. on: [push, workflow_dispatch]
  68. jobs:
  69. build:
  70. runs-on: ubuntu-latest
  71. container: ghcr.io/qmk/qmk_cli
  72. strategy:
  73. fail-fast: false
  74. matrix:
  75. # List of keymap json files to build
  76. file:
  77. - username.json
  78. # End of json file list
  79. steps:
  80. - name: Disable git safe directory checks
  81. run : git config --global --add safe.directory '*'
  82. - name: Checkout QMK
  83. uses: actions/checkout@v3
  84. with:
  85. repository: qmk/qmk_firmware
  86. submodules: recursive
  87. - name: Checkout userspace
  88. uses: actions/checkout@v3
  89. with:
  90. path: users/${{ github.actor }}
  91. - name: Build firmware
  92. run: qmk compile "users/${{ github.actor }}/${{ matrix.file }}"
  93. - name: Archive firmware
  94. uses: actions/upload-artifact@v3
  95. continue-on-error: true
  96. with:
  97. name: ${{ matrix.file }}_${{ github.actor }}
  98. path: |
  99. *.hex
  100. *.bin
  101. *.uf2
  102. ```
  103. Replace `username.json` with the JSON file name that was downloaded from [QMK Configurator](https://config.qmk.fm/#/) in the previous step.
  104. ::: warning
  105. Do note that the `build.yml` file requires ***proper indentation*** for every line. Incorrect spacing will trigger workflow syntax errors.
  106. :::
  107. ### Commit files to GitHub
  108. If you have completed all steps correctly, the folder `qmk_keymap/` will contain the following files:
  109. ```
  110. ├── .github
  111. │   └── workflows
  112. │   └── build.yml
  113. ├── rules.mk
  114. ├── config.h
  115. ├── source.c
  116. └── username.json
  117. ```
  118. To commit and push them into GitHub, run the following commands (replacing `gh-username` with your GitHub user name):
  119. ```
  120. cd ~/qmk_keymap
  121. git init
  122. git add -A
  123. git commit -m "Initial QMK keymap commit"
  124. git branch -M main
  125. git remote add origin https://github.com/gh-username/qmk_keymap.git
  126. git push -u origin main
  127. ```
  128. ::: tip
  129. Use your GitHub personal access token at the password prompt. If you have setup SSH access, replace `https://github.com/gh-username/qmk_keymap.git` with `git@github.com:gh-username/qmk_keymap.git` in the remote origin command above.
  130. :::
  131. ### Review workflow output
  132. Files committed to GitHub in the previous step will automatically trigger the workflow to build the JSON file listed in `build.yml`. To review its output:
  133. 1. Visit your "**qmk_keymap**" repository page on [GitHub](https://github.com/).
  134. 2. Select **Actions** tab to display the "**Build QMK Firmware**" workflow.
  135. 3. Select that workflow to display its run from the last commit.
  136. 4. Successfully compiled firmware will be under the "**Artifacts**" section.
  137. 5. If there are build errors, review the job log for details.
  138. Download and flash the firmware file into your keyboard using [QMK Toolbox](newbs_flashing#flashing-your-keyboard-with-qmk-toolbox).
  139. ## Customising your keymap
  140. This setup and workflow relies on the QMK [Userspace](feature_userspace) feature. The build process will copy the QMK source codes and clone your repository into its `users/` folder in a container. You must adhere to the following guidelines when customising your keymaps:
  141. * Keymap layout files must be retained in JSON format and cannot be converted to `keymap.c`.
  142. * User callback and functions (e.g. `process_record_user()`) can be placed in the `source.c` file.
  143. * Multiple keymap JSON files can be built in the same workflow. List them under `matrix.file:`, e.g.:
  144. ```yml
  145. file:
  146. - planck.json
  147. - crkbd.json
  148. ```
  149. * Code changes will require Git commit into GitHub to trigger the build workflow.
  150. ::: tip
  151. See [GitHub Actions guide](https://docs.github.com/en/actions/learn-github-actions) to learn more about development workflow.
  152. :::