All files / packages/sds-release-manager/src/commands publish-v1-gitcore-css.ts

94.11% Statements 32/34
83.33% Branches 20/24
50% Functions 2/4
93.1% Lines 27/29

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95                                                            7x 2x   5x 7x 7x 7x 7x 7x                                   5x           1x                     5x       5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x    
/**
 * CLI entry point for `publish-v1-gitcore-css`.
 *
 * Wires real gitcore/LFS services, the packet loader, and the classifier into the
 * publish orchestrator, then posts the validation comment and prints a summary.
 */
import path from 'node:path';
import { loadConfiguration } from '../config.js';
import {
  loadAuditPacket,
  runPublishV1GitcoreCss,
  type PublishOutcome,
} from '../orchestrators/publish-v1-gitcore-css.js';
import { loadRepositoryClassifier } from '../services/core-css-preparation-service.js';
import { GitCoreService } from '../services/gitcore-service.js';
import { GitLfsService } from '../services/git-lfs-service.js';
import { createLogger } from '../utils/logger.js';
import { buildValidationComment } from '../utils/validation-comment.js';
 
export type PublishV1GitcoreCssCommandOptions = {
  result?: string;
  report?: string;
  wi: string;
  dryRun?: boolean;
  publishVersionOnly?: boolean;
};
 
export async function publishV1GitcoreCssCommand(options: PublishV1GitcoreCssCommandOptions): Promise<void> {
  // Accept the packet by either --result (the file) or --report (its dir), but
  // never both; derive the result.json path from --report when given.
  if (Boolean(options.result) === Boolean(options.report)) {
    throw new Error('Provide exactly one of --result or --report');
  }
  const result = options.result ?? path.join(options.report as string, 'result.json');
  const config = loadConfiguration();
  const logger = createLogger();
  const gitcore = new GitCoreService(logger, config.gitcoreHost);
  const lfs = new GitLfsService(logger, config.gitLfsBatchEndpoint, config.gitLfsCredentialHost);
  const outcome = await runPublishV1GitcoreCss(
    {
      result,
      wi: options.wi,
      dryRun: Boolean(options.dryRun),
      publishVersionOnly: Boolean(options.publishVersionOnly),
    },
    {
      gitcore,
      lfs,
      loadPacket: (packetPath, manifest) => loadAuditPacket(packetPath, manifest),
      loadClassifier: () => loadRepositoryClassifier(),
      logger,
    },
  );
 
  // Post the byte-level validation comment only when a PR was newly created, so
  // reruns against an existing PR do not duplicate it.
  if (
    outcome.status === 'published' &&
    outcome.prCreated === true &&
    outcome.prUrl &&
    outcome.verdict !== 'no-change'
  ) {
    await gitcore.addPullRequestComment(
      outcome.repo,
      outcome.prUrl,
      buildValidationComment({
        version: outcome.version,
        verdict: outcome.verdict,
        target: outcome.target,
        artifacts: outcome.artifacts,
      }),
    );
  }
  printSummary(outcome, path.dirname(result));
}
 
function printSummary(outcome: PublishOutcome, reportDir: string): void {
  console.log();
  console.log('=== publish-v1-gitcore-css summary ===');
  console.log(`status:          ${outcome.status}`);
  console.log(`verdict:         ${outcome.verdict}`);
  console.log(`repo:            ${outcome.repo}`);
  console.log(`target:          ${outcome.target}`);
  console.log(`base SHA:        ${outcome.baseSha}`);
  Eif (outcome.branch) console.log(`branch:          ${outcome.branch}`);
  Eif (outcome.commitSha) console.log(`commit SHA:      ${outcome.commitSha}`);
  if (outcome.prUrl) console.log(`PR:              ${outcome.prUrl}`);
  console.log(`uploaded:        ${outcome.uploaded?.length ?? 0}`);
  console.log(`already present: ${outcome.alreadyPresent?.length ?? 0}`);
  if (outcome.reason) console.log(`reason:          ${outcome.reason}`);
  if (outcome.status === 'dry-run') console.log('intended actions: upload LFS, commit, create ref, open PR');
  console.log(`packet/report:   ${reportDir}`);
  console.log('Step 10 (Slack reviewer post) is manual — see release-v1-to-gitcore.md');
}