Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
54 changes: 54 additions & 0 deletions packages/eas-build-job/src/__tests__/android.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,60 @@ describe('Android.JobSchema', () => {
expect(error).toBeFalsy();
});

test('can set hooks with arbitrary names', () => {
const job = {
mode: BuildMode.BUILD,
type: Workflow.GENERIC,
platform: Platform.ANDROID,
projectArchive: {
type: ArchiveSourceType.URL,
url: 'https://expo.dev/builds/123',
},
projectRootDirectory: '.',
hooks: {
before_install_node_modules: [
{
id: 'before-install',
run: 'echo before install',
shell: 'sh',
},
],
my_custom_hook: [],
},
secrets,
initiatingUserId: randomUUID(),
appId: randomUUID(),
};
const { value, error } = Android.JobSchema.validate(job, joiOptions);
expect(value).toMatchObject(job);
expect(error).toBeFalsy();
});

test('can set hooks in custom mode', () => {
const customBuildJob = {
mode: BuildMode.CUSTOM,
type: Workflow.UNKNOWN,
platform: Platform.ANDROID,
projectArchive: {
type: ArchiveSourceType.URL,
url: 'https://expo.dev/builds/123',
},
projectRootDirectory: '.',
customBuildConfig: {
path: 'production.android.yml',
},
hooks: {
before_install_node_modules: [],
},
initiatingUserId: randomUUID(),
appId: randomUUID(),
};

const { value, error } = Android.JobSchema.validate(customBuildJob, joiOptions);
expect(value).toMatchObject(customBuildJob);
expect(error).toBeFalsy();
});

