Skip to content

Commit

Permalink
Extract assertProjectTarballSizeDoesNotExceedLimit
Browse files Browse the repository at this point in the history
  • Loading branch information
sjchmiela committed Feb 5, 2025
1 parent a22d9bf commit 242f949
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
6 changes: 2 additions & 4 deletions packages/eas-cli/src/build/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { collectMetadataAsync } from './metadata';
import { printDeprecationWarnings } from './utils/printBuildInfo';
import {
LocalFile,
assertProjectTarballSizeDoesNotExceedLimit,
makeProjectMetadataFileAsync,
makeProjectTarballAsync,
maybeWarnAboutProjectTarballSize,
Expand Down Expand Up @@ -277,10 +278,7 @@ async function uploadProjectAsync<TPlatform extends Platform>(
const projectTarball = await makeProjectTarballAsync(ctx.vcsClient);

maybeWarnAboutProjectTarballSize(projectTarball.size);

if (projectTarball.size > 2 * 1024 * 1024 * 1024) {
throw new Error('Project archive is too big. Maximum allowed size is 2GB.');
}
assertProjectTarballSizeDoesNotExceedLimit(projectTarball.size);

projectTarballPath = projectTarball.path;
const [bucketKey, { metadataLocation }] = await Promise.all([
Expand Down
14 changes: 14 additions & 0 deletions packages/eas-cli/src/build/utils/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,20 @@ export function maybeWarnAboutProjectTarballSize(size: number): void {
);
}

const MAX_ALLOWED_PROJECT_TARBALL_SIZE =
2 /* GiB */ * 1024 /* MiB */ * 1024 /* KiB */ * 1024; /* B */
export function assertProjectTarballSizeDoesNotExceedLimit(size: number): void {
if (size <= MAX_ALLOWED_PROJECT_TARBALL_SIZE) {
return;
}

throw new Error(
`Project archive is too big. Maximum allowed size is ${formatBytes(
MAX_ALLOWED_PROJECT_TARBALL_SIZE
)}.`
);
}

enum ShouldCommitChanges {
Yes,
ShowDiffFirst,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import chalk from 'chalk';
import fs from 'node:fs';

import {
assertProjectTarballSizeDoesNotExceedLimit,
makeProjectTarballAsync,
maybeWarnAboutProjectTarballSize,
} from '../build/utils/repository';
Expand Down Expand Up @@ -40,10 +41,7 @@ export async function uploadAccountScopedProjectSourceAsync({
projectTarballPath = projectTarball.path;

maybeWarnAboutProjectTarballSize(projectTarball.size);

if (projectTarball.size > 2 * 1024 * 1024 * 1024) {
throw new Error('Project archive is too big. Maximum allowed size is 2GB.');
}
assertProjectTarballSizeDoesNotExceedLimit(projectTarball.size);

const projectArchiveBucketKey = await uploadAccountScopedFileAtPathToGCSAsync(graphqlClient, {
accountId,
Expand Down

0 comments on commit 242f949

Please sign in to comment.