summaryrefslogtreecommitdiffstats
path: root/.github/workflows/mkosi.yml
blob: 425d737b62f36d6296a031b4d61aa96fd0ca70f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
---
# vi: ts=2 sw=2 et:
# SPDX-License-Identifier: LGPL-2.1-or-later
# Simple boot tests that build and boot the mkosi images generated by the mkosi config files in mkosi.conf.d/.
name: mkosi

on:
  push:
    branches:
      - main
      - v[0-9]+-stable
    paths:
      - '**'
      - '!README*'
      - '!LICENSE*'
      - '!LICENSES/**'
      - '!TODO'
      - '!docs/**'
      - '!man/**'
      - '!catalog/**'
      - '!shell-completion/**'
      - '!po/**'
      - '!.**'
      - '.github/**'

  pull_request:
    branches:
      - main
      - v[0-9]+-stable
    paths:
      - '**'
      - '!README*'
      - '!LICENSE*'
      - '!LICENSES/**'
      - '!TODO'
      - '!docs/**'
      - '!man/**'
      - '!catalog/**'
      - '!shell-completion/**'
      - '!po/**'
      - '!.**'
      - '.github/**'

permissions:
  contents: read

jobs:
  ci:
    runs-on: ubuntu-24.04
    concurrency:
      group: ${{ github.workflow }}-${{ matrix.distro }}-${{ matrix.release }}-${{ github.ref }}
      cancel-in-progress: true
    strategy:
      fail-fast: false
      matrix:
        include:
          - distro: arch
            release: rolling
            sanitizers: ""
            llvm: 0
            cflags: "-O2 -D_FORTIFY_SOURCE=3"
          - distro: debian
            release: testing
            sanitizers: ""
            llvm: 0
            cflags: "-Og"
          - distro: ubuntu
            release: noble
            sanitizers: ""
            llvm: 0
            cflags: "-Og"
          - distro: fedora
            release: "40"
            sanitizers: ""
            llvm: 0
            cflags: "-Og"
          - distro: fedora
            release: rawhide
            sanitizers: address,undefined
            llvm: 1
            cflags: "-Og"
          - distro: opensuse
            release: tumbleweed
            sanitizers: ""
            llvm: 0
            cflags: "-Og"
          - distro: centos
            release: "9"
            sanitizers: ""
            llvm: 0
            cflags: "-Og"

    steps:
    - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29
    - uses: systemd/mkosi@0081ea66faf56a35353d6aeadfe42f9679c7d1cf

    # Freeing up disk space with rm -rf can take multiple minutes. Since we don't need the extra free space
    # immediately, we remove the files in the background. However, we first move them to a different location
    # so that nothing tries to use anything in these directories anymore while we're busy deleting them.
    - name: Free disk space
      run: |
        sudo mv /usr/local /usr/local.trash
        sudo mv /opt/hostedtoolcache /opt/hostedtoolcache.trash
        sudo systemd-run rm -rf /usr/local.trash /opt/hostedtoolcache.trash

    - name: Btrfs
      run: |
        truncate --size=100G btrfs.raw
        mkfs.btrfs btrfs.raw
        sudo mkdir /mnt/mkosi
        LOOP="$(sudo losetup --find --show --direct-io=on btrfs.raw)"
        sudo mount "$LOOP" /mnt/mkosi --options compress=zstd:1,user_subvol_rm_allowed,noatime,discard=async,space_cache=v2
        sudo chown "$(id -u):$(id -g)" /mnt/mkosi
        mkdir /mnt/mkosi/tmp
        echo "TMPDIR=/mnt/mkosi/tmp" >>"$GITHUB_ENV"
        ln -s /mnt/mkosi/build build

    - name: Configure
      run: |
        tee mkosi.local.conf <<EOF
        [Distribution]
        Distribution=${{ matrix.distro }}
        Release=${{ matrix.release }}

        [Output]
        # Build a disk image in CI as this logic is much more prone to breakage.
        Format=disk
        UseSubvolumes=yes

        WorkspaceDirectory=$TMPDIR
        PackageCacheDirectory=$TMPDIR/cache

        [Content]
        Environment=
                # Build debuginfo packages since we'll be publishing the packages as artifacts.
                WITH_DEBUG=1
                CFLAGS="${{ matrix.cflags }}"
                SANITIZERS=${{ matrix.sanitizers }}
                MESON_OPTIONS=--werror
                LLVM=${{ matrix.llvm }}

        [Host]
        QemuMem=4G
        # We build with debuginfo so there's no point in mounting the sources into the machine.
        RuntimeBuildSources=no
        EOF

    - name: Generate secure boot key
      run: mkosi --debug genkey

    - name: Show image summary
      run: mkosi summary

    - name: Install dependencies
      run: |
        mkosi dependencies |
        xargs -d '\n' sudo apt-get install \
            gperf \
            libblkid-dev \
            libcap-dev \
            libcryptsetup-dev \
            libcurl4-openssl-dev \
            libfdisk-dev \
            libmicrohttpd-dev \
            libmount-dev \
            libtss2-dev \
            meson

    - name: Configure meson
      run: |
        meson setup build \
            --buildtype=debugoptimized \
            -Dintegration-tests=true \
            -Dremote=enabled \
            -Dopenssl=enabled \
            -Dblkid=enabled \
            -Dtpm2=enabled \
            -Dlibcryptsetup=enabled \
            -Dlibcurl=enabled \
            -Drepart=enabled \
            -Dfirstboot=true \
            -Dsysusers=true \
            -Dtmpfiles=true \
            -Dhwdb=true \
            -Dvmspawn=enabled

    - name: Build image
      run: meson compile -C build mkosi

    - name: Run integration tests
      run: sudo --preserve-env meson test -C build --no-rebuild --suite integration-tests --print-errorlogs --no-stdsplit --num-processes "$(($(nproc) - 1))"

    - name: Archive failed test journals
      uses: actions/upload-artifact@v4
      if: failure() && (github.repository == 'systemd/systemd' || github.repository == 'systemd/systemd-stable')
      with:
        name: ci-mkosi-${{ github.run_id }}-${{ github.run_attempt }}-${{ matrix.distro }}-${{ matrix.release }}-failed-test-journals
        path: |
          build/test/journal/*.journal
          build/meson-logs/*
        retention-days: 7

    - name: Archive packages
      uses: actions/upload-artifact@v4
      if: (success() || failure()) && (github.repository == 'systemd/systemd' || github.repository == 'systemd/systemd-stable')
      with:
        name: ci-mkosi-${{ github.run_id }}-${{ github.run_attempt }}-${{ matrix.distro }}-${{ matrix.release }}-packages
        path: |
          build/mkosi.output/*.rpm
          build/mkosi.output/*.deb
          build/mkosi.output/*.ddeb
          build/mkosi.output/*.pkg.tar
        retention-days: 4