Skip to content

Commit

Permalink
[ENG-10412] Upload projectMetadata file
Browse files Browse the repository at this point in the history
  • Loading branch information
khamilowicz committed Dec 13, 2023
1 parent ffa45bb commit 621303b
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This is the log of notable changes to EAS CLI and related packages.

### 🎉 New features

- Generate metadata file for project archive ([#2149](https://github.com/expo/eas-cli/pull/2149) by [@khamilowicz](https://github.com/khamilowicz))

### 🐛 Bug fixes

### 🧹 Chores
Expand Down
12 changes: 12 additions & 0 deletions packages/eas-cli/graphql.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 32 additions & 12 deletions packages/eas-cli/src/build/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import { transformMetadata } from './graphql';
import { LocalBuildMode, runLocalBuildAsync } from './local';
import { collectMetadataAsync } from './metadata';
import { printDeprecationWarnings } from './utils/printBuildInfo';
import { makeProjectTarballAsync, reviewAndCommitChangesAsync } from './utils/repository';
import { makeProjectMetadataFileAsync, makeProjectTarballAsync, reviewAndCommitChangesAsync } from './utils/repository';

export interface CredentialsResult<Credentials> {
source: CredentialsSource.LOCAL | CredentialsSource.REMOTE;
Expand Down Expand Up @@ -133,9 +133,11 @@ export async function prepareBuildRequestForPlatformAsync<

let projectArchive: ArchiveSource | undefined;
if (ctx.localBuildOptions.localBuildMode === LocalBuildMode.LOCAL_BUILD_PLUGIN) {
const projectPath = (await makeProjectTarballAsync(ctx.vcsClient)).path;
projectArchive = {
type: ArchiveSourceType.PATH,
path: (await makeProjectTarballAsync(ctx.vcsClient)).path,
path: projectPath,
metadataLocation: (await makeProjectMetadataFileAsync(projectPath)).path,
};
} else if (ctx.localBuildOptions.localBuildMode === LocalBuildMode.INTERNAL) {
projectArchive = {
Expand All @@ -145,7 +147,7 @@ export async function prepareBuildRequestForPlatformAsync<
} else if (!ctx.localBuildOptions.localBuildMode) {
projectArchive = {
type: ArchiveSourceType.GCS,
bucketKey: await uploadProjectAsync(ctx),
...(await uploadProjectAsync(ctx)),
};
}
assert(projectArchive);
Expand Down Expand Up @@ -231,7 +233,10 @@ export function handleBuildRequestError(error: any, platform: Platform): never {

async function uploadProjectAsync<TPlatform extends Platform>(
ctx: BuildContext<TPlatform>
): Promise<string> {
): Promise<{
bucketKey: string;
metadataLocation: string;
}> {
let projectTarballPath;
try {
return await withAnalyticsAsync(
Expand Down Expand Up @@ -274,7 +279,24 @@ async function uploadProjectAsync<TPlatform extends Platform>(
completedMessage: (duration: string) => `Uploaded to EAS ${chalk.dim(duration)}`,
})
);
return bucketKey;

const projectMetadataFile = await makeProjectMetadataFileAsync(projectTarball.path);

const metadataLocation = await uploadFileAtPathToGCSAsync(
ctx.graphqlClient,
UploadSessionType.EasBuildGcsProjectSources,
projectMetadataFile.path,
createProgressTracker({
total: projectMetadataFile.size,
message: ratio =>
`Uploading metadata to EAS Build (${formatBytes(projectMetadataFile.size * ratio)} / ${formatBytes(
projectMetadataFile.size
)})`,
completedMessage: (duration: string) => `Uploaded to EAS ${chalk.dim(duration)}`,
})
);

return { bucketKey, metadataLocation };
},
{
attemptEvent: BuildEvent.PROJECT_UPLOAD_ATTEMPT,
Expand Down Expand Up @@ -536,9 +558,8 @@ function formatSettledBuildsText(builds: BuildFragment[]): string {
builds.find(build => build.platform === platform),
`Build for platform ${platform} must be defined in this context`
);
return `${appPlatformEmojis[platform]} ${
appPlatformDisplayNames[platform]
} build - status: ${chalk.bold(statusToDisplayName[build.status])}`;
return `${appPlatformEmojis[platform]} ${appPlatformDisplayNames[platform]
} build - status: ${chalk.bold(statusToDisplayName[build.status])}`;
})
.join('\n ');
}
Expand All @@ -558,17 +579,16 @@ function formatPendingBuildsText(originalSpinnerText: string, builds: BuildFragm
const percent = Math.floor(
((build.initialQueuePosition - build.queuePosition + 1) /
(build.initialQueuePosition + 1)) *
100
100
);
const estimatedWaitTime =
typeof build.estimatedWaitTimeLeftSeconds === 'number'
? ` - ${formatEstimatedWaitTime(build.estimatedWaitTimeLeftSeconds)}`
: '';
extraInfo = ` - queue progress: ${chalk.bold(`${percent}%`)}${estimatedWaitTime}`;
}
return `${appPlatformEmojis[platform]} ${
appPlatformDisplayNames[platform]
} build - status: ${chalk.bold(status)}${extraInfo}`;
return `${appPlatformEmojis[platform]} ${appPlatformDisplayNames[platform]
} build - status: ${chalk.bold(status)}${extraInfo}`;
}),
].join('\n ');
}
Expand Down
3 changes: 3 additions & 0 deletions packages/eas-cli/src/build/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,19 @@ export function transformProjectArchive(archiveSource: ArchiveSource): ProjectAr
return {
type: ProjectArchiveSourceType.S3,
bucketKey: archiveSource.bucketKey,
metadataLocation: archiveSource.metadataLocation,
};
} else if (archiveSource.type === ArchiveSourceType.GCS) {
return {
type: ProjectArchiveSourceType.Gcs,
bucketKey: archiveSource.bucketKey,
metadataLocation: archiveSource.metadataLocation,
};
} else if (archiveSource.type === ArchiveSourceType.URL) {
return {
type: ProjectArchiveSourceType.Url,
url: archiveSource.url,
metadataLocation: archiveSource.metadataLocation,
};
} else {
throw new Error(`Unsupported project archive source type: '${archiveSource.type}'`);
Expand Down
29 changes: 29 additions & 0 deletions packages/eas-cli/src/build/utils/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,35 @@ export async function commitPromptAsync(
});
}

export async function makeProjectMetadataFileAsync(archivePath: string): Promise<{ path: string; size: number }> {
const spinner = ora('Creating project metadata file');
const timerLabel = 'makeProjectMetadataFileAsync';
startTimer(timerLabel);

const metadataLocation = path.join(getTmpDirectory(), `${uuidv4()}.json`);
const archiveContent: string[] = [];

await tar.list({
file: archivePath,
onentry: (entry: tar.ReadEntry) => {
if (entry.type === 'File') {
archiveContent.push(entry.path);
}
}
});

await fs.writeJSON(metadataLocation, {
archiveContent
});

const duration = endTimer(timerLabel);
const prettyTime = formatMilliseconds(duration);
spinner.succeed(
`Created project metadata file ${chalk.dim(prettyTime)}`);

return { path: metadataLocation, size: await fs.stat(metadataLocation).then(stat => stat.size) };
}

export async function makeProjectTarballAsync(
vcsClient: Client
): Promise<{ path: string; size: number }> {
Expand Down
1 change: 1 addition & 0 deletions packages/eas-cli/src/graphql/generated.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 621303b

Please sign in to comment.