export function UpdateManifestFiles()

in src/manifest.ts [16:73]


export function UpdateManifestFiles(
  manifestPaths: string[],
  images: string[],
  newManifestDirectory: string
): string[] {
  const newManifestPaths = [];

  // retrieve image names
  const imageObjs = images.map((image) => {
    return {
      name: GetImageName(image),
      fullImage: image,
    };
  });

  manifestPaths.forEach((manifestPath: string) => {
    core.debug(`Loading manifest ${manifestPath}`);
    const contents = fs.readFileSync(manifestPath).toString();
    const manifestObjs: any[] = k8s.loadAllYaml(contents);

    // swap images
    const swapImagesFn = (key: string, value: string) => {
      if (key !== "image") return value;

      const currentImageName = GetImageName(value);
      for (const { name, fullImage } of imageObjs) {
        if (name === currentImageName) {
          core.debug(
            `swapping image ${value} to ${fullImage} for ${manifestPath}`
          );
          return fullImage;
        }
      }

      return value; // image is not being swapped
    };

    manifestObjs.forEach((manifestObj) =>
      TraverseObject(manifestObj, swapImagesFn)
    );

    // write updated manifest
    core.debug(`Writing manifest ${manifestPath}`);
    const updatedManifest = manifestObjs
      .map((manifestObj) => k8s.dumpYaml(manifestObj))
      .join(`${YAML_DOCUMENT_SEPARATOR}\n`);
    const fileName = path.join(
      newManifestDirectory,
      path.basename(manifestPath)
    );

    fs.writeFileSync(fileName, updatedManifest);
    newManifestPaths.push(fileName);
    core.info(`Manifest ${manifestPath} written to ${fileName}`);
  });

  return newManifestPaths;
}