Skip to content

Commit

Permalink
Add support for generic artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
sjchmiela committed Jan 15, 2024
1 parent 0034366 commit 9ed06b1
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 11 deletions.
21 changes: 15 additions & 6 deletions packages/build-tools/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
errors,
Metadata,
EnvironmentSecretType,
GenericArtifactType,
isGenericArtifact,
} from '@expo/eas-build-job';
import { ExpoConfig } from '@expo/config';
import { bunyan } from '@expo/logger';
Expand All @@ -35,11 +37,18 @@ export interface LogBuffer {
getPhaseLogs(buildPhase: string): string[];
}

export type ArtifactToUpload = {
type: ManagedArtifactType;
paths: string[];
logger: bunyan;
};
export type ArtifactToUpload =
| {
type: ManagedArtifactType;
paths: string[];
logger: bunyan;
}
| {
type: GenericArtifactType;
key: string;
paths: string[];
logger: bunyan;
};

export interface BuildContextOptions {
workingdir: string;
Expand Down Expand Up @@ -214,7 +223,7 @@ export class BuildContext<TJob extends Job> {

public async uploadArtifacts(artifact: ArtifactToUpload): Promise<void> {
const bucketKey = await this._uploadArtifacts(artifact);
if (bucketKey) {
if (bucketKey && !isGenericArtifact(artifact)) {
this.artifacts[artifact.type] = bucketKey;
}
}
Expand Down
28 changes: 23 additions & 5 deletions packages/build-tools/src/steps/functions/uploadArtifact.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';

import { ManagedArtifactType } from '@expo/eas-build-job';
import { GenericArtifactType, ManagedArtifactType, isGenericArtifact } from '@expo/eas-build-job';
import { BuildFunction, BuildStepInput, BuildStepInputValueTypeName } from '@expo/steps';
import nullthrows from 'nullthrows';

Expand All @@ -18,10 +18,17 @@ export function createUploadArtifactBuildFunction(ctx: CustomBuildContext): Buil
allowedValues: [
ManagedArtifactType.APPLICATION_ARCHIVE,
ManagedArtifactType.BUILD_ARTIFACTS,
...Object.values(GenericArtifactType),
],
required: true,
allowedValueTypeName: BuildStepInputValueTypeName.STRING,
}),
BuildStepInput.createProvider({
id: 'key',
defaultValue: '',
required: false,
allowedValueTypeName: BuildStepInputValueTypeName.STRING,
}),
BuildStepInput.createProvider({
id: 'path',
required: true,
Expand All @@ -33,13 +40,24 @@ export function createUploadArtifactBuildFunction(ctx: CustomBuildContext): Buil
stepsCtx.workingDirectory,
nullthrows(inputs.path.value).toString()
);
const artifactType = inputs.type.value as ManagedArtifactType;

await ctx.runtimeApi.uploadArtifacts({
type: artifactType,
const artifact = {
type: inputs.type.value as ManagedArtifactType | GenericArtifactType,
paths: [filePath],
logger: stepsCtx.logger,
});
key: inputs.key.value as string,
};

if (!isGenericArtifact(artifact)) {
await ctx.runtimeApi.uploadArtifacts({
type: inputs.type.value as ManagedArtifactType,
paths: [filePath],
logger: stepsCtx.logger,
});
return;
}

await ctx.runtimeApi.uploadArtifacts(artifact);
},
});
}
24 changes: 24 additions & 0 deletions packages/eas-build-job/src/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,27 @@ export enum ManagedArtifactType {
*/
XCODE_BUILD_LOGS = 'XCODE_BUILD_LOGS',
}

// TODO: Consider adding dev-client artifacts. Or should dev clients live in user space?
export enum GenericArtifactType {
ANDROID_APK = 'android-apk',
ANDROID_AAB = 'android-aab',

IOS_SIMULATOR_APP = 'ios-simulator-app',
// TODO: Consider splitting into specific: internal-ipa and app-store-ipa.
// Should the "internal / app store" split live in user space?
IOS_IPA = 'ios-ipa',

UNKNOWN = 'unknown',
}

export const isGenericArtifact = <
TSpec extends { type: GenericArtifactType | ManagedArtifactType }
>(
artifactSpec: TSpec
): artifactSpec is TSpec & { type: GenericArtifactType } => {
if (Object.values(GenericArtifactType).includes(artifactSpec.type as GenericArtifactType)) {
return true;
}
return false;
};
1 change: 1 addition & 0 deletions packages/local-build-plugin/src/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export async function buildAndroidAsync(
logBuffer,
runGlobalExpoCliCommand: runGlobalExpoCliCommandAsync,
uploadArtifacts: async (artifact: ArtifactToUpload) => {
// TODO: Support GenericArtifactTypes
if (artifact.type !== ManagedArtifactType.APPLICATION_ARCHIVE) {
return null;
} else {
Expand Down
1 change: 1 addition & 0 deletions packages/local-build-plugin/src/ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export async function buildIosAsync(
logBuffer,
runGlobalExpoCliCommand: runGlobalExpoCliCommandAsync,
uploadArtifacts: async ({ type, paths, logger }: ArtifactToUpload) => {
// TODO: Support GenericArtifactTypes
if (type !== ManagedArtifactType.APPLICATION_ARCHIVE) {
return null;
} else {
Expand Down

0 comments on commit 9ed06b1

Please sign in to comment.