|
| 1 | +name: Build (UI) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + paths: |
| 7 | + - "packages/ui/**" |
| 8 | + pull_request: |
| 9 | + branches: [main] |
| 10 | + paths: |
| 11 | + - "packages/ui/**" |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: build-ui-${{ github.ref }} |
| 15 | + cancel-in-progress: true |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: read |
| 19 | + pull-requests: write |
| 20 | + |
| 21 | +jobs: |
| 22 | + build: |
| 23 | + name: Build (UI) |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - uses: oven-sh/setup-bun@v2 |
| 29 | + with: |
| 30 | + bun-version: "1.2.6" |
| 31 | + |
| 32 | + - name: Install dependencies |
| 33 | + shell: bash |
| 34 | + run: | |
| 35 | + set -euo pipefail |
| 36 | + bun install --frozen-lockfile |
| 37 | + for pkg in packages/*; do |
| 38 | + [ -f "$pkg/package.json" ] || continue |
| 39 | + grep -q '"file:' "$pkg/package.json" || continue |
| 40 | + grep -oP '"[^"]+": "file:\K[^"]+' "$pkg/package.json" | while read -r dep; do |
| 41 | + name=$(jq -r .name "$pkg/$dep/package.json") |
| 42 | + scope_dir="$pkg/node_modules/$(dirname "$name")" |
| 43 | + mkdir -p "$scope_dir" |
| 44 | + ln -sfn "$(cd "$pkg/$dep" && pwd)" "$pkg/node_modules/$name" |
| 45 | + done |
| 46 | + done |
| 47 | +
|
| 48 | + - name: Run build |
| 49 | + id: build |
| 50 | + continue-on-error: true |
| 51 | + working-directory: packages/ui |
| 52 | + shell: bash |
| 53 | + run: | |
| 54 | + set -o pipefail |
| 55 | + bun run build 2>&1 | tee "$GITHUB_WORKSPACE/build-ui-output.txt" |
| 56 | +
|
| 57 | + - name: Process results |
| 58 | + id: result |
| 59 | + shell: bash |
| 60 | + run: | |
| 61 | + set -euo pipefail |
| 62 | + if [ "${{ steps.build.outcome }}" = "success" ]; then |
| 63 | + echo "status=Passed" >> "$GITHUB_OUTPUT" |
| 64 | + echo "details=" >> "$GITHUB_OUTPUT" |
| 65 | + else |
| 66 | + echo "status=Failed" >> "$GITHUB_OUTPUT" |
| 67 | + echo "details=Build failed" >> "$GITHUB_OUTPUT" |
| 68 | + fi |
| 69 | +
|
| 70 | + - name: Upload build output |
| 71 | + if: always() |
| 72 | + uses: actions/upload-artifact@v4 |
| 73 | + with: |
| 74 | + name: build-ui-output |
| 75 | + path: build-ui-output.txt |
| 76 | + retention-days: 7 |
| 77 | + |
| 78 | + - name: Upload artifacts |
| 79 | + if: steps.build.outcome == 'success' |
| 80 | + uses: actions/upload-artifact@v4 |
| 81 | + with: |
| 82 | + name: ui-dist |
| 83 | + path: packages/ui/dist |
| 84 | + retention-days: 7 |
| 85 | + |
| 86 | + - name: Update PR comment |
| 87 | + if: github.event_name == 'pull_request' |
| 88 | + uses: actions/github-script@v7 |
| 89 | + env: |
| 90 | + SECTION: Build (UI) |
| 91 | + STATUS: ${{ steps.result.outputs.status }} |
| 92 | + DETAILS: ${{ steps.result.outputs.details }} |
| 93 | + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| 94 | + with: |
| 95 | + script: | |
| 96 | + const fs = require("fs"); |
| 97 | +
|
| 98 | + const marker = "<!-- ci-summary -->"; |
| 99 | + const detailsMarker = "<!-- details-section -->"; |
| 100 | + const section = process.env.SECTION; |
| 101 | + const status = process.env.STATUS; |
| 102 | + const details = process.env.DETAILS; |
| 103 | + const runUrl = process.env.RUN_URL; |
| 104 | +
|
| 105 | + const { owner, repo } = context.repo; |
| 106 | + const issue_number = context.payload.pull_request.number; |
| 107 | +
|
| 108 | + let output = ""; |
| 109 | + try { |
| 110 | + output = fs.readFileSync("build-ui-output.txt", "utf8"); |
| 111 | + } catch (_) { |
| 112 | + output = "(build-ui-output.txt not found)"; |
| 113 | + } |
| 114 | +
|
| 115 | + const MAX_CHARS = 60000; |
| 116 | + if (output.length > MAX_CHARS) { |
| 117 | + output = [ |
| 118 | + "(truncated; showing last " + MAX_CHARS + " chars)", |
| 119 | + "", |
| 120 | + output.slice(-MAX_CHARS), |
| 121 | + ].join("\n"); |
| 122 | + } |
| 123 | +
|
| 124 | + const comments = await github.paginate(github.rest.issues.listComments, { |
| 125 | + owner, repo, issue_number, per_page: 100, |
| 126 | + }); |
| 127 | +
|
| 128 | + const existing = comments.find(c => |
| 129 | + c.user?.login === "github-actions[bot]" && c.body?.includes(marker) |
| 130 | + ); |
| 131 | +
|
| 132 | + let rows = {}; |
| 133 | + let existingDetails = {}; |
| 134 | +
|
| 135 | + if (existing?.body) { |
| 136 | + const parts = existing.body.split(detailsMarker); |
| 137 | + const tableSection = parts[0] || ""; |
| 138 | +
|
| 139 | + const lines = tableSection.split("\n"); |
| 140 | + for (const line of lines) { |
| 141 | + const match = line.match(/^\| ([^|]+) \| ([^|]+) \|$/); |
| 142 | + if (match) { |
| 143 | + const name = match[1].trim(); |
| 144 | + if (name && name !== "Check" && !name.startsWith(":")) { |
| 145 | + rows[name] = match[2].trim(); |
| 146 | + } |
| 147 | + } |
| 148 | + } |
| 149 | +
|
| 150 | + const detailsRegex = /<details>\s*<summary><strong>([^<]+)<\/strong>.*?<\/summary>([\s\S]*?)<\/details>/g; |
| 151 | + let detailMatch; |
| 152 | + while ((detailMatch = detailsRegex.exec(existing.body)) !== null) { |
| 153 | + existingDetails[detailMatch[1].trim()] = detailMatch[0]; |
| 154 | + } |
| 155 | + } |
| 156 | +
|
| 157 | + const resultText = status === "Passed" ? "Passed" : "Failed"; |
| 158 | + rows[section] = status === "Passed" ? resultText : `[${resultText}](${runUrl}) - ${details}`; |
| 159 | +
|
| 160 | + if (status === "Failed") { |
| 161 | + existingDetails[section] = [ |
| 162 | + `<details>`, |
| 163 | + `<summary><strong>${section}</strong> - ${resultText}</summary>`, |
| 164 | + "", |
| 165 | + details || "Failed", |
| 166 | + "", |
| 167 | + `[View run](${runUrl})`, |
| 168 | + "", |
| 169 | + "```text", |
| 170 | + output, |
| 171 | + "```", |
| 172 | + "</details>", |
| 173 | + ].join("\n"); |
| 174 | + } else { |
| 175 | + delete existingDetails[section]; |
| 176 | + } |
| 177 | +
|
| 178 | + const order = ["Lint", "Lint (UI)", "Format", "Format (UI)", "Typecheck", "Typecheck (UI)", "Build", "Build (UI)", "Test", "Release", "Deploy UI", "Deploy Example", "PR Title", "Labels"]; |
| 179 | + const sortedKeys = Object.keys(rows).sort((a, b) => { |
| 180 | + const ai = order.indexOf(a), bi = order.indexOf(b); |
| 181 | + return (ai === -1 ? 999 : ai) - (bi === -1 ? 999 : bi); |
| 182 | + }); |
| 183 | +
|
| 184 | + let table = `| Check | Result |\n|:------|:-------|\n`; |
| 185 | + for (const key of sortedKeys) { |
| 186 | + table += `| ${key} | ${rows[key]} |\n`; |
| 187 | + } |
| 188 | +
|
| 189 | + const detailsOrder = ["Lint", "Lint (UI)", "Format", "Format (UI)", "Typecheck", "Typecheck (UI)", "Build", "Build (UI)", "Test", "Release", "Deploy UI", "Deploy Example", "PR Title", "Labels"]; |
| 190 | + const sortedDetails = Object.keys(existingDetails).sort((a, b) => { |
| 191 | + const ai = detailsOrder.indexOf(a), bi = detailsOrder.indexOf(b); |
| 192 | + return (ai === -1 ? 999 : ai) - (bi === -1 ? 999 : bi); |
| 193 | + }); |
| 194 | +
|
| 195 | + let body = `${marker}\n## CI Summary\n\n${table}`; |
| 196 | +
|
| 197 | + if (sortedDetails.length > 0) { |
| 198 | + body += `\n${detailsMarker}\n\n---\n\n${sortedDetails.map(k => existingDetails[k]).join("\n\n")}`; |
| 199 | + } |
| 200 | +
|
| 201 | + if (existing) { |
| 202 | + await github.rest.issues.updateComment({ owner, repo, comment_id: existing.id, body }); |
| 203 | + } else { |
| 204 | + await github.rest.issues.createComment({ owner, repo, issue_number, body }); |
| 205 | + } |
| 206 | +
|
| 207 | + - name: Fail if build failed |
| 208 | + if: steps.build.outcome == 'failure' |
| 209 | + run: exit 1 |
0 commit comments