|
| 1 | +name: Build & Publish QEMU Emulator Images |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - dev |
| 8 | + pull_request: |
| 9 | + paths: |
| 10 | + - 'docker/local-emulator/**' |
| 11 | + - '.github/workflows/qemu-emulator-build.yaml' |
| 12 | + workflow_dispatch: |
| 13 | + inputs: |
| 14 | + publish: |
| 15 | + description: 'Publish images to GitHub Releases' |
| 16 | + type: boolean |
| 17 | + default: false |
| 18 | + |
| 19 | +concurrency: |
| 20 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 21 | + cancel-in-progress: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/dev' }} |
| 22 | + |
| 23 | +env: |
| 24 | + EMULATOR_IMAGE_NAME: stack-local-emulator |
| 25 | + |
| 26 | +jobs: |
| 27 | + build: |
| 28 | + name: Build QEMU Image (${{ matrix.arch }}) |
| 29 | + runs-on: ubicloud-standard-8 |
| 30 | + timeout-minutes: 120 |
| 31 | + strategy: |
| 32 | + fail-fast: false |
| 33 | + matrix: |
| 34 | + include: |
| 35 | + - arch: amd64 |
| 36 | + - arch: arm64 |
| 37 | + |
| 38 | + steps: |
| 39 | + - uses: actions/checkout@v6 |
| 40 | + |
| 41 | + - name: Set up QEMU user-mode emulation |
| 42 | + uses: docker/setup-qemu-action@v3 |
| 43 | + |
| 44 | + - name: Set up Docker Buildx |
| 45 | + uses: docker/setup-buildx-action@v3 |
| 46 | + |
| 47 | + - name: Install QEMU dependencies |
| 48 | + run: | |
| 49 | + sudo apt-get update |
| 50 | + sudo apt-get install -y qemu-system-x86 qemu-system-arm qemu-utils genisoimage socat qemu-efi-aarch64 |
| 51 | +
|
| 52 | + - name: Build QEMU image |
| 53 | + run: | |
| 54 | + chmod +x docker/local-emulator/qemu/build-image.sh |
| 55 | + EMULATOR_PROVISION_TIMEOUT=6000 \ |
| 56 | + docker/local-emulator/qemu/build-image.sh ${{ matrix.arch }} |
| 57 | +
|
| 58 | + - name: Generate emulator env |
| 59 | + run: node docker/local-emulator/generate-env-development.mjs |
| 60 | + |
| 61 | + - name: Start emulator and verify |
| 62 | + run: | |
| 63 | + chmod +x docker/local-emulator/qemu/run-emulator.sh |
| 64 | + EMULATOR_ARCH=${{ matrix.arch }} \ |
| 65 | + EMULATOR_READY_TIMEOUT=3200 \ |
| 66 | + docker/local-emulator/qemu/run-emulator.sh start |
| 67 | +
|
| 68 | + - name: Verify services are healthy |
| 69 | + run: | |
| 70 | + EMULATOR_ARCH=${{ matrix.arch }} \ |
| 71 | + docker/local-emulator/qemu/run-emulator.sh status |
| 72 | +
|
| 73 | + - name: Stop emulator |
| 74 | + if: always() |
| 75 | + run: | |
| 76 | + EMULATOR_ARCH=${{ matrix.arch }} \ |
| 77 | + docker/local-emulator/qemu/run-emulator.sh stop |
| 78 | +
|
| 79 | + - name: Package image |
| 80 | + run: | |
| 81 | + BASE_IMG="docker/local-emulator/qemu/images/stack-emulator-${{ matrix.arch }}.qcow2" |
| 82 | + cp "$BASE_IMG" "stack-emulator-${{ matrix.arch }}.qcow2" |
| 83 | +
|
| 84 | + - name: Upload image artifact |
| 85 | + uses: actions/upload-artifact@v4 |
| 86 | + with: |
| 87 | + name: qemu-emulator-${{ matrix.arch }} |
| 88 | + path: stack-emulator-${{ matrix.arch }}.qcow2 |
| 89 | + retention-days: 30 |
| 90 | + compression-level: 0 |
| 91 | + |
| 92 | + test: |
| 93 | + name: Smoke Test (${{ matrix.arch }}) |
| 94 | + needs: build |
| 95 | + runs-on: ubicloud-standard-8 |
| 96 | + timeout-minutes: 60 |
| 97 | + strategy: |
| 98 | + fail-fast: false |
| 99 | + matrix: |
| 100 | + include: |
| 101 | + - arch: amd64 |
| 102 | + |
| 103 | + steps: |
| 104 | + - uses: actions/checkout@v6 |
| 105 | + |
| 106 | + - name: Install QEMU dependencies |
| 107 | + run: | |
| 108 | + sudo apt-get update |
| 109 | + sudo apt-get install -y qemu-system-x86 qemu-utils genisoimage socat |
| 110 | +
|
| 111 | + - name: Download built image |
| 112 | + uses: actions/download-artifact@v4 |
| 113 | + with: |
| 114 | + name: qemu-emulator-${{ matrix.arch }} |
| 115 | + path: docker/local-emulator/qemu/images/ |
| 116 | + |
| 117 | + - name: Generate emulator env |
| 118 | + run: node docker/local-emulator/generate-env-development.mjs |
| 119 | + |
| 120 | + - name: Start emulator from artifact |
| 121 | + run: | |
| 122 | + chmod +x docker/local-emulator/qemu/run-emulator.sh docker/local-emulator/qemu/common.sh |
| 123 | + EMULATOR_ARCH=${{ matrix.arch }} \ |
| 124 | + EMULATOR_READY_TIMEOUT=600 \ |
| 125 | + docker/local-emulator/qemu/run-emulator.sh start |
| 126 | +
|
| 127 | + - name: Verify services are healthy |
| 128 | + run: | |
| 129 | + EMULATOR_ARCH=${{ matrix.arch }} \ |
| 130 | + docker/local-emulator/qemu/run-emulator.sh status |
| 131 | +
|
| 132 | + - name: Smoke test — backend health |
| 133 | + run: curl -sf http://localhost:26701/health?db=1 |
| 134 | + |
| 135 | + - name: Smoke test — dashboard reachable |
| 136 | + run: curl -sf -o /dev/null -w "HTTP %{http_code}\n" http://localhost:26700/handler/sign-in |
| 137 | + |
| 138 | + - name: Smoke test — MinIO health |
| 139 | + run: curl -sf http://localhost:26702/minio/health/live |
| 140 | + |
| 141 | + - name: Smoke test — Inbucket reachable |
| 142 | + run: curl -sf -o /dev/null -w "HTTP %{http_code}\n" http://localhost:26703/ |
| 143 | + |
| 144 | + - name: Stop emulator |
| 145 | + if: always() |
| 146 | + run: | |
| 147 | + EMULATOR_ARCH=${{ matrix.arch }} \ |
| 148 | + docker/local-emulator/qemu/run-emulator.sh stop |
| 149 | +
|
| 150 | + - name: Print serial log on failure |
| 151 | + if: failure() |
| 152 | + run: tail -100 docker/local-emulator/qemu/run/vm/serial.log 2>/dev/null || true |
| 153 | + |
| 154 | + publish: |
| 155 | + name: Publish to GitHub Releases |
| 156 | + needs: [build, test] |
| 157 | + if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev' || (github.event_name == 'workflow_dispatch' && inputs.publish) |
| 158 | + runs-on: ubuntu-latest |
| 159 | + permissions: |
| 160 | + contents: write |
| 161 | + |
| 162 | + steps: |
| 163 | + - uses: actions/checkout@v6 |
| 164 | + |
| 165 | + - name: Download all artifacts |
| 166 | + uses: actions/download-artifact@v4 |
| 167 | + with: |
| 168 | + path: artifacts |
| 169 | + |
| 170 | + - name: Prepare release assets |
| 171 | + run: | |
| 172 | + mkdir -p release |
| 173 | + SHORT_SHA="${GITHUB_SHA:0:8}" |
| 174 | + BRANCH="${GITHUB_REF_NAME}" |
| 175 | + DATE="$(date -u +%Y%m%d)" |
| 176 | + TAG="emulator-${BRANCH}-${DATE}-${SHORT_SHA}" |
| 177 | + echo "RELEASE_TAG=${TAG}" >> "$GITHUB_ENV" |
| 178 | + echo "SHORT_SHA=${SHORT_SHA}" >> "$GITHUB_ENV" |
| 179 | +
|
| 180 | + for f in artifacts/qemu-emulator-*/*.qcow2; do |
| 181 | + cp "$f" release/ |
| 182 | + done |
| 183 | +
|
| 184 | + cat > release-notes.md <<EOF |
| 185 | + ## QEMU Emulator Images |
| 186 | +
|
| 187 | + Built from \`${BRANCH}\` @ \`${GITHUB_SHA}\` |
| 188 | +
|
| 189 | + ### Images |
| 190 | + | File | Description | |
| 191 | + |------|-------------| |
| 192 | + | \`stack-emulator-arm64.qcow2\` | ARM64 emulator image | |
| 193 | + | \`stack-emulator-amd64.qcow2\` | AMD64 emulator image | |
| 194 | +
|
| 195 | + ### Usage |
| 196 | + \`\`\`bash |
| 197 | + stack emulator pull |
| 198 | + stack emulator start |
| 199 | + \`\`\` |
| 200 | + EOF |
| 201 | +
|
| 202 | + ls -lh release/ |
| 203 | +
|
| 204 | + - name: Create or update GitHub Release |
| 205 | + env: |
| 206 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 207 | + run: | |
| 208 | + TITLE="QEMU Emulator — ${{ github.ref_name }} ($SHORT_SHA)" |
| 209 | +
|
| 210 | + if gh release view "$RELEASE_TAG" >/dev/null 2>&1; then |
| 211 | + gh release edit "$RELEASE_TAG" \ |
| 212 | + --title "$TITLE" \ |
| 213 | + --notes-file release-notes.md \ |
| 214 | + --prerelease |
| 215 | + gh release upload "$RELEASE_TAG" release/* --clobber |
| 216 | + else |
| 217 | + gh release create "$RELEASE_TAG" \ |
| 218 | + --title "$TITLE" \ |
| 219 | + --notes-file release-notes.md \ |
| 220 | + --prerelease \ |
| 221 | + release/* |
| 222 | + fi |
| 223 | +
|
| 224 | + - name: Update latest tag for branch |
| 225 | + env: |
| 226 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 227 | + run: | |
| 228 | + LATEST_TAG="emulator-${{ github.ref_name }}-latest" |
| 229 | + TITLE="QEMU Emulator — ${{ github.ref_name }} (latest)" |
| 230 | + NOTES="Latest emulator images from \`${{ github.ref_name }}\`. Auto-updated on each build." |
| 231 | +
|
| 232 | + if gh release view "$LATEST_TAG" >/dev/null 2>&1; then |
| 233 | + gh release edit "$LATEST_TAG" \ |
| 234 | + --draft \ |
| 235 | + --prerelease \ |
| 236 | + --target "${{ github.sha }}" \ |
| 237 | + --title "$TITLE" \ |
| 238 | + --notes "$NOTES" |
| 239 | + else |
| 240 | + gh release create "$LATEST_TAG" \ |
| 241 | + --draft \ |
| 242 | + --prerelease \ |
| 243 | + --target "${{ github.sha }}" \ |
| 244 | + --title "$TITLE" \ |
| 245 | + --notes "$NOTES" \ |
| 246 | + || gh release edit "$LATEST_TAG" \ |
| 247 | + --draft \ |
| 248 | + --prerelease \ |
| 249 | + --target "${{ github.sha }}" \ |
| 250 | + --title "$TITLE" \ |
| 251 | + --notes "$NOTES" |
| 252 | + fi |
| 253 | +
|
| 254 | + gh release upload "$LATEST_TAG" release/* --clobber |
| 255 | + gh release edit "$LATEST_TAG" --draft=false --prerelease |
0 commit comments