Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[eas-build-job] [ENG-12593] add fingerprint sources to metadata #421

Merged
merged 5 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 80 additions & 28 deletions packages/eas-build-job/src/__tests__/metadata.test.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
import { MetadataSchema } from '../metadata';
import { Metadata, MetadataSchema } from '../metadata';

const validMetadata: Metadata = {
appName: 'testapp',
appVersion: '1.0.0',
appBuildVersion: '123',
runtimeVersion: '3.2.1',
cliVersion: '1.2.3',
buildProfile: 'release',
credentialsSource: 'remote',
distribution: 'store',
gitCommitHash: '752e99d2b8fde1bf07ebb8af1b4a3c26a6703943',
gitCommitMessage: 'Lorem ipsum',
trackingContext: {},
workflow: 'generic' as any,
username: 'notdominik',
iosEnterpriseProvisioning: 'adhoc',
message: 'fix foo, bar, and baz',
runFromCI: true,
runWithNoWaitFlag: true,
customWorkflowName: 'blah blah',
developmentClient: true,
requiredPackageManager: 'yarn',
simulator: true,
selectedImage: 'default',
customNodeVersion: '12.0.0',
};

describe('MetadataSchema', () => {
test('valid metadata', () => {
const metadata = {
appName: 'testapp',
appVersion: '1.0.0',
appBuildVersion: '123',
runtimeVersion: '3.2.1',
cliVersion: '1.2.3',
buildProfile: 'release',
credentialsSource: 'remote',
distribution: 'store',
gitCommitHash: '752e99d2b8fde1bf07ebb8af1b4a3c26a6703943',
gitCommitMessage: 'Lorem ipsum',
trackingContext: {},
workflow: 'generic',
username: 'notdominik',
iosEnterpriseProvisioning: 'adhoc',
message: 'fix foo, bar, and baz',
runFromCI: true,
runWithNoWaitFlag: true,
customWorkflowName: 'blah blah',
developmentClient: true,
requiredPackageManager: 'yarn',
simulator: true,
selectedImage: 'default',
customNodeVersion: '12.0.0',
};
const { value, error } = MetadataSchema.validate(metadata, {
const { value, error } = MetadataSchema.validate(validMetadata, {
stripUnknown: true,
convert: true,
abortEarly: false,
});
expect(error).toBeFalsy();
expect(value).toEqual(metadata);
expect(value).toEqual(validMetadata);
});
test('invalid metadata', () => {
const metadata = {
Expand Down Expand Up @@ -69,4 +70,55 @@ describe('MetadataSchema', () => {
'"credentialsSource" must be one of [local, remote]. "gitCommitHash" length must be 40 characters long. "gitCommitHash" must only contain hexadecimal characters. "gitCommitMessage" length must be less than or equal to 4096 characters long. "message" length must be less than or equal to 1024 characters long'
);
});

test('Allows correct fingerprint', () => {
const metadata: Metadata = {
...validMetadata,
fingerprintSource: {
type: 'GCS' as any,
bucketKey:
'development/8a9c5554-cfbe-4b4c-814c-c476a1047db9/fd6f8af4-7293-46bd-bec7-3fe639f4fd3e',
},
};
const { value, error } = MetadataSchema.validate(metadata, {
stripUnknown: true,
convert: true,
abortEarly: false,
});
expect(error).toBeFalsy();
expect(value).toEqual(metadata);
});

test('Validates incorrect fingerprint type', () => {
const metadata: Metadata = {
...validMetadata,
fingerprintSource: {
type: 'BOO' as any,
bucketKey:
'development/8a9c5554-cfbe-4b4c-814c-c476a1047db9/fd6f8af4-7293-46bd-bec7-3fe639f4fd3e',
},
};
const { error } = MetadataSchema.validate(metadata, {
stripUnknown: true,
convert: true,
abortEarly: false,
});
expect(error?.message).toEqual('"fingerprintSource.type" must be one of [GCS, PATH, URL]');
});

test('Validates incorrect fingerprint key', () => {
const metadata: Metadata = {
...validMetadata,
fingerprintSource: {
type: 'GCS' as any,
url: 'development/8a9c5554-cfbe-4b4c-814c-c476a1047db9/fd6f8af4-7293-46bd-bec7-3fe639f4fd3e',
},
};
const { error } = MetadataSchema.validate(metadata, {
stripUnknown: true,
convert: true,
abortEarly: false,
});
expect(error?.message).toEqual('"fingerprintSource.bucketKey" is required');
});
});
41 changes: 41 additions & 0 deletions packages/eas-build-job/src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ import Joi from 'joi';

import { Workflow } from './common';

enum FingerprintSourceType {
'GCS' = 'GCS',
'PATH' = 'PATH',
'URL' = 'URL',
}

export type FingerprintSource =
| { type: FingerprintSourceType.GCS; bucketKey: string }
| { type: FingerprintSourceType.PATH; path: string }
| { type: FingerprintSourceType.URL; url: string };
kadikraman marked this conversation as resolved.
Show resolved Hide resolved

export type Metadata = {
/**
* Tracking context
Expand Down Expand Up @@ -54,6 +65,11 @@ export type Metadata = {
*/
runtimeVersion?: string;

/**
* The location of the fingerprint file if one exists
*/
fingerprintSource?: FingerprintSource;

/**
* Version of the react-native package used in the project.
*/
Expand Down Expand Up @@ -161,6 +177,30 @@ export type Metadata = {
customNodeVersion?: string;
};

export const FingerprintSourceSchema = Joi.object<FingerprintSource>({
type: Joi.string()
.valid(...Object.values(FingerprintSourceType))
.required(),
})
.when(Joi.object({ type: FingerprintSourceType.GCS }).unknown(), {
then: Joi.object({
type: Joi.string().valid(FingerprintSourceType.GCS).required(),
bucketKey: Joi.string().required(),
}),
})
.when(Joi.object({ type: FingerprintSourceType.PATH }).unknown(), {
then: Joi.object({
type: Joi.string().valid(FingerprintSourceType.PATH).required(),
path: Joi.string().required(),
}),
})
.when(Joi.object({ type: FingerprintSourceType.URL }).unknown(), {
then: Joi.object({
type: Joi.string().valid(FingerprintSourceType.URL).required(),
url: Joi.string().required(),
kadikraman marked this conversation as resolved.
Show resolved Hide resolved
}),
});

export const MetadataSchema = Joi.object({
trackingContext: Joi.object()
.pattern(Joi.string(), [Joi.string(), Joi.number(), Joi.boolean()])
Expand All @@ -173,6 +213,7 @@ export const MetadataSchema = Joi.object({
credentialsSource: Joi.string().valid('local', 'remote'),
sdkVersion: Joi.string(),
runtimeVersion: Joi.string(),
fingerprintSource: FingerprintSourceSchema,
reactNativeVersion: Joi.string(),
channel: Joi.string(),
appName: Joi.string(),
Expand Down
Loading