Skip to content
Snippets Groups Projects
Select Git revision
  • 7b677cd50a7a392943f43d43ad3200047908c5a0
  • main default protected
  • renovate/main-vitest-monorepo
  • next
  • fix/36615b-branch-reuse-no-cache
  • chore/punycode
  • fix/36615-branch-reuse-bug
  • renovate/main-redis-5.x
  • renovate/main-xmldoc-2.x
  • refactor/pin-new-value
  • feat/36219--git-x509-signing
  • feat/structured-logger
  • hotfix/39.264.1
  • feat/skip-dangling
  • gh-readonly-queue/next/pr-36034-7a061c4ca1024a19e2c295d773d9642625d1c2be
  • hotfix/39.238.3
  • refactor/gitlab-auto-approve
  • feat/template-strings
  • gh-readonly-queue/next/pr-35654-137d934242c784e0c45d4b957362214f0eade1d7
  • fix/32307-global-extends-merging
  • fix/32307-global-extends-repositories
  • 41.16.2
  • 41.16.1
  • 41.16.0
  • 41.15.0
  • 41.14.0
  • 41.13.1
  • 41.13.0
  • 41.12.1
  • 41.12.0
  • 41.11.1
  • 41.11.0
  • 41.10.1
  • 41.10.0
  • 41.9.0
  • 41.8.0
  • 41.7.2
  • 41.7.1
  • 41.7.0
  • 41.6.4
  • 41.6.3
41 results

api.ts

Blame
  • artifacts.ts 2.05 KiB
    import { quote } from 'shlex';
    import { logger } from '../../../logger';
    import { exec } from '../../../util/exec';
    import type { ExecOptions } from '../../../util/exec/types';
    import { readLocalFile } from '../../../util/fs';
    import type { UpdateArtifact, UpdateArtifactsResult } from '../types';
    import { isSystemManifest } from './common';
    
    export async function updateArtifacts({
      packageFileName,
      updatedDeps,
    }: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> {
      const systemDep = updatedDeps[0];
      if (!isSystemManifest(packageFileName) || !systemDep?.newVersion) {
        return null;
      }
      const existingFileContent = await readLocalFile(packageFileName);
      try {
        logger.debug(`Updating Flux system manifests`);
        const args: string[] = ['--export'];
        if (systemDep.managerData?.components) {
          args.push('--components', quote(systemDep.managerData.components));
        }
        const cmd = `flux install ${args.join(' ')} > ${quote(packageFileName)}`;
        const execOptions: ExecOptions = {
          docker: {
            image: 'sidecar',
          },
          toolConstraints: [
            {
              toolName: 'flux',
              constraint: updatedDeps[0].newVersion,
            },
          ],
        };
        const result = await exec(cmd, execOptions);
    
        const newFileContent = await readLocalFile(packageFileName);
        if (!newFileContent) {
          logger.debug('Cannot read new flux file content');
          return [
            {
              artifactError: {
                lockFile: packageFileName,
                stderr: result.stderr,
              },
            },
          ];
        }
        if (newFileContent === existingFileContent) {
          logger.debug('Flux contents are unchanged');
          return null;
        }
    
        return [
          {
            file: {
              type: 'addition',
              path: packageFileName,
              contents: newFileContent,
            },
          },
        ];
      } catch (err) {
        logger.debug({ err }, 'Error generating new Flux system manifests');
        return [
          {
            artifactError: {
              lockFile: packageFileName,
              stderr: err.message,
            },
          },
        ];
      }
    }