Skip to content

Commit

Permalink
fix(helmfile): make resolving deps in multi-doc files more stable (#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
pathob authored Dec 5, 2023
1 parent c426975 commit 4c4bd3a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/modules/manager/helmfile/__fixtures__/multidoc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ repositories:
- name: prometheus-community
url: https://prometheus-community.github.io/helm-charts

---

templates:
external-chart: &external-chart
missingFileHandler: Debug
Expand Down
14 changes: 14 additions & 0 deletions lib/modules/manager/helmfile/extract.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { codeBlock } from 'common-tags';
import { Fixtures } from '../../../../test/fixtures';
import { fs } from '../../../../test/util';
import { GlobalConfig } from '../../../config/global';
Expand All @@ -14,6 +15,19 @@ describe('modules/manager/helmfile/extract', () => {
GlobalConfig.set({ localDir });
});

it('skip null YAML document', async () => {
const content = codeBlock`
~
`;
const fileName = 'helmfile.yaml';
const result = await extractPackageFile(content, fileName, {
registryAliases: {
stable: 'https://charts.helm.sh/stable',
},
});
expect(result).toBeNull();
});

it('returns null if no releases', async () => {
const content = `
repositories:
Expand Down
16 changes: 13 additions & 3 deletions lib/modules/manager/helmfile/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function extractPackageFile(
): Promise<PackageFileContent | null> {
const deps: PackageDependency[] = [];
let docs: Doc[];
const registryAliases: Record<string, string> = {};
let registryAliases: Record<string, string> = {};
// Record kustomization usage for all deps, since updating artifacts is run on the helmfile.yaml as a whole.
let needKustomize = false;
try {
Expand All @@ -47,16 +47,26 @@ export async function extractPackageFile(
return null;
}
for (const doc of docs) {
if (!(doc && is.array(doc.releases))) {
if (!doc) {
continue;
}

// Always check for repositories in the current document and override the existing ones if any (as YAML does)
if (doc.repositories) {
registryAliases = {};
for (let i = 0; i < doc.repositories.length; i += 1) {
registryAliases[doc.repositories[i].name] = doc.repositories[i].url;
}
logger.debug(
{ registryAliases, packageFile },
`repositories discovered.`,
);
}

// Skip extraction if the document contains no releases
if (!is.array(doc.releases)) {
continue;
}
logger.debug({ registryAliases }, 'repositories discovered.');

for (const dep of doc.releases) {
let depName = dep.chart;
Expand Down

0 comments on commit 4c4bd3a

Please sign in to comment.