mirror of
https://github.com/expo/eas-cli.git
synced 2026-11-15 17:31:46 -10:00
The worker's secrets filter takes secrets added while the job runs through addBuildLogMask, which reaches steps via the build context's runtimeApi. eas/run_agent passes each leased token to it and drops its own masking. Masking marks every occurrence of every secret on the original message and masks once, so a secret that is a substring of another no longer breaks the longer match. The log buffer that feeds error detection masks with the same patterns.
113 lines
3.6 KiB
TypeScript
113 lines
3.6 KiB
TypeScript
import { BuildContext, BuildContextOptions, LogBuffer, RuntimeSettings } from '@expo/build-tools';
|
|
import { Job, ManagedArtifactType, Metadata, Platform } from '@expo/eas-build-job';
|
|
import { bunyan } from '@expo/logger';
|
|
import assert from 'assert';
|
|
|
|
import { GCSCacheManager } from './CacheManager';
|
|
import config from './config';
|
|
import { getBuildEnv } from './env';
|
|
import { Analytics } from './external/analytics';
|
|
import { uploadXcodeBuildLogs } from './ios/xcodeLogs';
|
|
import { prepareRuntimeEnvironmentConfigFiles } from './runtimeEnvironment';
|
|
import sentry from './sentry';
|
|
import {
|
|
uploadApplicationArchiveAsync,
|
|
uploadBuildArtifactsAsync,
|
|
uploadSourceMapAsync,
|
|
uploadWithAnalyticsAsync,
|
|
uploadWorkflowArtifactAsync,
|
|
} from './upload';
|
|
|
|
export async function createBuildContext<TJob extends Job>({
|
|
job,
|
|
logBuffer,
|
|
analytics,
|
|
metadata,
|
|
projectId,
|
|
buildId,
|
|
buildLogger,
|
|
addBuildLogMask,
|
|
}: {
|
|
job: TJob;
|
|
logBuffer: LogBuffer;
|
|
analytics: Analytics;
|
|
metadata: Metadata;
|
|
projectId: string;
|
|
buildId: string;
|
|
buildLogger: bunyan;
|
|
addBuildLogMask: (secret: string) => void;
|
|
}): Promise<BuildContext<TJob>> {
|
|
const childLogger = buildLogger.child({ buildId });
|
|
await RuntimeSettings.loadAsync({
|
|
environment: config.env,
|
|
env: job.builderEnvironment?.env,
|
|
});
|
|
await prepareRuntimeEnvironmentConfigFiles();
|
|
const env = getBuildEnv({ job, projectId, metadata, buildId });
|
|
|
|
const uploadArtifact: BuildContextOptions['uploadArtifact'] = async ({ artifact, logger }) => {
|
|
const { paths, type } = artifact;
|
|
|
|
switch (type) {
|
|
case ManagedArtifactType.XCODE_BUILD_LOGS: {
|
|
if (job.platform === Platform.IOS) {
|
|
await uploadXcodeBuildLogs(logger, paths[0]);
|
|
return { filename: null };
|
|
}
|
|
throw new Error('Uploading Xcode logs in non-iOS builds is not supported');
|
|
}
|
|
case ManagedArtifactType.APPLICATION_ARCHIVE: {
|
|
assert(job.platform, 'Uploading application archives outside of builds is not supported.');
|
|
return await uploadWithAnalyticsAsync(
|
|
() => uploadApplicationArchiveAsync(ctx, { artifactPaths: paths, buildId, logger }),
|
|
analytics
|
|
);
|
|
}
|
|
case ManagedArtifactType.BUILD_ARTIFACTS: {
|
|
assert(job.platform, 'Uploading build artifacts outside of builds is not supported.');
|
|
return await uploadWithAnalyticsAsync(
|
|
() => uploadBuildArtifactsAsync(ctx, { artifactPaths: paths, buildId, logger }),
|
|
analytics
|
|
);
|
|
}
|
|
case ManagedArtifactType.SOURCE_MAP: {
|
|
assert(job.platform, 'Uploading source maps outside of builds is not supported.');
|
|
return await uploadWithAnalyticsAsync(
|
|
() => uploadSourceMapAsync(ctx, { sourceMapPath: paths[0], buildId, logger }),
|
|
analytics
|
|
);
|
|
}
|
|
default: {
|
|
return await uploadWithAnalyticsAsync(
|
|
() =>
|
|
uploadWorkflowArtifactAsync(ctx, {
|
|
artifactPaths: paths,
|
|
logger,
|
|
name: artifact.name,
|
|
metadata: artifact.metadata,
|
|
}),
|
|
analytics
|
|
);
|
|
}
|
|
}
|
|
};
|
|
|
|
const ctx = new BuildContext<TJob>(job, {
|
|
workingdir: config.workingdir,
|
|
logger: childLogger,
|
|
logBuffer,
|
|
env,
|
|
uploadArtifact,
|
|
reportError: (msg, err, { tags, extras } = {}) => {
|
|
childLogger.error({ tags, extras, err }, msg);
|
|
sentry.capture(msg, err, { tags, extras });
|
|
},
|
|
cacheManager: new GCSCacheManager(),
|
|
metadata,
|
|
expoApiV2BaseUrl: config.wwwApiV2BaseUrl,
|
|
mcpServerUrl: config.mcpServerUrl,
|
|
addBuildLogMask,
|
|
});
|
|
return ctx;
|
|
}
|