Skip to content

Commit

Permalink
Merge pull request #69 from projectsyn/fix/failure-rendering-inventory
Browse files Browse the repository at this point in the history
Do not fail renovate if rendering the inventory failed
  • Loading branch information
glrf authored Jul 29, 2022
2 parents 6acf6a0 + de5e310 commit 18dc49f
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions src/commodore/inventory.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { join } from 'path';

import { execSync } from 'child_process';

import { logger } from 'renovate/dist/logger';
Expand All @@ -17,14 +19,11 @@ export async function writeFactsFile(
facts: Facts
): Promise<string> {
/* Write facts class for `commodore inventory component` */
const factsPath: string = `${cacheDir()}/${cacheKey}-facts.yaml`;
try {
await writeYamlFile(factsPath, {
parameters: { facts: pruneObject(facts) },
});
} catch (err) {
logger.error(`Error writing facts YAML: ${err}`);
}
const factsPath: string = join(cacheDir(), `${cacheKey}-facts.yaml`);
await writeYamlFile(factsPath, {
parameters: { facts: pruneObject(facts) },
});

return factsPath;
}

Expand All @@ -41,11 +40,22 @@ export async function renderInventory(
return cachedVersions;
}

const factsPath: string = await writeFactsFile(cacheKey('', facts), facts);

/* construct and execute Commodore command */
var command = `commodore inventory show ${globalPath} ${repoPath} -ojson -f ${factsPath} -f ${extraValuesPath}`;
let factsPath: string = '';
try {
logger.debug(
`Writing facts file for dist: ${facts.distribution}, cloud: ${facts.cloud}, region: ${facts.region}`
);
factsPath = await writeFactsFile(cacheKey('', facts), facts);
} catch (err) {
logger.warn(`Error writing facts YAML: ${err}`);
return {
components: new Map(),
packages: new Map(),
};
}
try {
/* construct and execute Commodore command */
var command = `commodore inventory show ${globalPath} ${repoPath} -ojson -f ${factsPath} -f ${extraValuesPath}`;
const result: string = execSync(command, { stdio: 'pipe' }).toString();
const resp: any = JSON.parse(result);

Expand All @@ -61,7 +71,7 @@ export async function renderInventory(
return params;
} catch (e: any) {
const stderr = e.stderr.toString();
logger.error(`Error rendering reclass inventory: ${stderr}`);
logger.warn(`Error rendering reclass inventory: ${stderr}`);
return {
components: new Map(),
packages: new Map(),
Expand Down

0 comments on commit 18dc49f

Please sign in to comment.