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 18, 2023
1 parent 43180c0 commit 6ec3bfc
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 5 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: 39 additions & 5 deletions packages/eas-cli/src/build/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ 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 +137,10 @@ 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,
};
} else if (ctx.localBuildOptions.localBuildMode === LocalBuildMode.INTERNAL) {
projectArchive = {
Expand All @@ -145,7 +150,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 +236,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 +282,33 @@ async function uploadProjectAsync<TPlatform extends Platform>(
completedMessage: (duration: string) => `Uploaded to EAS ${chalk.dim(duration)}`,
})
);
return bucketKey;
let projectMetadataFile: any;
try {
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 };
} catch (e) {
Log.warn('Failed to upload metadata to EAS Build');
Log.debug(e);
return { bucketKey };
} finally {
if (projectMetadataFile) {
await fs.remove(projectMetadataFile.path);
}
}
},
{
attemptEvent: BuildEvent.PROJECT_UPLOAD_ATTEMPT,
Expand Down
1 change: 1 addition & 0 deletions packages/eas-cli/src/build/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function transformProjectArchive(archiveSource: ArchiveSource): ProjectAr
return {
type: ProjectArchiveSourceType.S3,
bucketKey: archiveSource.bucketKey,
metadataLocation: archiveSource.metadataLocation,
};
} else if (archiveSource.type === ArchiveSourceType.GCS) {
return {
Expand Down
44 changes: 44 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,50 @@ 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';
const timer = setTimeout(
() => {
spinner.start();
},
Log.isDebug ? 1 : 1000
);
startTimer(timerLabel);

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

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

await fs.writeJSON(metadataLocation, {
archiveContent,
});
} catch (e) {
clearTimeout(timer);
if (spinner.isSpinning) {
spinner.fail();
}
throw e;
}

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 6ec3bfc

Please sign in to comment.