test('can set github trigger options', () => {
const job = {
mode: BuildMode.BUILD,
Expand Down
101 changes: 101 additions & 0 deletions packages/eas-build-job/src/__tests__/generic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,107 @@ describe('Generic.JobZ', () => {
expect(Generic.JobZ.parse(job)).toEqual(job);
});

it('accepts hooks with arbitrary names', () => {
const job: Generic.Job = {
projectArchive: {
type: ArchiveSourceType.GIT,
repositoryUrl: 'https://github.com/expo/expo.git',
gitCommitHash: '1234567890',
gitRef: null,
},
hooks: {
before_install_node_modules: [
{
id: 'before-install',
run: 'echo before install',
shell: 'sh',
},
],
my_custom_hook: [],
},
steps: [
{
id: 'step1',
name: 'Step 1',
run: 'echo Hello, world!',
shell: 'sh',
},
],
secrets: {
robotAccessToken: 'token',
environmentSecrets: [
{
name: 'secret-name',
value: 'secret-value',
type: EnvironmentSecretType.STRING,
},
],
},
expoDevUrl: 'https://expo.dev/accounts/name/builds/id',
builderEnvironment: {
image: 'macos-sonoma-14.5-xcode-15.4',
node: '20.15.1',
corepack: false,
env: {
KEY1: 'value1',
},
},
triggeredBy: BuildTrigger.GIT_BASED_INTEGRATION,
appId: randomUUID(),
initiatingUserId: randomUUID(),
};
expect(Generic.JobZ.parse(job)).toEqual(job);
});

it('errors when hook step definition is invalid', () => {
const job = {
projectArchive: {
type: ArchiveSourceType.GIT,
repositoryUrl: 'https://github.com/expo/expo.git',
gitCommitHash: '1234567890',
gitRef: null,
},
hooks: {
before_install_node_modules: [
{
id: 'missing-run-or-uses',
},
],
},
steps: [
{
id: 'step1',
name: 'Step 1',
run: 'echo Hello, world!',
shell: 'sh',
},
],
secrets: {
robotAccessToken: 'token',
environmentSecrets: [
{
name: 'secret-name',
value: 'secret-value',
type: EnvironmentSecretType.STRING,
},
],
},
expoDevUrl: 'https://expo.dev/accounts/name/builds/id',
builderEnvironment: {
image: 'macos-sonoma-14.5-xcode-15.4',
node: '20.15.1',
corepack: false,
env: {
KEY1: 'value1',
},
},
triggeredBy: BuildTrigger.GIT_BASED_INTEGRATION,
appId: randomUUID(),
initiatingUserId: randomUUID(),
};
expect(() => Generic.JobZ.parse(job)).toThrow(ZodError);
});

it('errors when steps are not provided', () => {
const job: Omit<Generic.Job, 'customBuildConfig' | 'steps'> = {
projectArchive: {
Expand Down
60 changes: 60 additions & 0 deletions packages/eas-build-job/src/__tests__/ios.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,66 @@ describe('Ios.JobSchema', () => {
expect(error).toBeFalsy();
});

test('valid generic job with hooks', () => {
const genericJob = {
secrets: {
buildCredentials,
},
type: Workflow.GENERIC,
platform: Platform.IOS,
projectArchive: {
type: ArchiveSourceType.URL,
url: 'http://localhost:3000',
},
projectRootDirectory: '.',
hooks: {
before_install_node_modules: [
{
id: 'before-install',
run: 'echo before install',
shell: 'sh',
},
],
my_custom_hook: [],
},
initiatingUserId: randomUUID(),
appId: randomUUID(),
};

const { value, error } = Ios.JobSchema.validate(genericJob, joiOptions);
expect(value).toMatchObject(genericJob);
expect(error).toBeFalsy();
});

test('valid resign job with hooks', () => {
const genericJob = {
mode: BuildMode.RESIGN,
secrets: {
buildCredentials,
},
type: Workflow.UNKNOWN,
platform: Platform.IOS,
projectArchive: {
type: ArchiveSourceType.NONE,
},
resign: {
applicationArchiveSource: {
type: ArchiveSourceType.URL,
url: 'http://localhost:3000/a.ipa',
},
},
hooks: {
before_install_node_modules: [],
},
initiatingUserId: randomUUID(),
appId: randomUUID(),
};

const { value, error } = Ios.JobSchema.validate(genericJob, joiOptions);
expect(value).toMatchObject(genericJob);
expect(error).toBeFalsy();
});

test('valid custom build job with metadataLocation', () => {
const customBuildJob = {
mode: BuildMode.CUSTOM,
Expand Down
4 changes: 4 additions & 0 deletions packages/eas-build-job/src/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
EnvSchema,
EnvironmentSecret,
EnvironmentSecretsSchema,
Hooks,
HooksSchema,
Platform,
StaticWorkflowInterpolationContext,
StaticWorkflowInterpolationContextZ,
Expand Down Expand Up @@ -106,6 +108,7 @@ export interface Job {
customBuildConfig?: {
path: string;
};
hooks?: Hooks;
steps?: Step[];
outputs?: Record<string, string>;

Expand Down Expand Up @@ -172,6 +175,7 @@ export const JobSchema = Joi.object({

buildType: Joi.string().valid(...Object.values(BuildType)),
username: Joi.string(),
hooks: HooksSchema,

experimental: Joi.object({
prebuildCommand: Joi.string(),
Expand Down
17 changes: 16 additions & 1 deletion packages/eas-build-job/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Joi from 'joi';
import { z } from 'zod';

import { BuildPhase, BuildPhaseResult } from './logs';
import { validateSteps } from './step';
import { Step, StepZ, validateSteps } from './step';

export enum BuildMode {
BUILD = 'build',
Expand Down Expand Up @@ -142,6 +142,21 @@ export const EnvironmentSecretZ = z.object({
type: z.nativeEnum(EnvironmentSecretType),
});

export type Hooks = Record<string, Step[]>;
export const HooksSchema = Joi.object().pattern(
Joi.string(),
Joi.array()
.items(Joi.any())
.required()
.custom(steps => {
if (steps.length === 0) {
return steps;
}
return validateSteps(steps);
}, 'steps validation')
);
export const HooksZ = z.record(z.string(), z.array(StepZ));

export interface Cache {
disabled: boolean;
clear: boolean;
Expand Down
2 changes: 2 additions & 0 deletions packages/eas-build-job/src/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ArchiveSourceSchemaZ,
BuildTrigger,
EnvironmentSecretZ,
HooksZ,
StaticWorkflowInterpolationContextZ,
} from './common';
import { StepZ } from './step';
Expand Down Expand Up @@ -45,6 +46,7 @@ export namespace Generic {
initiatingUserId: z.string(),
appId: z.string(),

hooks: HooksZ.optional(),
steps: z.array(StepZ).min(1),
outputs: z.record(z.string(), z.string()).optional(),
});
Expand Down
1 change: 1 addition & 0 deletions packages/eas-build-job/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export {
Env,
EnvironmentSecret,
EnvironmentSecretType,
Hooks,
Workflow,
Platform,
Cache,
Expand Down
4 changes: 4 additions & 0 deletions packages/eas-build-job/src/ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
EnvSchema,
EnvironmentSecret,
EnvironmentSecretsSchema,
Hooks,
HooksSchema,
Platform,
StaticWorkflowInterpolationContext,
StaticWorkflowInterpolationContextZ,
Expand Down Expand Up @@ -120,6 +122,7 @@ export interface Job {
customBuildConfig?: {
path: string;
};
hooks?: Hooks;
steps?: Step[];
outputs?: Record<string, string>;

Expand Down Expand Up @@ -206,6 +209,7 @@ export const JobSchema = Joi.object({
applicationArchivePath: Joi.string(),

username: Joi.string(),
hooks: HooksSchema,

experimental: Joi.object({
prebuildCommand: Joi.string(),
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock

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