|
| 1 | +name: PR Cross-OS Smoke Test |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: read |
| 9 | + pull-requests: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + smoke: |
| 13 | + name: Smoke (Runner ${{ matrix.os }}) |
| 14 | + runs-on: ${{ matrix.os }} |
| 15 | + strategy: |
| 16 | + fail-fast: false |
| 17 | + matrix: |
| 18 | + os: [ubuntu-latest, windows-latest] |
| 19 | + env: |
| 20 | + CGO_ENABLED: 0 |
| 21 | + steps: |
| 22 | + - name: Checkout |
| 23 | + uses: actions/checkout@v4 |
| 24 | + |
| 25 | + - name: Setup Go |
| 26 | + uses: actions/setup-go@v5 |
| 27 | + with: |
| 28 | + go-version: '1.22' |
| 29 | + check-latest: true |
| 30 | + |
| 31 | + - name: Setup Node |
| 32 | + uses: actions/setup-node@v4 |
| 33 | + with: |
| 34 | + node-version: '20' |
| 35 | + cache: 'npm' |
| 36 | + cache-dependency-path: 'frontend/package-lock.json' |
| 37 | + continue-on-error: true |
| 38 | + |
| 39 | + - name: Install frontend deps |
| 40 | + working-directory: frontend |
| 41 | + run: | |
| 42 | + if [ -f package.json ]; then npm ci || npm install; fi |
| 43 | + shell: bash |
| 44 | + |
| 45 | + - name: Build frontend |
| 46 | + working-directory: frontend |
| 47 | + run: | |
| 48 | + if [ -f package.json ]; then npm run build || echo 'frontend build failed (continuing)'; fi |
| 49 | + shell: bash |
| 50 | + |
| 51 | + - name: Smoke test |
| 52 | + run: bash ./.github/scripts/run-smoke.sh |
| 53 | + shell: bash |
| 54 | + |
| 55 | + - name: Collect results |
| 56 | + if: always() |
| 57 | + id: collect |
| 58 | + run: | |
| 59 | + echo "status=$(cat smoke-logs/result.txt 2>/dev/null || echo 'missing')" >> $GITHUB_OUTPUT |
| 60 | + echo "status_json=$(cat smoke-logs/status.json 2>/dev/null || echo '{}')" >> $GITHUB_OUTPUT |
| 61 | + shell: bash |
| 62 | + |
| 63 | + - name: Upload logs |
| 64 | + if: always() |
| 65 | + uses: actions/upload-artifact@v4 |
| 66 | + with: |
| 67 | + name: smoke-${{ matrix.os }} |
| 68 | + path: | |
| 69 | + smoke-logs/server.log |
| 70 | + smoke-logs/status.json |
| 71 | + smoke-logs/result.txt |
| 72 | + if-no-files-found: warn |
| 73 | + |
| 74 | + smoke-linux-distros: |
| 75 | + name: Smoke (Container ${{ matrix.distro }}) |
| 76 | + runs-on: ubuntu-latest |
| 77 | + strategy: |
| 78 | + fail-fast: false |
| 79 | + matrix: |
| 80 | + include: |
| 81 | + - distro: debian |
| 82 | + image: debian:trixie |
| 83 | + pkg_update: apt-get update |
| 84 | + install: apt-get install -y --no-install-recommends ca-certificates curl git build-essential wget nodejs npm bash |
| 85 | + needs_go: true |
| 86 | + - distro: arch |
| 87 | + image: archlinux:base |
| 88 | + pkg_update: pacman -Sy --noconfirm |
| 89 | + install: pacman -S --noconfirm ca-certificates curl git wget tar nodejs npm go base-devel bash |
| 90 | + needs_go: false |
| 91 | + container: |
| 92 | + image: ${{ matrix.image }} |
| 93 | + env: |
| 94 | + GO_VERSION: '1.22.6' |
| 95 | + CGO_ENABLED: 0 |
| 96 | + steps: |
| 97 | + - name: Prepare packages |
| 98 | + run: | |
| 99 | + set -e |
| 100 | + ${{ matrix.pkg_update }} |
| 101 | + ${{ matrix.install }} |
| 102 | + - name: Install Go (if needed) |
| 103 | + if: matrix.needs_go == true |
| 104 | + run: | |
| 105 | + set -e |
| 106 | + ARCH=$(uname -m) |
| 107 | + case "$ARCH" in |
| 108 | + x86_64) GOARCH=amd64 ;; |
| 109 | + aarch64) GOARCH=arm64 ;; |
| 110 | + *) echo "Unsupported arch: $ARCH"; exit 1 ;; |
| 111 | + esac |
| 112 | + curl -fsSL https://go.dev/dl/go${GO_VERSION}.linux-${GOARCH}.tar.gz -o /tmp/go.tgz |
| 113 | + rm -rf /usr/local/go && tar -C /usr/local -xzf /tmp/go.tgz |
| 114 | + echo "/usr/local/go/bin" >> $GITHUB_PATH |
| 115 | + /usr/local/go/bin/go version |
| 116 | + - name: Add Go to PATH (arch already has go) |
| 117 | + if: matrix.needs_go == false |
| 118 | + run: which go || echo "go not found" || true |
| 119 | + - name: Checkout |
| 120 | + uses: actions/checkout@v4 |
| 121 | + - name: Node version |
| 122 | + run: node --version && npm --version || true |
| 123 | + - name: Install frontend deps |
| 124 | + working-directory: frontend |
| 125 | + run: | |
| 126 | + if [ -f package.json ]; then npm ci || npm install; fi |
| 127 | + - name: Build frontend |
| 128 | + working-directory: frontend |
| 129 | + run: | |
| 130 | + if [ -f package.json ]; then npm run build || echo 'frontend build failed (continuing)'; fi |
| 131 | + - name: Run smoke test |
| 132 | + run: bash ./.github/scripts/run-smoke.sh |
| 133 | + - name: Collect results |
| 134 | + if: always() |
| 135 | + id: collect |
| 136 | + run: | |
| 137 | + echo "status=$(cat smoke-logs/result.txt 2>/dev/null || echo 'missing')" >> $GITHUB_OUTPUT |
| 138 | + echo "status_json=$(cat smoke-logs/status.json 2>/dev/null || echo '{}')" >> $GITHUB_OUTPUT |
| 139 | + - name: Upload logs |
| 140 | + if: always() |
| 141 | + uses: actions/upload-artifact@v4 |
| 142 | + with: |
| 143 | + name: smoke-${{ matrix.distro }} |
| 144 | + path: | |
| 145 | + smoke-logs/server.log |
| 146 | + smoke-logs/status.json |
| 147 | + smoke-logs/result.txt |
| 148 | + if-no-files-found: warn |
| 149 | + |
| 150 | + summarize: |
| 151 | + name: Summarize & Comment |
| 152 | + needs: [smoke, smoke-linux-distros] |
| 153 | + runs-on: ubuntu-latest |
| 154 | + permissions: |
| 155 | + pull-requests: write |
| 156 | + contents: read |
| 157 | + steps: |
| 158 | + - name: Download artifacts |
| 159 | + uses: actions/download-artifact@v4 |
| 160 | + with: |
| 161 | + path: artifacts |
| 162 | + |
| 163 | + - name: Build summary |
| 164 | + id: summary |
| 165 | + run: | |
| 166 | + set -e |
| 167 | + echo '### Cross-OS Smoke Test Results' > summary.md |
| 168 | + echo '' >> summary.md |
| 169 | + STATUS_TABLE="| OS | Status | Details |\n|----|--------|---------|" |
| 170 | + for dir in artifacts/*; do |
| 171 | + osname=$(basename "$dir" | sed 's/^smoke-//') |
| 172 | + resultFile=$(find "$dir" -name result.txt -maxdepth 2 -type f 2>/dev/null | head -n1) |
| 173 | + logFile=$(find "$dir" -name server.log -maxdepth 2 -type f 2>/dev/null | head -n1) |
| 174 | + status="missing" |
| 175 | + if [ -f "$resultFile" ]; then status=$(cat "$resultFile"); fi |
| 176 | + detailsLink="(logs unavailable)" |
| 177 | + if [ -f "$logFile" ]; then |
| 178 | + head -n5 "$logFile" > "$dir/head.txt" || true |
| 179 | + tail -n5 "$logFile" > "$dir/tail.txt" || true |
| 180 | + detailsLink="See below" |
| 181 | + fi |
| 182 | + STATUS_TABLE+="\n| $osname | $status | $detailsLink |" |
| 183 | + done |
| 184 | + echo "$STATUS_TABLE" >> summary.md |
| 185 | + echo '' >> summary.md |
| 186 | + echo '<details><summary>Log excerpts</summary>' >> summary.md |
| 187 | + for dir in artifacts/*; do |
| 188 | + osname=$(basename "$dir" | sed 's/^smoke-//') |
| 189 | + logFile=$(find "$dir" -name server.log -maxdepth 2 -type f 2>/dev/null | head -n1) |
| 190 | + if [ -f "$logFile" ]; then |
| 191 | + echo "\n#### $osname" >> summary.md |
| 192 | + echo '\n<details><summary>First 5 lines</summary>' >> summary.md |
| 193 | + echo '\n```' >> summary.md |
| 194 | + cat "$dir/head.txt" >> summary.md |
| 195 | + echo '```' >> summary.md |
| 196 | + echo '</details>' >> summary.md |
| 197 | + echo '\n<details><summary>Last 5 lines</summary>' >> summary.md |
| 198 | + echo '\n```' >> summary.md |
| 199 | + cat "$dir/tail.txt" >> summary.md |
| 200 | + echo '```' >> summary.md |
| 201 | + echo '</details>' >> summary.md |
| 202 | + fi |
| 203 | + done |
| 204 | + echo '\n</details>' >> summary.md |
| 205 | + SUMMARY_BODY=$(cat summary.md) |
| 206 | + SUMMARY_BODY_ESCAPED=$(printf '%s' "$SUMMARY_BODY" | sed -e ':a' -e 'N' -e '$!ba' -e 's/%/%25/g' -e 's/\n/%0A/g' -e 's/\r/%0D/g') |
| 207 | + echo "body=$SUMMARY_BODY_ESCAPED" >> $GITHUB_OUTPUT |
| 208 | +
|
| 209 | + - name: Create or update PR comment |
| 210 | + uses: actions/github-script@v7 |
| 211 | + with: |
| 212 | + script: | |
| 213 | + const markerStart = '<!-- smoke-test-report-start -->'; |
| 214 | + const markerEnd = '<!-- smoke-test-report-end -->'; |
| 215 | + const body = process.env.SUMMARY_BODY || `\n${{ steps.summary.outputs.body }}`; |
| 216 | + const {owner, repo, number} = context.issue; |
| 217 | + const { data: comments } = await github.rest.issues.listComments({owner, repo, issue_number: number, per_page: 100}); |
| 218 | + const existing = comments.find(c => c.body && c.body.includes(markerStart)); |
| 219 | + const finalBody = `${markerStart}\n${body}\n${markerEnd}`; |
| 220 | + if (existing) { |
| 221 | + await github.rest.issues.updateComment({owner, repo, comment_id: existing.id, body: finalBody}); |
| 222 | + } else { |
| 223 | + await github.rest.issues.createComment({owner, repo, issue_number: number, body: finalBody}); |
| 224 | + } |
| 225 | + env: |
| 226 | + SUMMARY_BODY: ${{ steps.summary.outputs.body }} |
0 commit comments