Skip to content

Commit

Permalink
emit a JSON summary of the result of the features publish command (#…
Browse files Browse the repository at this point in the history
…305)

* emit a JSON summary of the result of the features package command

* linter

* json result for templates too
  • Loading branch information
joshspicer authored Dec 1, 2022
1 parent 1289e4e commit 0a3e2dc
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/spec-node/collectionCommonUtils/publishCommandImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function doPublishCommand(version: string, ociRef: OCIRef, outputDi
const publishedVersions = await getPublishedVersions(ociRef, output);

if (!publishedVersions) {
return false;
return;
}

const semanticVersions: string[] | undefined = getSermanticVersions(version, publishedVersions, output);
Expand All @@ -54,11 +54,11 @@ export async function doPublishCommand(version: string, ociRef: OCIRef, outputDi
const pathToTgz = path.join(outputDir, getArchiveName(ociRef.id, collectionType));
if (! await pushOCIFeatureOrTemplate(output, ociRef, pathToTgz, semanticVersions, collectionType)) {
output.write(`(!) ERR: Failed to publish ${collectionType}: '${ociRef.resource}'`, LogLevel.Error);
return false;
return;
}
}
output.write(`Published ${collectionType}: ${ociRef.id}...`, LogLevel.Info);
return true;
output.write(`Published ${collectionType}: '${ociRef.id}'`, LogLevel.Info);
return semanticVersions ?? []; // Not an error if no versions were published, likely they just already existed and were skipped.
}

export async function doPublishMetadata(collectionRef: OCICollectionRef, outputDir: string, output: Log, collectionType: string) {
Expand All @@ -70,6 +70,6 @@ export async function doPublishMetadata(collectionRef: OCICollectionRef, outputD
output.write(`(!) ERR: Failed to publish collection metadata: ${OCICollectionFileName}`, LogLevel.Error);
return false;
}
output.write('Published collection metadata...', LogLevel.Info);
output.write('Published collection metadata.', LogLevel.Info);
return true;
}
2 changes: 1 addition & 1 deletion src/spec-node/featuresCLI/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async function featuresPackage({
const output = createLog({
logLevel: mapLogLevel(inputLogLevel),
logFormat: 'text',
log: (str) => process.stdout.write(str),
log: (str) => process.stderr.write(str),
terminalDimensions: undefined,
}, pkg, new Date(), disposables);

Expand Down
14 changes: 12 additions & 2 deletions src/spec-node/featuresCLI/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async function featuresPublish({
const output = createLog({
logLevel: mapLogLevel(inputLogLevel),
logFormat: 'text',
log: (str) => process.stdout.write(str),
log: (str) => process.stderr.write(str),
terminalDimensions: undefined,
}, pkg, new Date(), disposables);

Expand All @@ -67,6 +67,8 @@ async function featuresPublish({
process.exit(1);
}

let result = {};

for (const f of metadata.features) {
output.write(`Processing feature: ${f.id}...`, LogLevel.Info);

Expand All @@ -82,10 +84,16 @@ async function featuresPublish({
process.exit(1);
}

if (! await doPublishCommand(f.version, featureRef, outputDir, output, collectionType)) {
const publishResult = await doPublishCommand(f.version, featureRef, outputDir, output, collectionType);
if (!publishResult) {
output.write(`(!) ERR: Failed to publish '${resource}'`, LogLevel.Error);
process.exit(1);
}

result = {
...result,
[f.id]: publishResult,
};
}

const featureCollectionRef: OCICollectionRef | undefined = getCollectionRef(output, registry, namespace);
Expand All @@ -99,6 +107,8 @@ async function featuresPublish({
process.exit(1);
}

console.log(JSON.stringify(result));

// Cleanup
await rmLocal(outputDir, { recursive: true, force: true });
await dispose();
Expand Down
22 changes: 19 additions & 3 deletions src/spec-node/templatesCLI/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function templatesPublish({
const output = createLog({
logLevel: mapLogLevel(inputLogLevel),
logFormat: 'text',
log: (str) => process.stdout.write(str),
log: (str) => process.stderr.write(str),
terminalDimensions: undefined,
}, pkg, new Date(), disposables);

Expand All @@ -68,6 +68,8 @@ async function templatesPublish({
process.exit(1);
}

let result = {};

for (const t of metadata.templates) {
output.write(`Processing template: ${t.id}...`, LogLevel.Info);

Expand All @@ -83,7 +85,16 @@ async function templatesPublish({
process.exit(1);
}

await doPublishCommand(t.version, templateRef, outputDir, output, collectionType);
const publishResult = await doPublishCommand(t.version, templateRef, outputDir, output, collectionType);
if (!publishResult) {
output.write(`(!) ERR: Failed to publish '${resource}'`, LogLevel.Error);
process.exit(1);
}

result = {
...result,
[t.id]: publishResult,
};
}

const templateCollectionRef: OCICollectionRef | undefined = getCollectionRef(output, registry, namespace);
Expand All @@ -92,7 +103,12 @@ async function templatesPublish({
process.exit(1);
}

await doPublishMetadata(templateCollectionRef, outputDir, output, collectionType);
if (! await doPublishMetadata(templateCollectionRef, outputDir, output, collectionType)) {
output.write(`(!) ERR: Failed to publish '${templateCollectionRef.registry}/${templateCollectionRef.path}'`, LogLevel.Error);
process.exit(1);
}

console.log(JSON.stringify(result));

// Cleanup
await rmLocal(outputDir, { recursive: true, force: true });
Expand Down

0 comments on commit 0a3e2dc

Please sign in to comment.