Skip to content

Build and test the Nix shell environment #2025

Build and test the Nix shell environment

Build and test the Nix shell environment #2025

Workflow file for this run

name: Build and test the Nix shell environment
on:
pull_request:
push:
branches:
- main
- master
workflow_dispatch:
inputs:
mode:
description: 'Build mode: quick|default|full'
required: true
default: "default"
schedule:
- cron: '42 2 * * *'
env:
CACHIX_NAME: sigprof
jobs:
# The `setup` job determines the strategy for the real build job.
setup:
name: Setup
runs-on: ubuntu-latest
outputs:
strategy: ${{ steps.strategy.outputs.result }}
steps:
- id: strategy
name: Determine build strategy
uses: actions/github-script@v7.0.1
with:
script: |
// Matrix for the "quick" mode.
const quickMatrix = {
os: [ "ubuntu-latest" ],
source: [
{ repo: "qmk/qmk_firmware", branch: "master" }
],
nixPath: [
"nixpkgs=channel:nixos-24.05"
]
};
// Matrix for the "default" and "full" modes.
const defaultMatrix = {
os: [ "ubuntu-latest", "macos-12", "macos-14" ],
source: [
{ repo: "qmk/qmk_firmware", branch: "master" }
],
nixPath: [
"nixpkgs=channel:nixos-24.05"
]
};
// Determine the mode from workflow inputs.
let mode = "default";
if (context.eventName == "workflow_dispatch") {
const payload = context.payload;
const inputs = payload && payload.inputs;
mode = inputs && inputs.mode && inputs.mode.trim() || "default";
} else if (context.eventName == "schedule") {
mode = "full";
}
// Determine build strategy according to the selected mode.
const strategy = {
"fail-fast": !(mode == "full"),
"matrix": (mode == "quick") ? quickMatrix : defaultMatrix
};
// Print the resulting strategy to the log.
core.startGroup("Job strategy:");
core.info(JSON.stringify(strategy, null, 2));
core.endGroup();
// Return the strategy as the step output in the JSON format.
return strategy;
test:
needs: setup
strategy: ${{ fromJSON(needs.setup.outputs.strategy) }}
defaults:
run:
shell: bash
working-directory: qmk_firmware
runs-on: ${{ matrix.os }}
steps:
- name: Install Nix
uses: cachix/install-nix-action@v26
with:
nix_path: "${{ matrix.nixPath }}"
- name: Show nixpkgs version
working-directory: .
run: nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version'
- name: Setup Cachix
uses: cachix/cachix-action@v14
with:
name: ${{ env.CACHIX_NAME }}
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- name: Checkout the project source
uses: actions/checkout@v4.1.1
with:
path: nix-devenv-qmk
- name: Checkout the QMK firmware source
uses: actions/checkout@v4.1.1
with:
path: qmk_firmware
repository: ${{ matrix.source.repo }}
ref: ${{ matrix.source.branch }}
submodules: recursive
- name: Configure the 'upstream' remote
run: git remote add upstream https://github.com/qmk/qmk_firmware
- name: Configure the udev rules
if: ${{ runner.os == 'Linux' }}
run: sudo install -o root -g root -m 0644 util/udev/50-qmk.rules /etc/udev/rules.d/
- name: Build the Nix shell environment
id: nix_shell
run: nix-shell ../nix-devenv-qmk/shell.nix --show-trace --run 'true'
- name: Update submodules
run: nix-shell ../nix-devenv-qmk/shell.nix --run 'make git-submodule'
- name: Test 'qmk doctor'
if: ${{ always() && (steps.nix_shell.outcome == 'success') }}
run: nix-shell ../nix-devenv-qmk/shell.nix --run 'qmk doctor'
- name: Test 'qmk setup'
if: ${{ always() && (steps.nix_shell.outcome == 'success') }}
run: |
# Test 'qmk setup'
# 'qmk setup' does not return the exit code of 'qmk doctor',
# therefore grepping the text output is needed.
nix-shell ../nix-devenv-qmk/shell.nix --run 'qmk setup' 2>&1 | tee qmk-setup.log
grep -q "QMK is ready to go" qmk-setup.log
- name: Test AVR build using 'make'
if: ${{ always() && (steps.nix_shell.outcome == 'success') }}
run: nix-shell ../nix-devenv-qmk/shell.nix --run 'make planck/rev5:default'
- name: Test Arm build using 'make'
if: ${{ always() && (steps.nix_shell.outcome == 'success') }}
run: nix-shell ../nix-devenv-qmk/shell.nix --run 'make planck/rev6:default'
- name: Test 'make clean'
if: ${{ always() && (steps.nix_shell.outcome == 'success') }}
run: nix-shell ../nix-devenv-qmk/shell.nix --run 'make clean'
- name: Force clean before testing 'qmk compile'
if: ${{ always() && (steps.nix_shell.outcome == 'success') }}
run: git clean -fdx
- name: Test AVR build using 'qmk compile'
if: ${{ always() && (steps.nix_shell.outcome == 'success') }}
run: nix-shell ../nix-devenv-qmk/shell.nix --run 'qmk compile -kb planck/rev5 -km default'
- name: Test Arm build using 'qmk compile'
if: ${{ always() && (steps.nix_shell.outcome == 'success') }}
run: nix-shell ../nix-devenv-qmk/shell.nix --run 'qmk compile -kb planck/rev6 -km default'
- name: Test 'qmk clean'
if: ${{ always() && (steps.nix_shell.outcome == 'success') }}
run: nix-shell ../nix-devenv-qmk/shell.nix --run 'qmk clean'
finish:
needs:
- setup
- test
runs-on: ubuntu-latest
if: always()
env:
ci_success: >-
${{
(needs.setup.result == 'success')
&& (needs.test.result == 'success')
}}
steps:
- name: Report CI status
run: $ci_success