|
| 1 | +name: Build with Nix |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + pull_request: |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + |
| 11 | +jobs: |
| 12 | + build: |
| 13 | + name: Build with Nix (Ubuntu) |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - name: Checkout |
| 17 | + uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + path: smp-server-fixtures |
| 20 | + persist-credentials: false |
| 21 | + |
| 22 | + # Install Nix with flakes enabled |
| 23 | + - name: Install Nix |
| 24 | + uses: DeterminateSystems/nix-installer-action@main |
| 25 | + with: |
| 26 | + extra-conf: | |
| 27 | + experimental-features = nix-command flakes |
| 28 | +
|
| 29 | + # Cache the Nix store for fast dependency restoration |
| 30 | + - name: Cache Nix store |
| 31 | + uses: DeterminateSystems/magic-nix-cache-action@main |
| 32 | + |
| 33 | + # Install system GCC for portable native_sim builds |
| 34 | + - name: Install system GCC multilib |
| 35 | + run: | |
| 36 | + sudo apt-get update |
| 37 | + sudo apt-get install -y gcc gcc-multilib g++-multilib |
| 38 | +
|
| 39 | + # Cache the Zephyr SDK |
| 40 | + - name: Cache Zephyr SDK |
| 41 | + uses: actions/cache@v4 |
| 42 | + with: |
| 43 | + path: ~/zephyr-sdk-0.17.4 |
| 44 | + key: zephyr-sdk-0.17.4-${{ runner.os }} |
| 45 | + |
| 46 | + # Cache the workspace (zephyr, modules, bootloader) |
| 47 | + # Exclude the current repo to avoid caching build artifacts |
| 48 | + - name: Cache Zephyr workspace |
| 49 | + uses: actions/cache@v4 |
| 50 | + with: |
| 51 | + path: | |
| 52 | + zephyr |
| 53 | + modules |
| 54 | + bootloader |
| 55 | + .west |
| 56 | + key: zephyr-workspace-${{ runner.os }}-${{ hashFiles('smp-server-fixtures/west.yml') }} |
| 57 | + restore-keys: | |
| 58 | + zephyr-workspace-${{ runner.os }}- |
| 59 | +
|
| 60 | + # Cache Python virtual environment |
| 61 | + # Invalidates when west.yml changes (affects Python dependencies via west packages) |
| 62 | + - name: Cache Python venv |
| 63 | + uses: actions/cache@v4 |
| 64 | + with: |
| 65 | + path: .venv |
| 66 | + key: python-venv-${{ runner.os }}-${{ hashFiles('smp-server-fixtures/west.yml') }} |
| 67 | + restore-keys: | |
| 68 | + python-venv-${{ runner.os }}- |
| 69 | +
|
| 70 | + # Cache ccache for faster C/C++ compilation |
| 71 | + - name: Cache ccache |
| 72 | + uses: actions/cache@v4 |
| 73 | + with: |
| 74 | + path: .ccache |
| 75 | + key: ccache-${{ runner.os }}-${{ github.sha }} |
| 76 | + restore-keys: | |
| 77 | + ccache-${{ runner.os }}- |
| 78 | +
|
| 79 | + # Initialize west workspace if not cached |
| 80 | + # Note: west update will be run later by nix develop shell hook |
| 81 | + # This step just sets up the workspace structure |
| 82 | + - name: Initialize west workspace |
| 83 | + working-directory: smp-server-fixtures |
| 84 | + run: | |
| 85 | + if [ ! -d "../.west" ]; then |
| 86 | + echo "Initializing west workspace..." |
| 87 | + pip3 install west |
| 88 | + cd .. |
| 89 | + west init -l smp-server-fixtures |
| 90 | + else |
| 91 | + echo "West workspace already initialized (from cache)" |
| 92 | + fi |
| 93 | +
|
| 94 | + # Enter Nix development environment and build |
| 95 | + - name: Build with Nix environment |
| 96 | + working-directory: smp-server-fixtures |
| 97 | + run: | |
| 98 | + nix develop --command bash -c ' |
| 99 | + set -e |
| 100 | +
|
| 101 | + # Show environment info |
| 102 | + echo "=== Environment Info ===" |
| 103 | + echo "GCC: $(which gcc) - $(gcc --version | head -1)" |
| 104 | + echo "Python: $(which python) - $(python --version)" |
| 105 | + echo "West: $(which west) - $(west --version)" |
| 106 | + echo "Ccache: $(ccache -s || echo "empty")" |
| 107 | + echo "" |
| 108 | +
|
| 109 | + # Build native_sim serial fixture |
| 110 | + echo "=== Building native_sim serial fixture ===" |
| 111 | + west build -b native_sim apps/smp-server -T smp_server.fixture.serial.native_sim |
| 112 | +
|
| 113 | + # Run Twister integration tests |
| 114 | + echo "=== Running Twister Integration Tests ===" |
| 115 | + west twister -T apps -v --inline-logs --integration --short-build-path -O /tmp/twister-out |
| 116 | +
|
| 117 | + # Show ccache stats |
| 118 | + echo "" |
| 119 | + echo "=== Ccache Statistics ===" |
| 120 | + ccache -s |
| 121 | + ' |
| 122 | +
|
| 123 | + # Upload native_sim serial fixture |
| 124 | + - name: Upload native_sim serial fixture |
| 125 | + uses: actions/upload-artifact@v4 |
| 126 | + with: |
| 127 | + name: smp-server-fixture-serial-${{ github.sha }}-native_sim-nix |
| 128 | + path: smp-server-fixtures/build/smp-server/zephyr/zephyr.exe |
| 129 | + |
| 130 | + # Upload twister artifacts |
| 131 | + - name: Upload twister artifacts |
| 132 | + uses: actions/upload-artifact@v4 |
| 133 | + with: |
| 134 | + name: smp-server-fixtures-nix-${{ github.sha }}-ubuntu |
| 135 | + path: | |
| 136 | + /tmp/twister-out/**/*.hex |
| 137 | + /tmp/twister-out/**/*.bin |
| 138 | + /tmp/twister-out/**/*.exe |
| 139 | + /tmp/twister-out/**/*.elf |
| 140 | + /tmp/twister-out/**/*.map |
| 141 | + /tmp/twister-out/**/*.stat |
| 142 | + /tmp/twister-out/**/zephyr.dts |
| 143 | + /tmp/twister-out/**/build.log |
| 144 | + /tmp/twister-out/twister.log |
0 commit comments