* POST the multipart form. Returns the parsed 202 response body.
(bundles)
| 129 | * POST the multipart form. Returns the parsed 202 response body. |
| 130 | */ |
| 131 | async function uploadBundles(bundles) { |
| 132 | const metadata = { |
| 133 | commit: process.env.GITHUB_SHA ?? 'unknown', |
| 134 | branch: process.env.GITHUB_REF_NAME ?? 'unknown', |
| 135 | triggeredBy: 'github-actions', |
| 136 | workflowRunUrl: |
| 137 | process.env.GITHUB_SERVER_URL && process.env.GITHUB_REPOSITORY && process.env.GITHUB_RUN_ID |
| 138 | ? `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}` |
| 139 | : undefined, |
| 140 | cells: bundles.map(b => b.cell), |
| 141 | }; |
| 142 | |
| 143 | const form = new FormData(); |
| 144 | form.append('metadata', JSON.stringify(metadata)); |
| 145 | for (const b of bundles) { |
| 146 | const buf = await readFile(b.tarPath); |
| 147 | form.append(b.fieldName, new Blob([buf], { type: 'application/gzip' }), path.basename(b.tarPath)); |
| 148 | } |
| 149 | |
| 150 | const res = await fetch(`${LAB_URL}/api/builds`, { |
| 151 | method: 'POST', |
| 152 | headers: { Authorization: `Bearer ${TOKEN}` }, |
| 153 | body: form, |
| 154 | }); |
| 155 | if (!res.ok) { |
| 156 | throw new Error(`Upload failed: ${res.status} ${await res.text()}`); |
| 157 | } |
| 158 | return res.json(); |
| 159 | } |
| 160 | |
| 161 | async function formatSize(filePath) { |
| 162 | const { size } = await stat(filePath); |