|
| 1 | +# .github/workflows/qemu.yaml |
| 2 | + |
| 3 | +name: Build Under Latest Ubuntu |
| 4 | + |
| 5 | +on: |
| 6 | + workflow_dispatch: NULL |
| 7 | + |
| 8 | +jobs: |
| 9 | + |
| 10 | + qemu-build: |
| 11 | + name: Build with ${{matrix.compiler.label}}/${{matrix.march.label}} |
| 12 | + strategy: |
| 13 | + fail-fast: FALSE |
| 14 | + matrix: |
| 15 | + compiler: |
| 16 | + - { label: 'gcc9', gcc: 'gcc', gxx: 'g++' } |
| 17 | + - { label: 'gcc10', gcc: 'gcc-10', gxx: 'g++-10' } |
| 18 | + - { label: 'clang18', gcc: 'clang-18', gxx: 'clang++-18' } |
| 19 | + march: |
| 20 | + - { label: '64', flags: '' } |
| 21 | + - { label: '32', flags: '-m32 -msse2 -mfpmath=sse' } |
| 22 | + - { label: 'x32', flags: '-mx32' } |
| 23 | + |
| 24 | + runs-on: ubuntu-latest |
| 25 | + needs: [ qemu-cache ] |
| 26 | + |
| 27 | + defaults: |
| 28 | + run: { shell: bash } |
| 29 | + steps: |
| 30 | + |
| 31 | + - &minfo |
| 32 | + name: Host Machine Information |
| 33 | + run: | |
| 34 | + exec 2>&1 |
| 35 | + set -x |
| 36 | + lscpu; free -h; df -H . |
| 37 | + - &sinfo |
| 38 | + name: Host System Information |
| 39 | + run: | |
| 40 | + exec 2>&1 |
| 41 | + date; uname -a; uptime |
| 42 | + set -x |
| 43 | + systemd-detect-virt; cat /etc/os-release; ls -C /boot || : |
| 44 | + - &cinfo |
| 45 | + name: Context Information |
| 46 | + run: | |
| 47 | + exec 2>&1 |
| 48 | + tty || :; id; printf %s\\n "SHELL=$SHELL" "PATH=$PATH" |
| 49 | + set -x |
| 50 | + pwd |
| 51 | + - name: Host Setup |
| 52 | + run: | |
| 53 | + exec 2>&1 |
| 54 | + set -x |
| 55 | + sudo sed -i /azure/d /etc/apt/apt-mirrors.txt |
| 56 | + sudo apt-get update |
| 57 | + sudo apt-get install --no-install-recommends qemu-system-x86 cloud-image-utils |
| 58 | + - name: QEMU Information |
| 59 | + run: | |
| 60 | + exec 2>&1 |
| 61 | + qemu-system-x86_64 --version |
| 62 | +
|
| 63 | + - name: Cache Object Lookup |
| 64 | + uses: actions/cache@v4 |
| 65 | + with: |
| 66 | + key: ubuntu-focal-cloud-generic |
| 67 | + path: | |
| 68 | + ~/root.img |
| 69 | + ~/.ssh/id_rsa |
| 70 | + /usr/local/bin/vmbash.sh |
| 71 | + - name: Start Guest |
| 72 | + run: | |
| 73 | + exec 2>&1 |
| 74 | + set -x |
| 75 | + cd |
| 76 | + sudo qemu-system-x86_64 -enable-kvm -cpu host -smp 4 -m 10G \ |
| 77 | + -drive file=root.img,if=virtio,cache=unsafe -nic user,model=virtio,hostfwd=:127.0.0.1:222-:22 \ |
| 78 | + -daemonize -vga none -display none |
| 79 | + until ssh -oStrictHostKeyChecking=no -p222 [email protected] : 2>/dev/null; do sleep 1; done |
| 80 | + - name: Time Synchronization |
| 81 | + shell: vmbash.sh {0} |
| 82 | + run: | |
| 83 | + exec 2>&1 |
| 84 | + until [ "$(set -x; timedatectl show --value -pNTPSynchronized)" = yes ]; do (set -x; sleep 1) done |
| 85 | +
|
| 86 | + - name: Checkout |
| 87 | + uses: actions/checkout@v4 |
| 88 | + with: { ref: master } |
| 89 | + - name: Upload to Guest |
| 90 | + run: | |
| 91 | + exec 2>&1 |
| 92 | + set -x |
| 93 | + cd .. |
| 94 | + tar c --{owner,group}=0 manool | ssh -p222 [email protected] tar x |
| 95 | +
|
| 96 | + - name: Build and Test |
| 97 | + shell: vmbash.sh {0} |
| 98 | + run: | |
| 99 | + exec 2>&1 |
| 100 | + set -x |
| 101 | + make -Cmanool -j4 run \ |
| 102 | + GCC='${{matrix.compiler.gcc}}' GXX='${{matrix.compiler.gxx}}' \ |
| 103 | + MARCH='${{matrix.march.flags}}' |
| 104 | +
|
| 105 | + - name: Download from Guest |
| 106 | + run: | |
| 107 | + exec 2>&1 |
| 108 | + set -x |
| 109 | + cd .. |
| 110 | + rm -r manool |
| 111 | + ssh -p222 [email protected] tar c --{owner,group}=0 manool | tar x |
| 112 | + - name: Upload Results |
| 113 | + uses: actions/upload-artifact@v4 |
| 114 | + with: |
| 115 | + name: build-${{matrix.compiler.label}}-${{matrix.march.label}} |
| 116 | + path: build |
| 117 | + |
| 118 | + qemu-cache: |
| 119 | + name: Prepare Guest VM |
| 120 | + runs-on: ubuntu-latest |
| 121 | + |
| 122 | + defaults: |
| 123 | + run: { shell: bash } |
| 124 | + steps: |
| 125 | + |
| 126 | + - *minfo |
| 127 | + - *sinfo |
| 128 | + - *cinfo |
| 129 | + - name: Cache Object Lookup |
| 130 | + id: cache |
| 131 | + uses: actions/cache@v4 |
| 132 | + with: |
| 133 | + key: ubuntu-focal-cloud-generic |
| 134 | + path: | |
| 135 | + ~/root.img |
| 136 | + ~/.ssh/id_rsa |
| 137 | + /usr/local/bin/vmbash.sh |
| 138 | + lookup-only: TRUE |
| 139 | + |
| 140 | + - name: Host Setup |
| 141 | + if: steps.cache.outputs.cache-hit != 'true' |
| 142 | + run: | |
| 143 | + exec 2>&1 |
| 144 | + set -x |
| 145 | + sudo sed -i /azure/d /etc/apt/apt-mirrors.txt |
| 146 | + sudo apt-get update |
| 147 | + sudo apt-get install --no-install-recommends qemu-system-x86 cloud-image-utils |
| 148 | + - name: QEMU Information |
| 149 | + if: steps.cache.outputs.cache-hit != 'true' |
| 150 | + run: | |
| 151 | + exec 2>&1 |
| 152 | + qemu-system-x86_64 --version |
| 153 | +
|
| 154 | + - name: Deploy and Start Guest |
| 155 | + if: steps.cache.outputs.cache-hit != 'true' |
| 156 | + run: | |
| 157 | + exec 2>&1 |
| 158 | + set -x |
| 159 | + cd |
| 160 | +
|
| 161 | + wget --no-show-progress -O root.img \ |
| 162 | + https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img |
| 163 | + qemu-img resize root.img 6G |
| 164 | +
|
| 165 | + mkdir -m700 .ssh |
| 166 | + ssh-keygen -N '' -t ed25519 -f .ssh/id_rsa |
| 167 | + cloud-localds seed.iso - <<END |
| 168 | + #cloud-config |
| 169 | + users: |
| 170 | + - name: root |
| 171 | + ssh_authorized_keys: [ '$(<.ssh/id_rsa.pub)' ] |
| 172 | + END |
| 173 | +
|
| 174 | + sudo qemu-system-x86_64 -enable-kvm -cpu host -smp 4 -m 10G \ |
| 175 | + -drive file=root.img,if=virtio,cache=unsafe -nic user,model=virtio,hostfwd=:127.0.0.1:222-:22 \ |
| 176 | + -daemonize -vga none -display none -cdrom seed.iso |
| 177 | + until ssh -oStrictHostKeyChecking=no -p222 [email protected] : 2>/dev/null; do sleep 1; done |
| 178 | +
|
| 179 | + tee /usr/local/bin/vmbash.sh <<'END' >/dev/null; chmod +x /usr/local/bin/vmbash.sh |
| 180 | + #!/bin/bash |
| 181 | + ssh -p222 [email protected] bash --noprofile --norc -e -o pipefail <$1 |
| 182 | + END |
| 183 | +
|
| 184 | + - name: Time Synchronization |
| 185 | + if: steps.cache.outputs.cache-hit != 'true' |
| 186 | + shell: vmbash.sh {0} |
| 187 | + run: | |
| 188 | + exec 2>&1 |
| 189 | + until [ "$(set -x; timedatectl show --value -pNTPSynchronized)" = yes ]; do (set -x; sleep 1) done |
| 190 | +
|
| 191 | + - name: Guest Information |
| 192 | + if: steps.cache.outputs.cache-hit != 'true' |
| 193 | + shell: vmbash.sh {0} |
| 194 | + run: | |
| 195 | + exec 2>&1 |
| 196 | + set -x |
| 197 | + lscpu; free -h; df -H . |
| 198 | + - name: Guest Setup |
| 199 | + if: steps.cache.outputs.cache-hit != 'true' |
| 200 | + shell: vmbash.sh {0} |
| 201 | + run: | |
| 202 | + exec 2>&1 |
| 203 | + set -x |
| 204 | + apt-get update |
| 205 | + apt-get -y install make g++{,-10}-multilib clang-18 |
| 206 | + make --version; g++ --version; g++-10 --version; clang++-18 --version |
| 207 | + |
| 208 | + - name: Guest Shutdown |
| 209 | + if: steps.cache.outputs.cache-hit != 'true' |
| 210 | + run: | |
| 211 | + exec 2>&1 |
| 212 | + (set -x; ssh -p222 [email protected] poweroff) || : |
| 213 | + while [ "$(set -x; sudo lsof -w ~/root.img)" ]; do (set -x; sleep 1) done |
0 commit comments