Skip to content

Commit d8f0fe7

Browse files
committed
Fix Netlify upload CI regressions
1 parent b66fb86 commit d8f0fe7

3 files changed

Lines changed: 67 additions & 15 deletions

File tree

packages/cli/src/index.ts

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2324,6 +2324,19 @@ function resolveUploadManifestConfig(featuresUploads: boolean): UploadManifestCo
23242324
};
23252325
}
23262326

2327+
function hasExplicitUploadManifestOverrideEnv(): boolean {
2328+
return [
2329+
'TH_UPLOAD_REMOTE_BASE_URL',
2330+
'TH_UPLOAD_REMOTE_ENDPOINT_URL',
2331+
'TH_UPLOAD_REMOTE_STATUS_URL',
2332+
'TH_UPLOAD_RUNNER',
2333+
'TH_UPLOAD_PROVIDER',
2334+
'TH_UPLOAD_BASE_URL',
2335+
'TH_UPLOAD_ACCEPT',
2336+
'TH_UPLOAD_MAX_BYTES'
2337+
].some((key) => String(process.env[key] ?? '').trim() !== '');
2338+
}
2339+
23272340
function normalizeFunctionsDirectory(value: string | undefined): string {
23282341
const trimmed = String(value ?? '').trim().replace(/^\/+|\/+$/g, '');
23292342
if (!trimmed) return 'netlify/functions';
@@ -3862,19 +3875,22 @@ function buildFromSchema(
38623875
const zeroAddress = '0x0000000000000000000000000000000000000000';
38633876
const txMode = resolveTxMode(opts.txMode, Number(opts.targetChainId ?? anvil.id));
38643877
const relayBaseUrl = String(opts.relayBaseUrl ?? process.env.TH_RELAY_BASE_URL ?? '/__tokenhost/relay').trim() || '/__tokenhost/relay';
3878+
const explicitUploadManifestConfig = hasExplicitUploadManifestOverrideEnv() ? resolveUploadManifestConfig(features.uploads) : null;
38653879
const netlifyUploadBuild = resolveNetlifyUploadBuildConfig(schema);
3866-
const uploadConfig = netlifyUploadBuild
3867-
? {
3868-
enabled: true,
3869-
baseUrl: netlifyUploadBuild.endpointUrl,
3870-
endpointUrl: netlifyUploadBuild.endpointUrl,
3871-
statusUrl: netlifyUploadBuild.statusUrl,
3872-
provider: netlifyUploadBuild.provider,
3873-
runnerMode: 'remote' as const,
3874-
accept: netlifyUploadBuild.accept,
3875-
maxBytes: netlifyUploadBuild.maxBytes
3876-
}
3877-
: resolveUploadManifestConfig(features.uploads);
3880+
const uploadConfig =
3881+
explicitUploadManifestConfig ??
3882+
(netlifyUploadBuild
3883+
? {
3884+
enabled: true,
3885+
baseUrl: netlifyUploadBuild.endpointUrl,
3886+
endpointUrl: netlifyUploadBuild.endpointUrl,
3887+
statusUrl: netlifyUploadBuild.statusUrl,
3888+
provider: netlifyUploadBuild.provider,
3889+
runnerMode: 'remote' as const,
3890+
accept: netlifyUploadBuild.accept,
3891+
maxBytes: netlifyUploadBuild.maxBytes
3892+
}
3893+
: resolveUploadManifestConfig(features.uploads));
38783894

38793895
const manifest = {
38803896
manifestVersion: '0.1.0',

test/integration/testGeneratedAppUiTests.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { expect } from 'chai';
22
import fs from 'fs';
3+
import net from 'net';
34
import os from 'os';
45
import path from 'path';
56
import { spawn, spawnSync } from 'child_process';
@@ -58,6 +59,23 @@ function waitForOutput(proc, pattern, timeoutMs) {
5859
});
5960
}
6061

62+
function getAvailablePort(host) {
63+
return new Promise((resolve, reject) => {
64+
const server = net.createServer();
65+
server.unref();
66+
server.on('error', reject);
67+
server.listen(0, host, () => {
68+
const address = server.address();
69+
const port = typeof address === 'object' && address ? address.port : null;
70+
server.close((err) => {
71+
if (err) reject(err);
72+
else if (!port) reject(new Error('Unable to determine an available port.'));
73+
else resolve(port);
74+
});
75+
});
76+
});
77+
}
78+
6179
describe('Generated app UI tests', function () {
6280
it('emits schema-aware UI smoke tests that pass against canonical job-board preview', async function () {
6381
this.timeout(240000);
@@ -79,7 +97,7 @@ describe('Generated app UI tests', function () {
7997
expect(buildRes.status, buildRes.stderr || buildRes.stdout).to.equal(0);
8098

8199
const host = '127.0.0.1';
82-
const port = 46000 + Math.floor(Math.random() * 1000);
100+
const port = await getAvailablePort(host);
83101
const baseUrl = `http://${host}:${port}`;
84102
const preview = spawn(
85103
'node',

test/integration/testMicroblogRemoteUploadFlow.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { expect } from 'chai';
22
import fs from 'fs';
3+
import net from 'net';
34
import os from 'os';
45
import path from 'path';
56
import { spawn, spawnSync } from 'child_process';
@@ -57,6 +58,23 @@ async function request(url, init) {
5758
return { status: res.status, json, buffer, headers: res.headers };
5859
}
5960

61+
function getAvailablePort(host) {
62+
return new Promise((resolve, reject) => {
63+
const server = net.createServer();
64+
server.unref();
65+
server.on('error', reject);
66+
server.listen(0, host, () => {
67+
const address = server.address();
68+
const port = typeof address === 'object' && address ? address.port : null;
69+
server.close((err) => {
70+
if (err) reject(err);
71+
else if (!port) reject(new Error('Unable to determine an available port.'));
72+
else resolve(port);
73+
});
74+
});
75+
});
76+
}
77+
6078
describe('Microblog example remote upload adapter flow', function () {
6179
it('builds the canonical microblog app against a standalone remote upload adapter', async function () {
6280
this.timeout(180000);
@@ -65,7 +83,7 @@ describe('Microblog example remote upload adapter flow', function () {
6583
const outDir = path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'th-microblog-remote-')), 'out');
6684

6785
const adapterHost = '127.0.0.1';
68-
const adapterPort = 48000 + Math.floor(Math.random() * 1000);
86+
const adapterPort = await getAvailablePort(adapterHost);
6987
const adapterBaseUrl = `http://${adapterHost}:${adapterPort}`;
7088
const adapterEndpointPath = '/api/upload';
7189
const adapterStatusPath = '/api/upload/status';
@@ -87,7 +105,7 @@ describe('Microblog example remote upload adapter flow', function () {
87105
});
88106

89107
const previewHost = '127.0.0.1';
90-
const previewPort = 49000 + Math.floor(Math.random() * 1000);
108+
const previewPort = await getAvailablePort(previewHost);
91109
const previewBaseUrl = `http://${previewHost}:${previewPort}`;
92110

93111
let preview = null;

0 commit comments

Comments
 (0)