diff --git a/packages/build-tools/src/builders/android.ts b/packages/build-tools/src/builders/android.ts index 97dd46db6..292e3094b 100644 --- a/packages/build-tools/src/builders/android.ts +++ b/packages/build-tools/src/builders/android.ts @@ -59,10 +59,7 @@ async function buildAsync(ctx: BuildContext): Promise { }); await ctx.runBuildPhase(BuildPhase.RESTORE_CACHE, async () => { - await ctx.cacheManager?.restoreCache( - { global: ctx, logger: ctx.logger, workingdir: ctx.workingdir }, - ctx.job.cache - ); + await ctx.cacheManager?.restoreCache(ctx); }); await ctx.runBuildPhase(BuildPhase.POST_INSTALL_HOOK, async () => { @@ -98,10 +95,7 @@ async function buildAsync(ctx: BuildContext): Promise { }); await ctx.runBuildPhase(BuildPhase.SAVE_CACHE, async () => { - await ctx.cacheManager?.saveCache( - { global: ctx, logger: ctx.logger, workingdir: ctx.workingdir }, - ctx.job.cache - ); + await ctx.cacheManager?.saveCache(ctx); }); await ctx.runBuildPhase(BuildPhase.UPLOAD_APPLICATION_ARCHIVE, async () => { diff --git a/packages/build-tools/src/builders/ios.ts b/packages/build-tools/src/builders/ios.ts index 781c8de12..f1039142a 100644 --- a/packages/build-tools/src/builders/ios.ts +++ b/packages/build-tools/src/builders/ios.ts @@ -63,10 +63,7 @@ async function buildAsync(ctx: BuildContext): Promise { }); await ctx.runBuildPhase(BuildPhase.RESTORE_CACHE, async () => { - await ctx.cacheManager?.restoreCache( - { global: ctx, logger: ctx.logger, workingdir: ctx.workingdir }, - ctx.job.cache - ); + await ctx.cacheManager?.restoreCache(ctx); }); await ctx.runBuildPhase(BuildPhase.INSTALL_PODS, async () => { @@ -109,10 +106,7 @@ async function buildAsync(ctx: BuildContext): Promise { }); await ctx.runBuildPhase(BuildPhase.SAVE_CACHE, async () => { - await ctx.cacheManager?.saveCache( - { global: ctx, logger: ctx.logger, workingdir: ctx.workingdir }, - ctx.job.cache - ); + await ctx.cacheManager?.saveCache(ctx); }); await ctx.runBuildPhase(BuildPhase.UPLOAD_APPLICATION_ARCHIVE, async () => { diff --git a/packages/build-tools/src/context.ts b/packages/build-tools/src/context.ts index 160659520..73b483485 100644 --- a/packages/build-tools/src/context.ts +++ b/packages/build-tools/src/context.ts @@ -17,15 +17,14 @@ import { } from '@expo/eas-build-job'; import { BuildTrigger } from '@expo/eas-build-job/dist/common'; import { bunyan } from '@expo/logger'; -import { CacheManager } from '@expo/steps'; import { SpawnOptions, SpawnPromise, SpawnResult } from '@expo/turtle-spawn'; import fs from 'fs-extra'; +import { DynamicCacheManager } from '@expo/steps'; import { resolveBuildPhaseErrorAsync } from './buildErrors/detectError'; import { readAppConfig } from './utils/appConfig'; import { createTemporaryEnvironmentSecretFile } from './utils/environmentSecrets'; import { PackageManager, resolvePackageManager } from './utils/packageManager'; -export { CacheManager } from '@expo/steps'; export type Artifacts = Partial>; @@ -56,6 +55,7 @@ export interface BuildContextOptions { logBuffer: LogBuffer; env: Env; cacheManager?: CacheManager; + dynamicCacheManager?: DynamicCacheManager; /** * @deprecated */ @@ -82,6 +82,7 @@ export class BuildContext { public logger: bunyan; public readonly logBuffer: LogBuffer; public readonly cacheManager?: CacheManager; + public readonly dynamicCacheManager?: DynamicCacheManager; /** * @deprecated */ @@ -115,6 +116,7 @@ export class BuildContext { this.logger = this.defaultLogger; this.logBuffer = options.logBuffer; this.cacheManager = options.cacheManager; + this.dynamicCacheManager = options.dynamicCacheManager; this.runGlobalExpoCliCommand = options.runGlobalExpoCliCommand; this._uploadArtifact = options.uploadArtifact; this.reportError = options.reportError; diff --git a/packages/build-tools/src/customBuildContext.ts b/packages/build-tools/src/customBuildContext.ts index f5adc628b..48fba710a 100644 --- a/packages/build-tools/src/customBuildContext.ts +++ b/packages/build-tools/src/customBuildContext.ts @@ -10,9 +10,13 @@ import { Platform, } from '@expo/eas-build-job'; import { bunyan } from '@expo/logger'; -import { ExternalBuildContextProvider, BuildRuntimePlatform, CacheManager } from '@expo/steps'; +import { + ExternalBuildContextProvider, + BuildRuntimePlatform, + DynamicCacheManager, +} from '@expo/steps'; -import { ArtifactToUpload, BuildContext } from './context'; +import { ArtifactToUpload, BuildContext, CacheManager } from './context'; const platformToBuildRuntimePlatform: Record = { [Platform.ANDROID]: BuildRuntimePlatform.LINUX, @@ -21,6 +25,7 @@ const platformToBuildRuntimePlatform: Record = { export interface BuilderRuntimeApi { uploadArtifact: (spec: { artifact: ArtifactToUpload; logger: bunyan }) => Promise; + cacheManager?: DynamicCacheManager; } export class CustomBuildContext implements ExternalBuildContextProvider { @@ -66,6 +71,7 @@ export class CustomBuildContext implements ExternalBuildContextProvider { this.buildLogsDirectory = path.join(buildCtx.workingdir, 'logs'); this.runtimeApi = { uploadArtifact: (...args) => buildCtx['uploadArtifact'](...args), + cacheManager: buildCtx.dynamicCacheManager, }; this.cacheManager = buildCtx.cacheManager; this.buildDirectory = buildCtx.buildDirectory; diff --git a/packages/build-tools/src/steps/easFunctions.ts b/packages/build-tools/src/steps/easFunctions.ts index 1aba170b0..7da9bb240 100644 --- a/packages/build-tools/src/steps/easFunctions.ts +++ b/packages/build-tools/src/steps/easFunctions.ts @@ -33,8 +33,8 @@ export function getEasFunctions(ctx: CustomBuildContext): BuildFunction[] { createInstallNodeModulesBuildFunction(), createPrebuildBuildFunction(), createFindAndUploadBuildArtifactsBuildFunction(ctx), - createSaveCacheBuildFunction(), - createRestoreCacheBuildFunction(), + createSaveCacheBuildFunction(ctx), + createRestoreCacheBuildFunction(ctx), configureEASUpdateIfInstalledFunction(), injectAndroidCredentialsFunction(), configureAndroidVersionFunction(), diff --git a/packages/build-tools/src/steps/functions/__tests__/cache.test.ts b/packages/build-tools/src/steps/functions/__tests__/cache.test.ts index e57d737df..444188d08 100644 --- a/packages/build-tools/src/steps/functions/__tests__/cache.test.ts +++ b/packages/build-tools/src/steps/functions/__tests__/cache.test.ts @@ -2,47 +2,65 @@ import fs from 'fs/promises'; import os from 'os'; import path from 'path'; +import { Job, Metadata } from '@expo/eas-build-job'; import { BuildRuntimePlatform, BuildStepGlobalContext, + Cache, + DynamicCacheManager, ExternalBuildContextProvider, - CacheManager, } from '@expo/steps'; import { anything, capture, instance, mock, reset, verify, when } from 'ts-mockito'; import { createLogger } from '../../../__mocks__/@expo/logger'; +import { createTestIosJob } from '../../../__tests__/utils/job'; +import { createMockLogger } from '../../../__tests__/utils/logger'; +import { BuildContext } from '../../../context'; +import { CustomBuildContext } from '../../../customBuildContext'; import { createRestoreCacheBuildFunction, createSaveCacheBuildFunction } from '../cache'; -const cacheSaveBuildFunction = createSaveCacheBuildFunction(); -const cacheRestoreBuildFunction = createRestoreCacheBuildFunction(); +const dynamicCacheManagerMock = mock(); +const dynamicCacheManager = instance(dynamicCacheManagerMock); + +const buildCtx = new BuildContext(createTestIosJob({}), { + env: {}, + logBuffer: { getLogs: () => [], getPhaseLogs: () => [] }, + logger: createMockLogger(), + uploadArtifact: jest.fn(), + workingdir: '', + dynamicCacheManager, + runGlobalExpoCliCommand: jest.fn(), +}); +const customContext = new CustomBuildContext(buildCtx); + +const cacheSaveBuildFunction = createSaveCacheBuildFunction(customContext); +const cacheRestoreBuildFunction = createRestoreCacheBuildFunction(customContext); const providerMock = mock(); -const cacheManagerMock = mock(); -const cacheManager = instance(cacheManagerMock); -const initialCache = { downloadUrls: {} }; +const initialCache: Cache = { disabled: false, clear: false, paths: [] }; const provider = instance(providerMock); let ctx: BuildStepGlobalContext; -const existingKey = - 'c7d8e33243968f8675ec0463ad89e11c1e754723695ab9b23dfb8f9ddd389a28-value-8b6e2366e2a2ff8b43556a1dcc5f1cf97ddcf4cdf3c8f9a6d54e0efe2e747922'; - describe('cache functions', () => { let key: string; let paths: string[]; beforeEach(async () => { key = '${ hashFiles("./src/*") }-value'; paths = ['path1', 'path2']; - reset(cacheManagerMock); + reset(dynamicCacheManagerMock); reset(providerMock); const projectSourceDirectory = await fs.mkdtemp(path.join(os.tmpdir(), 'project-')); when(providerMock.logger).thenReturn(createLogger()); when(providerMock.runtimePlatform).thenReturn(BuildRuntimePlatform.LINUX); - when(providerMock.staticContext()).thenReturn({ some: 'key', job: { cache: initialCache } }); - when(providerMock.cacheManager).thenReturn(cacheManager); + when(providerMock.staticContext()).thenReturn({ + metadata: {} as Metadata, + env: {}, + job: { cache: initialCache } as Job, + }); when(providerMock.projectSourceDirectory).thenReturn(projectSourceDirectory); when(providerMock.defaultWorkingDirectory).thenReturn(projectSourceDirectory); when(providerMock.projectTargetDirectory).thenReturn(projectSourceDirectory); @@ -62,9 +80,6 @@ describe('cache functions', () => { }); test('restores cache if it exists', async () => { - when(cacheManagerMock.restoreCache(anything(), anything())); - initialCache.downloadUrls = { [existingKey]: 'url' }; - const buildStep = cacheRestoreBuildFunction.createBuildStepFromFunctionCall(ctx, { callInputs: { key, paths }, }); @@ -73,25 +88,12 @@ describe('cache functions', () => { await buildStep.executeAsync(); - verify(cacheManagerMock.restoreCache(anything(), anything())).once(); + verify(dynamicCacheManagerMock.restoreCache(anything(), anything())).once(); - const [, cache] = capture(cacheManagerMock.restoreCache).first(); + const [, cache] = capture(dynamicCacheManagerMock.restoreCache).first(); expect(cache.key).toMatch(/^\w+-value/); expect(cache.paths).toStrictEqual(paths); }); - - test("doesn't restore cache if it doesn't exist", async () => { - when(cacheManagerMock.restoreCache(anything(), anything())); - initialCache.downloadUrls = { invalidkey: 'url' }; - - const buildStep = cacheRestoreBuildFunction.createBuildStepFromFunctionCall(ctx, { - callInputs: { key, paths }, - }); - - await buildStep.executeAsync(); - - verify(cacheManagerMock.restoreCache(anything(), anything())).never(); - }); }); describe('cacheSaveBuildFunction', () => { @@ -102,35 +104,16 @@ describe('cache functions', () => { }); test('saves cache if it does not exist', async () => { - when(cacheManagerMock.restoreCache(anything(), anything())); - - initialCache.downloadUrls = {}; - const buildStep = cacheSaveBuildFunction.createBuildStepFromFunctionCall(ctx, { callInputs: { key, paths }, }); await buildStep.executeAsync(); - verify(cacheManagerMock.saveCache(anything(), anything())).once(); + verify(dynamicCacheManagerMock.saveCache(anything(), anything())).once(); - const [, cache] = capture(cacheManagerMock.saveCache).first(); + const [, cache] = capture(dynamicCacheManagerMock.saveCache).first(); expect(cache?.key).toMatch(/^\w+-value/); - expect(cache?.paths).toStrictEqual(paths); - }); - - test("doesn't save cache if it exists", async () => { - when(cacheManagerMock.restoreCache(anything(), anything())); - - initialCache.downloadUrls = { [existingKey]: 'url' }; - - const buildStep = cacheSaveBuildFunction.createBuildStepFromFunctionCall(ctx, { - callInputs: { key, paths }, - }); - - await buildStep.executeAsync(); - - verify(cacheManagerMock.saveCache(anything(), anything())).never(); }); }); }); diff --git a/packages/build-tools/src/steps/functions/cache.ts b/packages/build-tools/src/steps/functions/cache.ts index 38b5c3099..9b2934af9 100644 --- a/packages/build-tools/src/steps/functions/cache.ts +++ b/packages/build-tools/src/steps/functions/cache.ts @@ -1,5 +1,3 @@ -import crypto from 'crypto'; - import { BuildFunction, BuildStepInput, @@ -7,16 +5,9 @@ import { BuildStepOutput, } from '@expo/steps'; -function createCacheKey(cacheKey: string, paths: string[]): string { - const hash = crypto.createHash('sha256'); - hash.update(paths.sort().join('')); - - const pathsHash = hash.digest('hex'); - - return `${cacheKey}-${pathsHash}`; -} +import { CustomBuildContext } from '../../customBuildContext'; -export function createRestoreCacheBuildFunction(): BuildFunction { +export function createRestoreCacheBuildFunction(ctx: CustomBuildContext): BuildFunction { return new BuildFunction({ namespace: 'eas', id: 'restore-cache', @@ -30,6 +21,7 @@ export function createRestoreCacheBuildFunction(): BuildFunction { BuildStepInput.createProvider({ id: 'paths', required: true, + defaultValue: [], allowedValueTypeName: BuildStepInputValueTypeName.JSON, }), ], @@ -38,28 +30,34 @@ export function createRestoreCacheBuildFunction(): BuildFunction { id: 'cache_key', required: true, }), + BuildStepOutput.createProvider({ + id: 'cache_paths', + required: false, + }), ], fn: async (stepsCtx, { inputs, outputs }) => { - const cacheManager = stepsCtx.global.cacheManager; + const cacheManager = ctx.runtimeApi.cacheManager; if (!cacheManager) { return; } - outputs.cache_key.set(inputs.key.value as string); + const key = inputs.key.value as string; const paths = inputs.paths.value as [string]; - const key = createCacheKey(inputs.key.value as string, paths); - cacheManager.generateUrls = true; + outputs.cache_key.set(key); + if (paths.length > 0) { + outputs.cache_paths.set(JSON.stringify(paths)); + } + const { job: { cache }, - } = stepsCtx.global.provider.staticContext(); + } = stepsCtx.global.staticContext; - if (!(cache.downloadUrls && key in cache.downloadUrls)) { - stepsCtx.logger.info(`Cache ${key} does not exist, skipping restoring`); - return; - } - stepsCtx.logger.info(`Restoring cache ${key} in:\n ${paths.join('\n')}`); + stepsCtx.logger.info(`Restoring cache ${inputs.key.value} from:`); + paths.forEach((path) => { + stepsCtx.logger.info(`- ${path}`); + }); await cacheManager.restoreCache(stepsCtx, { ...cache, @@ -72,7 +70,7 @@ export function createRestoreCacheBuildFunction(): BuildFunction { }); } -export function createSaveCacheBuildFunction(): BuildFunction { +export function createSaveCacheBuildFunction(ctx: CustomBuildContext): BuildFunction { return new BuildFunction({ namespace: 'eas', id: 'save-cache', @@ -83,40 +81,20 @@ export function createSaveCacheBuildFunction(): BuildFunction { required: true, allowedValueTypeName: BuildStepInputValueTypeName.STRING, }), - BuildStepInput.createProvider({ - id: 'paths', - required: true, - allowedValueTypeName: BuildStepInputValueTypeName.JSON, - }), ], fn: async (stepsCtx, { inputs }) => { - const cacheManager = stepsCtx.global.cacheManager; + const cacheManager = ctx.runtimeApi.cacheManager; if (!cacheManager) { return; } - const paths = inputs.paths.value as [string]; - const key = createCacheKey(inputs.key.value as string, paths); - - const { - job: { cache }, - } = stepsCtx.global.provider.staticContext(); - if (cache.downloadUrls && key in cache.downloadUrls) { - stepsCtx.logger.info(`Cache ${key} already exists, skipping saving`); - return; - } - - stepsCtx.logger.info(`Saving cache from:\n ${paths.join('\n')}`); - - cacheManager.generateUrls = true; await cacheManager.saveCache(stepsCtx, { disabled: false, clear: false, - key, - paths, + key: inputs.key.value as string, + paths: [], }); - stepsCtx.logger.info('Cache saved'); }, }); } diff --git a/packages/eas-build-job/src/common.ts b/packages/eas-build-job/src/common.ts index 594603118..5056f2b27 100644 --- a/packages/eas-build-job/src/common.ts +++ b/packages/eas-build-job/src/common.ts @@ -117,7 +117,6 @@ export interface Cache { */ customPaths?: string[]; paths: string[]; - downloadUrls?: Record; } export const CacheSchema = Joi.object({ diff --git a/packages/steps/src/BuildStepContext.ts b/packages/steps/src/BuildStepContext.ts index 438658af1..b70b507a4 100644 --- a/packages/steps/src/BuildStepContext.ts +++ b/packages/steps/src/BuildStepContext.ts @@ -5,24 +5,21 @@ import { BuildStaticContext } from '@expo/eas-build-job'; import { bunyan } from '@expo/logger'; import { v4 as uuidv4 } from 'uuid'; -import { BuildRuntimePlatform } from './BuildRuntimePlatform.js'; import { BuildStep, BuildStepOutputAccessor, SerializedBuildStepOutputAccessor, } from './BuildStep.js'; -import { BuildStepEnv } from './BuildStepEnv.js'; -import { CacheManager } from './cacheUtils.js'; -import { BuildStepRuntimeError } from './errors.js'; import { getObjectValueForInterpolation, interpolateWithGlobalContext, parseOutputPath, } from './utils/template.js'; +import { BuildStepRuntimeError } from './errors.js'; +import { BuildRuntimePlatform } from './BuildRuntimePlatform.js'; +import { BuildStepEnv } from './BuildStepEnv.js'; interface SerializedExternalBuildContextProvider { - buildDirectory: string; - projectRootDirectory: string; projectSourceDirectory: string; projectTargetDirectory: string; defaultWorkingDirectory: string; @@ -33,15 +30,12 @@ interface SerializedExternalBuildContextProvider { } export interface ExternalBuildContextProvider { - buildDirectory: string; - projectRootDirectory: string; readonly projectSourceDirectory: string; readonly projectTargetDirectory: string; readonly defaultWorkingDirectory: string; readonly buildLogsDirectory: string; readonly runtimePlatform: BuildRuntimePlatform; readonly logger: bunyan; - readonly cacheManager?: CacheManager; readonly staticContext: () => BuildStaticContext; @@ -61,25 +55,16 @@ export class BuildStepGlobalContext { public readonly runtimePlatform: BuildRuntimePlatform; public readonly baseLogger: bunyan; private didCheckOut = false; - public readonly cacheManager?: CacheManager; private stepById: Record = {}; constructor( - public readonly provider: ExternalBuildContextProvider, + private readonly provider: ExternalBuildContextProvider, public readonly skipCleanup: boolean ) { this.stepsInternalBuildDirectory = path.join(os.tmpdir(), 'eas-build', uuidv4()); this.runtimePlatform = provider.runtimePlatform; this.baseLogger = provider.logger; - this.cacheManager = provider.cacheManager; - } - - public get buildDirectory(): string { - return this.provider.buildDirectory; - } - public get projectRootDirectory(): string { - return this.provider.projectRootDirectory; } public get projectSourceDirectory(): string { @@ -160,8 +145,6 @@ export class BuildStepGlobalContext { defaultWorkingDirectory: this.provider.defaultWorkingDirectory, buildLogsDirectory: this.provider.buildLogsDirectory, runtimePlatform: this.provider.runtimePlatform, - buildDirectory: this.provider.buildDirectory, - projectRootDirectory: this.provider.projectRootDirectory, staticContext: this.provider.staticContext(), env: this.provider.env, }, @@ -179,8 +162,6 @@ export class BuildStepGlobalContext { defaultWorkingDirectory: serialized.provider.defaultWorkingDirectory, buildLogsDirectory: serialized.provider.buildLogsDirectory, runtimePlatform: serialized.provider.runtimePlatform, - buildDirectory: serialized.provider.buildDirectory, - projectRootDirectory: serialized.provider.projectRootDirectory, logger, staticContext: () => serialized.provider.staticContext, env: serialized.provider.env, @@ -219,10 +200,6 @@ export class BuildStepContext { this.relativeWorkingDirectory = relativeWorkingDirectory; } - public get workingdir(): string { - return this.workingDirectory; - } - public get global(): BuildStepGlobalContext { return this.ctx; } diff --git a/packages/steps/src/BuildStepInput.ts b/packages/steps/src/BuildStepInput.ts index 4ed541045..7ae4c0c24 100644 --- a/packages/steps/src/BuildStepInput.ts +++ b/packages/steps/src/BuildStepInput.ts @@ -113,7 +113,11 @@ export class BuildStepInput< } private requiresInterpolation(rawValue: any): rawValue is string { - return typeof rawValue === 'string'; + return !( + rawValue === undefined || + typeof rawValue === 'boolean' || + typeof rawValue === 'number' + ); } public validateFunctions( @@ -161,9 +165,7 @@ export class BuildStepInput< } if (!this.requiresInterpolation(rawValue)) { - const currentTypeName = - typeof rawValue === 'object' ? BuildStepInputValueTypeName.JSON : typeof rawValue; - if (currentTypeName !== this.allowedValueTypeName && rawValue !== undefined) { + if (typeof rawValue !== this.allowedValueTypeName && rawValue !== undefined) { throw new BuildStepRuntimeError( `Input parameter "${this.id}" for step "${this.stepDisplayName}" must be of type "${this.allowedValueTypeName}".` ); diff --git a/packages/steps/src/__tests__/BuildStepContext-test.ts b/packages/steps/src/__tests__/BuildStepContext-test.ts index f660fbe30..dbbce95cc 100644 --- a/packages/steps/src/__tests__/BuildStepContext-test.ts +++ b/packages/steps/src/__tests__/BuildStepContext-test.ts @@ -101,8 +101,6 @@ describe(BuildStepGlobalContext, () => { projectTargetDirectory: '/d/e/f', defaultWorkingDirectory: '/d/e/f/i', buildLogsDirectory: '/non/existent/dir', - projectRootDirectory: '/a/b/c', - buildDirectory: '/d/e/f', runtimePlatform: BuildRuntimePlatform.DARWIN, staticContext: { a: 1 }, env: {}, @@ -123,8 +121,6 @@ describe(BuildStepGlobalContext, () => { projectTargetDirectory: '/d/e/f', defaultWorkingDirectory: '/g/h/i', buildLogsDirectory: '/j/k/l', - projectRootDirectory: '/a/b/c', - buildDirectory: '/d/e/f', runtimePlatform: BuildRuntimePlatform.DARWIN, staticContext: { a: 1 } as unknown as BuildStaticContext, env: {}, @@ -140,8 +136,6 @@ describe(BuildStepGlobalContext, () => { expect(ctx.skipCleanup).toBe(true); expect(ctx.projectSourceDirectory).toBe('/a/b/c'); expect(ctx.projectTargetDirectory).toBe('/d/e/f'); - expect(ctx.projectRootDirectory).toBe('/a/b/c'); - expect(ctx.buildDirectory).toBe('/d/e/f'); expect(ctx.buildLogsDirectory).toBe('/j/k/l'); expect(ctx.staticContext).toEqual({ a: 1 }); expect(ctx.env).toEqual({}); diff --git a/packages/steps/src/cacheUtils.ts b/packages/steps/src/cacheUtils.ts index a990aacca..d433884d1 100644 --- a/packages/steps/src/cacheUtils.ts +++ b/packages/steps/src/cacheUtils.ts @@ -1,4 +1,4 @@ -import { bunyan } from '@expo/logger'; +import { BuildStepContext } from './BuildStepContext.js'; export interface Cache { disabled: boolean; @@ -7,25 +7,9 @@ export interface Cache { cacheDefaultPaths?: boolean; customPaths?: string[]; paths: string[]; - downloadUrls?: Record; } -interface CacheableContextCtx { - buildDirectory: string; - projectRootDirectory?: string; - env: Record; -} - -export interface CacheableContext { - logger: bunyan; - global: CacheableContextCtx; - workingdir: string; -} - -export interface CacheManager { - // TOOD: Change any to CacheableContext - saveCache(ctx: any, cache?: Cache): Promise; - // TOOD: Change any to CacheableContext - restoreCache(ctx: any, cache: Cache): Promise; - generateUrls?: boolean; +export interface DynamicCacheManager { + saveCache(ctx: BuildStepContext, cache: Cache): Promise; + restoreCache(ctx: BuildStepContext, cache: Cache): Promise; } diff --git a/packages/steps/src/cli/cli.ts b/packages/steps/src/cli/cli.ts index 8cb7f1dec..e0d025025 100644 --- a/packages/steps/src/cli/cli.ts +++ b/packages/steps/src/cli/cli.ts @@ -7,7 +7,6 @@ import { BuildConfigParser } from '../BuildConfigParser.js'; import { BuildRuntimePlatform } from '../BuildRuntimePlatform.js'; import { BuildStepGlobalContext, ExternalBuildContextProvider } from '../BuildStepContext.js'; import { BuildStepEnv } from '../BuildStepEnv.js'; -import { CacheManager } from '../cacheUtils.js'; import { BuildWorkflowError } from '../errors.js'; const logger = createLogger({ @@ -28,7 +27,6 @@ export class CliContextProvider implements ExternalBuildContextProvider { public readonly buildDirectory: string, public readonly projectRootDirectory: string ) {} - cacheManager?: CacheManager | undefined; public get env(): BuildStepEnv { return this._env; } diff --git a/packages/steps/src/utils/template.ts b/packages/steps/src/utils/template.ts index a4c3b0a4c..dd2501fad 100644 --- a/packages/steps/src/utils/template.ts +++ b/packages/steps/src/utils/template.ts @@ -74,59 +74,6 @@ export async function interpolateWithFunctionsAsync( return result; } -export function templateFunctionsAndArgsIterator(templateString: string): Iterable { - return { - [Symbol.iterator]() { - const regex = new RegExp(BUILD_STEP_FUNCTION_EXPRESSION_REGEXP, 'g'); - let functionCallMatch; - return { - next() { - while ((functionCallMatch = regex.exec(templateString))) { - if (functionCallMatch?.groups) { - const templateFunction = functionCallMatch.groups['fun']; - try { - const args = JSON.parse(`[${functionCallMatch.groups['args']}]`.replace(/'/g, '"')); - return { done: false, value: { templateFunction, args, functionCallMatch } }; - } catch (e) { - if (e instanceof SyntaxError) { - throw new BuildConfigError(`contains syntax error in "${templateString}"`); - } - throw e; - } - } - } - return { done: true, value: null }; - }, - }; - }, - }; -} - -export function iterateWithFunctions( - templateString: string, - fn: (fn: string, args: string[]) => any -): void { - const iterator = templateFunctionsAndArgsIterator(templateString); - for (const { templateFunction, args } of iterator) { - fn(templateFunction, args); - } -} - -export async function interpolateWithFunctionsAsync( - templateString: string, - fn: (fn: string, args: string[]) => Promise -): Promise { - let result = templateString; - - const iterator = templateFunctionsAndArgsIterator(templateString); - - for (const { templateFunction, args, functionCallMatch } of iterator) { - const value = await fn(templateFunction, args); - result = result.replace(functionCallMatch[0], value); - } - return result; -} - export function interpolateWithOutputs( interpolableValue: InterpolableType, fn: (path: string) => string