From 0b521309951058f7f10fe9c3495fb7bd28b9f43e Mon Sep 17 00:00:00 2001 From: lstoeferle <48953604+lstoeferle@users.noreply.github.com> Date: Wed, 13 Mar 2024 09:27:42 +0100 Subject: [PATCH 1/4] feat(terragrunt): add support for gitlab-tags datasource --- lib/modules/manager/terragrunt/index.ts | 2 ++ .../manager/terragrunt/modules.spec.ts | 30 ++++++++++++++++++- lib/modules/manager/terragrunt/modules.ts | 14 +++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/lib/modules/manager/terragrunt/index.ts b/lib/modules/manager/terragrunt/index.ts index 58864cf7f57085..944e45c1c485a4 100644 --- a/lib/modules/manager/terragrunt/index.ts +++ b/lib/modules/manager/terragrunt/index.ts @@ -1,6 +1,7 @@ import type { Category } from '../../../constants'; import { GitTagsDatasource } from '../../datasource/git-tags'; import { GithubTagsDatasource } from '../../datasource/github-tags'; +import { GitlabTagsDatasource } from '../../datasource/gitlab-tags'; import { TerraformModuleDatasource } from '../../datasource/terraform-module'; export { updateArtifacts } from './artifacts'; @@ -9,6 +10,7 @@ export { extractPackageFile } from './extract'; export const supportedDatasources = [ GitTagsDatasource.id, GithubTagsDatasource.id, + GitlabTagsDatasource.id, TerraformModuleDatasource.id, ]; diff --git a/lib/modules/manager/terragrunt/modules.spec.ts b/lib/modules/manager/terragrunt/modules.spec.ts index b2b30361860704..8e53ae6e70f279 100644 --- a/lib/modules/manager/terragrunt/modules.spec.ts +++ b/lib/modules/manager/terragrunt/modules.spec.ts @@ -1,4 +1,8 @@ -import { gitTagsRefMatchRegex, githubRefMatchRegex } from './modules'; +import { + gitTagsRefMatchRegex, + githubRefMatchRegex, + gitlabRefMatchRegex, +} from './modules'; describe('modules/manager/terragrunt/modules', () => { describe('githubRefMatchRegex', () => { @@ -23,6 +27,30 @@ describe('modules/manager/terragrunt/modules', () => { }); }); + describe('gitlabRefMatchRegex', () => { + it('should split project and tag from source', () => { + const groups = gitlabRefMatchRegex.exec( + 'gitlab.my-domain.com/hashicorp/example//sub-directory?ref=v1.0.0', + )?.groups; + expect(groups).toEqual({ + host: 'gitlab.my-domain.com', + project: 'hashicorp/example', + tag: 'v1.0.0', + }); + }); + + it('should parse alpha-numeric characters as well as dots, underscores, and dashes in repo names', () => { + const groups = gitlabRefMatchRegex.exec( + 'gitlab.my-domain.com:1234/hashicorp/example.repo-123?ref=v1.0.0', + )?.groups; + expect(groups).toEqual({ + host: 'gitlab.my-domain.com:1234', + project: 'hashicorp/example.repo-123', + tag: 'v1.0.0', + }); + }); + }); + describe('gitTagsRefMatchRegex', () => { it('should split project and tag from source', () => { const http = gitTagsRefMatchRegex.exec( diff --git a/lib/modules/manager/terragrunt/modules.ts b/lib/modules/manager/terragrunt/modules.ts index 01fc5b43562569..d9528b748d3ba4 100644 --- a/lib/modules/manager/terragrunt/modules.ts +++ b/lib/modules/manager/terragrunt/modules.ts @@ -2,6 +2,7 @@ import { logger } from '../../../logger'; import { regEx } from '../../../util/regex'; import { GitTagsDatasource } from '../../datasource/git-tags'; import { GithubTagsDatasource } from '../../datasource/github-tags'; +import { GitlabTagsDatasource } from '../../datasource/gitlab-tags'; import { TerraformModuleDatasource } from '../../datasource/terraform-module'; import type { PackageDependency } from '../types'; import { extractTerragruntProvider } from './providers'; @@ -10,6 +11,9 @@ import type { ExtractionResult, TerraformManagerData } from './types'; export const githubRefMatchRegex = regEx( /github\.com([/:])(?[^/]+\/[a-z0-9-_.]+).*\?(depth=\d+&)?ref=(?.*?)(&depth=\d+)?$/i, ); +export const gitlabRefMatchRegex = regEx( + /(?gitlab(\.[a-z0-9-_]+)*\.com(:\d+)?)([/:])(?[^/]+\/[a-z0-9-_.]+).*\?(depth=\d+&)?ref=(?.*?)(&depth=\d+)?$/i, +); export const gitTagsRefMatchRegex = regEx( /(?:git::)?(?(?:http|https|ssh):\/\/(?:.*@)?(?.*.*\/(?.*\/.*)))\?(depth=\d+&)?ref=(?.*?)(&depth=\d+)?$/, ); @@ -37,6 +41,7 @@ export function analyseTerragruntModule( // TODO #22198 const source = dep.managerData!.source; const githubRefMatch = githubRefMatchRegex.exec(source ?? ''); + const gitlabRefMatch = gitlabRefMatchRegex.exec(source ?? ''); const gitTagsRefMatch = gitTagsRefMatchRegex.exec(source ?? ''); const tfrVersionMatch = tfrVersionMatchRegex.exec(source ?? ''); @@ -49,6 +54,15 @@ export function analyseTerragruntModule( dep.depName = 'github.com/' + dep.packageName; dep.currentValue = githubRefMatch.groups.tag; dep.datasource = GithubTagsDatasource.id; + } else if (gitlabRefMatch?.groups) { + dep.depType = 'repository'; + dep.packageName = gitlabRefMatch.groups.project.replace( + regEx(/\.git$/), + '', + ); + dep.depName = `${gitlabRefMatch.groups.host}/${dep.packageName}`; + dep.currentValue = gitlabRefMatch.groups.tag; + dep.datasource = GitlabTagsDatasource.id; } else if (gitTagsRefMatch?.groups) { dep.depType = 'gitTags'; if (gitTagsRefMatch.groups.path.includes('//')) { From 8cde50679bbb5c54519f27ee96c517d85ec18d7d Mon Sep 17 00:00:00 2001 From: lstoeferle <48953604+lstoeferle@users.noreply.github.com> Date: Wed, 13 Mar 2024 13:08:50 +0100 Subject: [PATCH 2/4] feat(terragrunt): add support for gitlab-, bitbucket- and gitea-tags datasources --- .../manager/terragrunt/__fixtures__/2.hcl | 91 ++++- .../manager/terragrunt/__fixtures__/3.hcl | 91 ++++- .../manager/terragrunt/__fixtures__/4.hcl | 90 ++++- .../manager/terragrunt/extract.spec.ts | 354 ++++++++++++++++-- lib/modules/manager/terragrunt/index.ts | 4 + .../manager/terragrunt/modules.spec.ts | 30 +- lib/modules/manager/terragrunt/modules.ts | 32 +- 7 files changed, 589 insertions(+), 103 deletions(-) diff --git a/lib/modules/manager/terragrunt/__fixtures__/2.hcl b/lib/modules/manager/terragrunt/__fixtures__/2.hcl index b99906d626d704..560a6ab206a685 100644 --- a/lib/modules/manager/terragrunt/__fixtures__/2.hcl +++ b/lib/modules/manager/terragrunt/__fixtures__/2.hcl @@ -125,42 +125,113 @@ terraform { foo = "bar" } -# foobar +# invalid, ignored by test since it does not have source on the next line +terraform { +} + +# unsupported terragrunt, ignored by test since it does not have source on the next line terraform { - source = "https://bitbucket.com/hashicorp/example?ref=v1.0.0" + name = "foo" + dummy = "true" } + # gittags terraform { - source = "git::https://bitbucket.com/hashicorp/example?ref=v1.0.0" + source = "git::https://mygit.com/hashicorp/example?ref=v1.0.0" } # gittags_badversion terraform { - source = "git::https://bitbucket.com/hashicorp/example?ref=next" + source = "git::https://mygit.com/hashicorp/example?ref=next" } # gittags_subdir terraform { - source = "git::https://bitbucket.com/hashicorp/example//subdir/test?ref=v1.0.1" + source = "git::https://mygit.com/hashicorp/example//subdir/test?ref=v1.0.1" } # gittags_http terraform { - source = "git::http://bitbucket.com/hashicorp/example?ref=v1.0.2" + source = "git::http://mygit.com/hashicorp/example?ref=v1.0.2" } # gittags_ssh +terraform { + source = "git::ssh://git@mygit.com/hashicorp/example?ref=v1.0.3" +} + +# bitbucket-tags +terraform { + source = "git::https://bitbucket.com/hashicorp/example?ref=v1.0.0" +} + +# bitbucket-tags_badversion +terraform { + source = "git::https://bitbucket.com/hashicorp/example?ref=next" +} + +# bitbucket-tags_subdir +terraform { + source = "git::https://bitbucket.com/hashicorp/example//subdir/test?ref=v1.0.1" +} + +# bitbucket-tags_http +terraform { + source = "git::http://bitbucket.com/hashicorp/example?ref=v1.0.2" +} + +# bitbucket-tags_ssh terraform { source = "git::ssh://git@bitbucket.com/hashicorp/example?ref=v1.0.3" } -# invalid, ignored by test since it does not have source on the next line +# gitlab-tags terraform { + source = "git::https://gitlab.com/hashicorp/example?ref=v1.0.0" } -# unsupported terragrunt, ignored by test since it does not have source on the next line +# gitlab-tags_badversion terraform { - name = "foo" - dummy = "true" + source = "git::https://gitlab.com/hashicorp/example?ref=next" +} + +# gitlab-tags_subdir +terraform { + source = "git::https://gitlab.com/hashicorp/example//subdir/test?ref=v1.0.1" +} + +# gitlab-tags_http +terraform { + source = "git::http://gitlab.com/hashicorp/example?ref=v1.0.2" +} + +# gitlab-tags_ssh +terraform { + source = "git::ssh://git@gitlab.com/hashicorp/example?ref=v1.0.3" +} + +# gitea-tags +terraform { + source = "git::https://gitea.com/hashicorp/example?ref=v1.0.0" +} + +# gitea-tags_badversion +terraform { + source = "git::https://gitea.com/hashicorp/example?ref=next" +} + +# gitea-tags_subdir +terraform { + source = "git::https://gitea.com/hashicorp/example//subdir/test?ref=v1.0.1" +} + +# gitea-tags_http +terraform { + source = "git::http://gitea.com/hashicorp/example?ref=v1.0.2" +} + +# gitea-tags_ssh +terraform { + source = "git::ssh://git@gitea.com/hashicorp/example?ref=v1.0.3" } diff --git a/lib/modules/manager/terragrunt/__fixtures__/3.hcl b/lib/modules/manager/terragrunt/__fixtures__/3.hcl index bfb076653db875..4118778e18e9b9 100644 --- a/lib/modules/manager/terragrunt/__fixtures__/3.hcl +++ b/lib/modules/manager/terragrunt/__fixtures__/3.hcl @@ -125,42 +125,113 @@ terraform { foo = "bar" } -# foobar +# invalid, ignored by test since it does not have source on the next line +terraform { +} + +# unsupported terragrunt, ignored by test since it does not have source on the next line terraform { - source = "https://bitbucket.com/hashicorp/example?ref=v1.0.0&depth=1" + name = "foo" + dummy = "true" } + # gittags terraform { - source = "git::https://bitbucket.com/hashicorp/example?ref=v1.0.0&depth=1" + source = "git::https://mygit.com/hashicorp/example?ref=v1.0.0&depth=1" } # gittags_badversion terraform { - source = "git::https://bitbucket.com/hashicorp/example?ref=next&depth=1" + source = "git::https://mygit.com/hashicorp/example?ref=next&depth=1" } # gittags_subdir terraform { - source = "git::https://bitbucket.com/hashicorp/example//subdir/test?ref=v1.0.1&depth=1" + source = "git::https://mygit.com/hashicorp/example//subdir/test?ref=v1.0.1&depth=1" } # gittags_http terraform { - source = "git::http://bitbucket.com/hashicorp/example?ref=v1.0.2&depth=1" + source = "git::http://mygit.com/hashicorp/example?ref=v1.0.2&depth=1" } # gittags_ssh +terraform { + source = "git::ssh://git@mygit.com/hashicorp/example?ref=v1.0.3&depth=1" +} + +# bitbucket-tags +terraform { + source = "git::https://bitbucket.com/hashicorp/example?ref=v1.0.0&depth=1" +} + +# bitbucket-tags_badversion +terraform { + source = "git::https://bitbucket.com/hashicorp/example?ref=next&depth=1" +} + +# bitbucket-tags_subdir +terraform { + source = "git::https://bitbucket.com/hashicorp/example//subdir/test?ref=v1.0.1&depth=1" +} + +# bitbucket-tags_http +terraform { + source = "git::http://bitbucket.com/hashicorp/example?ref=v1.0.2&depth=1" +} + +# bitbucket-tags_ssh terraform { source = "git::ssh://git@bitbucket.com/hashicorp/example?ref=v1.0.3&depth=1" } -# invalid, ignored by test since it does not have source on the next line +# gitlab-tags terraform { + source = "git::https://gitlab.com/hashicorp/example?ref=v1.0.0&depth=1" } -# unsupported terragrunt, ignored by test since it does not have source on the next line +# gitlab-tags_badversion terraform { - name = "foo" - dummy = "true" + source = "git::https://gitlab.com/hashicorp/example?ref=next&depth=1" +} + +# gitlab-tags_subdir +terraform { + source = "git::https://gitlab.com/hashicorp/example//subdir/test?ref=v1.0.1&depth=1" +} + +# gitlab-tags_http +terraform { + source = "git::http://gitlab.com/hashicorp/example?ref=v1.0.2&depth=1" +} + +# gitlab-tags_ssh +terraform { + source = "git::ssh://git@gitlab.com/hashicorp/example?ref=v1.0.3&depth=1" +} + +# gitea-tags +terraform { + source = "git::https://gitea.com/hashicorp/example?ref=v1.0.0&depth=1" +} + +# gitea-tags_badversion +terraform { + source = "git::https://gitea.com/hashicorp/example?ref=next&depth=1" +} + +# gitea-tags_subdir +terraform { + source = "git::https://gitea.com/hashicorp/example//subdir/test?ref=v1.0.1&depth=1" +} + +# gitea-tags_http +terraform { + source = "git::http://gitea.com/hashicorp/example?ref=v1.0.2&depth=1" +} + +# gitea-tags_ssh +terraform { + source = "git::ssh://git@gitea.com/hashicorp/example?ref=v1.0.3&depth=1" } diff --git a/lib/modules/manager/terragrunt/__fixtures__/4.hcl b/lib/modules/manager/terragrunt/__fixtures__/4.hcl index 72889fb6aed347..dfb0a62a0d746f 100644 --- a/lib/modules/manager/terragrunt/__fixtures__/4.hcl +++ b/lib/modules/manager/terragrunt/__fixtures__/4.hcl @@ -125,42 +125,112 @@ terraform { foo = "bar" } -# foobar +# invalid, ignored by test since it does not have source on the next line +terraform { +} + +# unsupported terragrunt, ignored by test since it does not have source on the next line terraform { - source = "https://bitbucket.com/hashicorp/example?depth=1&ref=v1.0.0" + name = "foo" + dummy = "true" } # gittags terraform { - source = "git::https://bitbucket.com/hashicorp/example?depth=1&ref=v1.0.0" + source = "git::https://mygit.com/hashicorp/example?depth=1&ref=v1.0.0" } # gittags_badversion terraform { - source = "git::https://bitbucket.com/hashicorp/example?depth=1&ref=next" + source = "git::https://mygit.com/hashicorp/example?depth=1&ref=next" } # gittags_subdir terraform { - source = "git::https://bitbucket.com/hashicorp/example//subdir/test?depth=1&ref=v1.0.1" + source = "git::https://mygit.com/hashicorp/example//subdir/test?depth=1&ref=v1.0.1" } # gittags_http terraform { - source = "git::http://bitbucket.com/hashicorp/example?depth=1&ref=v1.0.2" + source = "git::http://mygit.com/hashicorp/example?depth=1&ref=v1.0.2" } # gittags_ssh +terraform { + source = "git::ssh://git@mygit.com/hashicorp/example?depth=1&ref=v1.0.3" +} + +# bitbucket-tags +terraform { + source = "git::https://bitbucket.com/hashicorp/example?depth=1&ref=v1.0.0" +} + +# bitbucket-tags_badversion +terraform { + source = "git::https://bitbucket.com/hashicorp/example?depth=1&ref=next" +} + +# bitbucket-tags_subdir +terraform { + source = "git::https://bitbucket.com/hashicorp/example//subdir/test?depth=1&ref=v1.0.1" +} + +# bitbucket-tags_http +terraform { + source = "git::http://bitbucket.com/hashicorp/example?depth=1&ref=v1.0.2" +} + +# bitbucket-tags_ssh terraform { source = "git::ssh://git@bitbucket.com/hashicorp/example?depth=1&ref=v1.0.3" } -# invalid, ignored by test since it does not have source on the next line +# gitlab-tags terraform { + source = "git::https://gitlab.com/hashicorp/example?depth=1&ref=v1.0.0" } -# unsupported terragrunt, ignored by test since it does not have source on the next line +# gitlab-tags_badversion terraform { - name = "foo" - dummy = "true" + source = "git::https://gitlab.com/hashicorp/example?depth=1&ref=next" +} + +# gitlab-tags_subdir +terraform { + source = "git::https://gitlab.com/hashicorp/example//subdir/test?depth=1&ref=v1.0.1" +} + +# gitlab-tags_http +terraform { + source = "git::http://gitlab.com/hashicorp/example?depth=1&ref=v1.0.2" +} + +# gitlab-tags_ssh +terraform { + source = "git::ssh://git@gitlab.com/hashicorp/example?depth=1&ref=v1.0.3" +} + +# gitea-tags +terraform { + source = "git::https://gitea.com/hashicorp/example?depth=1&ref=v1.0.0" +} + +# gitea-tags_badversion +terraform { + source = "git::https://gitea.com/hashicorp/example?depth=1&ref=next" +} + +# gitea-tags_subdir +terraform { + source = "git::https://gitea.com/hashicorp/example//subdir/test?depth=1&ref=v1.0.1" +} + +# gitea-tags_http +terraform { + source = "git::http://gitea.com/hashicorp/example?depth=1&ref=v1.0.2" +} + +# gitea-tags_ssh +terraform { + source = "git::ssh://git@gitea.com/hashicorp/example?depth=1&ref=v1.0.3" } diff --git a/lib/modules/manager/terragrunt/extract.spec.ts b/lib/modules/manager/terragrunt/extract.spec.ts index bcba2edcbf9efc..8f4440063f5539 100644 --- a/lib/modules/manager/terragrunt/extract.spec.ts +++ b/lib/modules/manager/terragrunt/extract.spec.ts @@ -152,57 +152,155 @@ describe('modules/manager/terragrunt/extract', () => { { skipReason: 'no-source', }, + { + skipReason: 'no-source', + }, + { + skipReason: 'no-source', + }, { currentValue: 'v1.0.0', datasource: 'git-tags', - depName: 'bitbucket.com/hashicorp/example', + depName: 'mygit.com/hashicorp/example', depType: 'gitTags', - packageName: 'https://bitbucket.com/hashicorp/example', + packageName: 'https://mygit.com/hashicorp/example', }, { - currentValue: 'v1.0.0', + currentValue: 'next', datasource: 'git-tags', + depName: 'mygit.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://mygit.com/hashicorp/example', + }, + { + currentValue: 'v1.0.1', + datasource: 'git-tags', + depName: 'mygit.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://mygit.com/hashicorp/example', + }, + { + currentValue: 'v1.0.2', + datasource: 'git-tags', + depName: 'mygit.com/hashicorp/example', + depType: 'gitTags', + packageName: 'http://mygit.com/hashicorp/example', + }, + { + currentValue: 'v1.0.3', + datasource: 'git-tags', + depName: 'mygit.com/hashicorp/example', + depType: 'gitTags', + packageName: 'ssh://git@mygit.com/hashicorp/example', + }, + { + currentValue: 'v1.0.0', + datasource: 'bitbucket-tags', depName: 'bitbucket.com/hashicorp/example', depType: 'gitTags', packageName: 'https://bitbucket.com/hashicorp/example', }, { currentValue: 'next', - datasource: 'git-tags', + datasource: 'bitbucket-tags', depName: 'bitbucket.com/hashicorp/example', depType: 'gitTags', packageName: 'https://bitbucket.com/hashicorp/example', }, { currentValue: 'v1.0.1', - datasource: 'git-tags', + datasource: 'bitbucket-tags', depName: 'bitbucket.com/hashicorp/example', depType: 'gitTags', packageName: 'https://bitbucket.com/hashicorp/example', }, { currentValue: 'v1.0.2', - datasource: 'git-tags', + datasource: 'bitbucket-tags', depName: 'bitbucket.com/hashicorp/example', depType: 'gitTags', packageName: 'http://bitbucket.com/hashicorp/example', }, { currentValue: 'v1.0.3', - datasource: 'git-tags', + datasource: 'bitbucket-tags', depName: 'bitbucket.com/hashicorp/example', depType: 'gitTags', packageName: 'ssh://git@bitbucket.com/hashicorp/example', }, { - skipReason: 'no-source', + currentValue: 'v1.0.0', + datasource: 'gitlab-tags', + depName: 'gitlab.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://gitlab.com/hashicorp/example', }, { - skipReason: 'no-source', + currentValue: 'next', + datasource: 'gitlab-tags', + depName: 'gitlab.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://gitlab.com/hashicorp/example', + }, + { + currentValue: 'v1.0.1', + datasource: 'gitlab-tags', + depName: 'gitlab.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://gitlab.com/hashicorp/example', + }, + { + currentValue: 'v1.0.2', + datasource: 'gitlab-tags', + depName: 'gitlab.com/hashicorp/example', + depType: 'gitTags', + packageName: 'http://gitlab.com/hashicorp/example', + }, + { + currentValue: 'v1.0.3', + datasource: 'gitlab-tags', + depName: 'gitlab.com/hashicorp/example', + depType: 'gitTags', + packageName: 'ssh://git@gitlab.com/hashicorp/example', + }, + { + currentValue: 'v1.0.0', + datasource: 'gitea-tags', + depName: 'gitea.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://gitea.com/hashicorp/example', + }, + { + currentValue: 'next', + datasource: 'gitea-tags', + depName: 'gitea.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://gitea.com/hashicorp/example', + }, + { + currentValue: 'v1.0.1', + datasource: 'gitea-tags', + depName: 'gitea.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://gitea.com/hashicorp/example', + }, + { + currentValue: 'v1.0.2', + datasource: 'gitea-tags', + depName: 'gitea.com/hashicorp/example', + depType: 'gitTags', + packageName: 'http://gitea.com/hashicorp/example', + }, + { + currentValue: 'v1.0.3', + datasource: 'gitea-tags', + depName: 'gitea.com/hashicorp/example', + depType: 'gitTags', + packageName: 'ssh://git@gitea.com/hashicorp/example', }, ], }); - expect(res?.deps).toHaveLength(30); + expect(res?.deps).toHaveLength(44); expect(res?.deps.filter((dep) => dep.skipReason)).toHaveLength(4); }); @@ -317,57 +415,155 @@ describe('modules/manager/terragrunt/extract', () => { { skipReason: 'no-source', }, + { + skipReason: 'no-source', + }, + { + skipReason: 'no-source', + }, { currentValue: 'v1.0.0', datasource: 'git-tags', - depName: 'bitbucket.com/hashicorp/example', + depName: 'mygit.com/hashicorp/example', depType: 'gitTags', - packageName: 'https://bitbucket.com/hashicorp/example', + packageName: 'https://mygit.com/hashicorp/example', }, { - currentValue: 'v1.0.0', + currentValue: 'next', datasource: 'git-tags', + depName: 'mygit.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://mygit.com/hashicorp/example', + }, + { + currentValue: 'v1.0.1', + datasource: 'git-tags', + depName: 'mygit.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://mygit.com/hashicorp/example', + }, + { + currentValue: 'v1.0.2', + datasource: 'git-tags', + depName: 'mygit.com/hashicorp/example', + depType: 'gitTags', + packageName: 'http://mygit.com/hashicorp/example', + }, + { + currentValue: 'v1.0.3', + datasource: 'git-tags', + depName: 'mygit.com/hashicorp/example', + depType: 'gitTags', + packageName: 'ssh://git@mygit.com/hashicorp/example', + }, + { + currentValue: 'v1.0.0', + datasource: 'bitbucket-tags', depName: 'bitbucket.com/hashicorp/example', depType: 'gitTags', packageName: 'https://bitbucket.com/hashicorp/example', }, { currentValue: 'next', - datasource: 'git-tags', + datasource: 'bitbucket-tags', depName: 'bitbucket.com/hashicorp/example', depType: 'gitTags', packageName: 'https://bitbucket.com/hashicorp/example', }, { currentValue: 'v1.0.1', - datasource: 'git-tags', + datasource: 'bitbucket-tags', depName: 'bitbucket.com/hashicorp/example', depType: 'gitTags', packageName: 'https://bitbucket.com/hashicorp/example', }, { currentValue: 'v1.0.2', - datasource: 'git-tags', + datasource: 'bitbucket-tags', depName: 'bitbucket.com/hashicorp/example', depType: 'gitTags', packageName: 'http://bitbucket.com/hashicorp/example', }, { currentValue: 'v1.0.3', - datasource: 'git-tags', + datasource: 'bitbucket-tags', depName: 'bitbucket.com/hashicorp/example', depType: 'gitTags', packageName: 'ssh://git@bitbucket.com/hashicorp/example', }, { - skipReason: 'no-source', + currentValue: 'v1.0.0', + datasource: 'gitlab-tags', + depName: 'gitlab.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://gitlab.com/hashicorp/example', }, { - skipReason: 'no-source', + currentValue: 'next', + datasource: 'gitlab-tags', + depName: 'gitlab.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://gitlab.com/hashicorp/example', + }, + { + currentValue: 'v1.0.1', + datasource: 'gitlab-tags', + depName: 'gitlab.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://gitlab.com/hashicorp/example', + }, + { + currentValue: 'v1.0.2', + datasource: 'gitlab-tags', + depName: 'gitlab.com/hashicorp/example', + depType: 'gitTags', + packageName: 'http://gitlab.com/hashicorp/example', + }, + { + currentValue: 'v1.0.3', + datasource: 'gitlab-tags', + depName: 'gitlab.com/hashicorp/example', + depType: 'gitTags', + packageName: 'ssh://git@gitlab.com/hashicorp/example', + }, + { + currentValue: 'v1.0.0', + datasource: 'gitea-tags', + depName: 'gitea.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://gitea.com/hashicorp/example', + }, + { + currentValue: 'next', + datasource: 'gitea-tags', + depName: 'gitea.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://gitea.com/hashicorp/example', + }, + { + currentValue: 'v1.0.1', + datasource: 'gitea-tags', + depName: 'gitea.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://gitea.com/hashicorp/example', + }, + { + currentValue: 'v1.0.2', + datasource: 'gitea-tags', + depName: 'gitea.com/hashicorp/example', + depType: 'gitTags', + packageName: 'http://gitea.com/hashicorp/example', + }, + { + currentValue: 'v1.0.3', + datasource: 'gitea-tags', + depName: 'gitea.com/hashicorp/example', + depType: 'gitTags', + packageName: 'ssh://git@gitea.com/hashicorp/example', }, ], }); - expect(res?.deps).toHaveLength(30); + expect(res?.deps).toHaveLength(44); expect(res?.deps.filter((dep) => dep.skipReason)).toHaveLength(4); }); @@ -482,57 +678,155 @@ describe('modules/manager/terragrunt/extract', () => { { skipReason: 'no-source', }, + { + skipReason: 'no-source', + }, + { + skipReason: 'no-source', + }, { currentValue: 'v1.0.0', datasource: 'git-tags', - depName: 'bitbucket.com/hashicorp/example', + depName: 'mygit.com/hashicorp/example', depType: 'gitTags', - packageName: 'https://bitbucket.com/hashicorp/example', + packageName: 'https://mygit.com/hashicorp/example', }, { - currentValue: 'v1.0.0', + currentValue: 'next', + datasource: 'git-tags', + depName: 'mygit.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://mygit.com/hashicorp/example', + }, + { + currentValue: 'v1.0.1', + datasource: 'git-tags', + depName: 'mygit.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://mygit.com/hashicorp/example', + }, + { + currentValue: 'v1.0.2', + datasource: 'git-tags', + depName: 'mygit.com/hashicorp/example', + depType: 'gitTags', + packageName: 'http://mygit.com/hashicorp/example', + }, + { + currentValue: 'v1.0.3', datasource: 'git-tags', + depName: 'mygit.com/hashicorp/example', + depType: 'gitTags', + packageName: 'ssh://git@mygit.com/hashicorp/example', + }, + { + currentValue: 'v1.0.0', + datasource: 'bitbucket-tags', depName: 'bitbucket.com/hashicorp/example', depType: 'gitTags', packageName: 'https://bitbucket.com/hashicorp/example', }, { currentValue: 'next', - datasource: 'git-tags', + datasource: 'bitbucket-tags', depName: 'bitbucket.com/hashicorp/example', depType: 'gitTags', packageName: 'https://bitbucket.com/hashicorp/example', }, { currentValue: 'v1.0.1', - datasource: 'git-tags', + datasource: 'bitbucket-tags', depName: 'bitbucket.com/hashicorp/example', depType: 'gitTags', packageName: 'https://bitbucket.com/hashicorp/example', }, { currentValue: 'v1.0.2', - datasource: 'git-tags', + datasource: 'bitbucket-tags', depName: 'bitbucket.com/hashicorp/example', depType: 'gitTags', packageName: 'http://bitbucket.com/hashicorp/example', }, { currentValue: 'v1.0.3', - datasource: 'git-tags', + datasource: 'bitbucket-tags', depName: 'bitbucket.com/hashicorp/example', depType: 'gitTags', packageName: 'ssh://git@bitbucket.com/hashicorp/example', }, { - skipReason: 'no-source', + currentValue: 'v1.0.0', + datasource: 'gitlab-tags', + depName: 'gitlab.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://gitlab.com/hashicorp/example', }, { - skipReason: 'no-source', + currentValue: 'next', + datasource: 'gitlab-tags', + depName: 'gitlab.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://gitlab.com/hashicorp/example', + }, + { + currentValue: 'v1.0.1', + datasource: 'gitlab-tags', + depName: 'gitlab.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://gitlab.com/hashicorp/example', + }, + { + currentValue: 'v1.0.2', + datasource: 'gitlab-tags', + depName: 'gitlab.com/hashicorp/example', + depType: 'gitTags', + packageName: 'http://gitlab.com/hashicorp/example', + }, + { + currentValue: 'v1.0.3', + datasource: 'gitlab-tags', + depName: 'gitlab.com/hashicorp/example', + depType: 'gitTags', + packageName: 'ssh://git@gitlab.com/hashicorp/example', + }, + { + currentValue: 'v1.0.0', + datasource: 'gitea-tags', + depName: 'gitea.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://gitea.com/hashicorp/example', + }, + { + currentValue: 'next', + datasource: 'gitea-tags', + depName: 'gitea.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://gitea.com/hashicorp/example', + }, + { + currentValue: 'v1.0.1', + datasource: 'gitea-tags', + depName: 'gitea.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://gitea.com/hashicorp/example', + }, + { + currentValue: 'v1.0.2', + datasource: 'gitea-tags', + depName: 'gitea.com/hashicorp/example', + depType: 'gitTags', + packageName: 'http://gitea.com/hashicorp/example', + }, + { + currentValue: 'v1.0.3', + datasource: 'gitea-tags', + depName: 'gitea.com/hashicorp/example', + depType: 'gitTags', + packageName: 'ssh://git@gitea.com/hashicorp/example', }, ], }); - expect(res?.deps).toHaveLength(30); + expect(res?.deps).toHaveLength(44); expect(res?.deps.filter((dep) => dep.skipReason)).toHaveLength(4); }); diff --git a/lib/modules/manager/terragrunt/index.ts b/lib/modules/manager/terragrunt/index.ts index 944e45c1c485a4..9343bcd0c5e8ae 100644 --- a/lib/modules/manager/terragrunt/index.ts +++ b/lib/modules/manager/terragrunt/index.ts @@ -1,5 +1,7 @@ import type { Category } from '../../../constants'; +import { BitbucketTagsDatasource } from '../../datasource/bitbucket-tags'; import { GitTagsDatasource } from '../../datasource/git-tags'; +import { GiteaTagsDatasource } from '../../datasource/gitea-tags'; import { GithubTagsDatasource } from '../../datasource/github-tags'; import { GitlabTagsDatasource } from '../../datasource/gitlab-tags'; import { TerraformModuleDatasource } from '../../datasource/terraform-module'; @@ -11,6 +13,8 @@ export const supportedDatasources = [ GitTagsDatasource.id, GithubTagsDatasource.id, GitlabTagsDatasource.id, + BitbucketTagsDatasource.id, + GiteaTagsDatasource.id, TerraformModuleDatasource.id, ]; diff --git a/lib/modules/manager/terragrunt/modules.spec.ts b/lib/modules/manager/terragrunt/modules.spec.ts index 8e53ae6e70f279..b2b30361860704 100644 --- a/lib/modules/manager/terragrunt/modules.spec.ts +++ b/lib/modules/manager/terragrunt/modules.spec.ts @@ -1,8 +1,4 @@ -import { - gitTagsRefMatchRegex, - githubRefMatchRegex, - gitlabRefMatchRegex, -} from './modules'; +import { gitTagsRefMatchRegex, githubRefMatchRegex } from './modules'; describe('modules/manager/terragrunt/modules', () => { describe('githubRefMatchRegex', () => { @@ -27,30 +23,6 @@ describe('modules/manager/terragrunt/modules', () => { }); }); - describe('gitlabRefMatchRegex', () => { - it('should split project and tag from source', () => { - const groups = gitlabRefMatchRegex.exec( - 'gitlab.my-domain.com/hashicorp/example//sub-directory?ref=v1.0.0', - )?.groups; - expect(groups).toEqual({ - host: 'gitlab.my-domain.com', - project: 'hashicorp/example', - tag: 'v1.0.0', - }); - }); - - it('should parse alpha-numeric characters as well as dots, underscores, and dashes in repo names', () => { - const groups = gitlabRefMatchRegex.exec( - 'gitlab.my-domain.com:1234/hashicorp/example.repo-123?ref=v1.0.0', - )?.groups; - expect(groups).toEqual({ - host: 'gitlab.my-domain.com:1234', - project: 'hashicorp/example.repo-123', - tag: 'v1.0.0', - }); - }); - }); - describe('gitTagsRefMatchRegex', () => { it('should split project and tag from source', () => { const http = gitTagsRefMatchRegex.exec( diff --git a/lib/modules/manager/terragrunt/modules.ts b/lib/modules/manager/terragrunt/modules.ts index d9528b748d3ba4..f881a78a95ca90 100644 --- a/lib/modules/manager/terragrunt/modules.ts +++ b/lib/modules/manager/terragrunt/modules.ts @@ -1,6 +1,9 @@ import { logger } from '../../../logger'; +import { detectPlatform } from '../../../util/common'; import { regEx } from '../../../util/regex'; +import { BitbucketTagsDatasource } from '../../datasource/bitbucket-tags'; import { GitTagsDatasource } from '../../datasource/git-tags'; +import { GiteaTagsDatasource } from '../../datasource/gitea-tags'; import { GithubTagsDatasource } from '../../datasource/github-tags'; import { GitlabTagsDatasource } from '../../datasource/gitlab-tags'; import { TerraformModuleDatasource } from '../../datasource/terraform-module'; @@ -11,9 +14,6 @@ import type { ExtractionResult, TerraformManagerData } from './types'; export const githubRefMatchRegex = regEx( /github\.com([/:])(?[^/]+\/[a-z0-9-_.]+).*\?(depth=\d+&)?ref=(?.*?)(&depth=\d+)?$/i, ); -export const gitlabRefMatchRegex = regEx( - /(?gitlab(\.[a-z0-9-_]+)*\.com(:\d+)?)([/:])(?[^/]+\/[a-z0-9-_.]+).*\?(depth=\d+&)?ref=(?.*?)(&depth=\d+)?$/i, -); export const gitTagsRefMatchRegex = regEx( /(?:git::)?(?(?:http|https|ssh):\/\/(?:.*@)?(?.*.*\/(?.*\/.*)))\?(depth=\d+&)?ref=(?.*?)(&depth=\d+)?$/, ); @@ -35,13 +35,26 @@ export function extractTerragruntModule( return result; } +function detectGitTagDatasource(registryUrl: string): string { + const platform = detectPlatform(registryUrl); + switch (platform) { + case 'gitlab': + return GitlabTagsDatasource.id; + case 'bitbucket': + return BitbucketTagsDatasource.id; + case 'gitea': + return GiteaTagsDatasource.id; + default: + return GitTagsDatasource.id; + } +} + export function analyseTerragruntModule( dep: PackageDependency, ): void { // TODO #22198 const source = dep.managerData!.source; const githubRefMatch = githubRefMatchRegex.exec(source ?? ''); - const gitlabRefMatch = gitlabRefMatchRegex.exec(source ?? ''); const gitTagsRefMatch = gitTagsRefMatchRegex.exec(source ?? ''); const tfrVersionMatch = tfrVersionMatchRegex.exec(source ?? ''); @@ -54,15 +67,6 @@ export function analyseTerragruntModule( dep.depName = 'github.com/' + dep.packageName; dep.currentValue = githubRefMatch.groups.tag; dep.datasource = GithubTagsDatasource.id; - } else if (gitlabRefMatch?.groups) { - dep.depType = 'repository'; - dep.packageName = gitlabRefMatch.groups.project.replace( - regEx(/\.git$/), - '', - ); - dep.depName = `${gitlabRefMatch.groups.host}/${dep.packageName}`; - dep.currentValue = gitlabRefMatch.groups.tag; - dep.datasource = GitlabTagsDatasource.id; } else if (gitTagsRefMatch?.groups) { dep.depType = 'gitTags'; if (gitTagsRefMatch.groups.path.includes('//')) { @@ -75,7 +79,7 @@ export function analyseTerragruntModule( dep.packageName = gitTagsRefMatch.groups.url; } dep.currentValue = gitTagsRefMatch.groups.tag; - dep.datasource = GitTagsDatasource.id; + dep.datasource = detectGitTagDatasource(gitTagsRefMatch.groups.url); } else if (tfrVersionMatch?.groups) { dep.depType = 'terragrunt'; dep.depName = From 32662ec36f0ee8da1e7a8461edbfefac53fdf4eb Mon Sep 17 00:00:00 2001 From: lstoeferle <48953604+lstoeferle@users.noreply.github.com> Date: Fri, 15 Mar 2024 13:47:38 +0100 Subject: [PATCH 3/4] test(terragrunt): remove obsolete extract test fixtures --- .../manager/terragrunt/__fixtures__/2.hcl | 60 ---- .../manager/terragrunt/__fixtures__/3.hcl | 60 ---- .../manager/terragrunt/__fixtures__/4.hcl | 60 ---- .../manager/terragrunt/extract.spec.ts | 258 +----------------- 4 files changed, 3 insertions(+), 435 deletions(-) diff --git a/lib/modules/manager/terragrunt/__fixtures__/2.hcl b/lib/modules/manager/terragrunt/__fixtures__/2.hcl index 560a6ab206a685..94cd97b3b17afa 100644 --- a/lib/modules/manager/terragrunt/__fixtures__/2.hcl +++ b/lib/modules/manager/terragrunt/__fixtures__/2.hcl @@ -166,72 +166,12 @@ terraform { source = "git::https://bitbucket.com/hashicorp/example?ref=v1.0.0" } -# bitbucket-tags_badversion -terraform { - source = "git::https://bitbucket.com/hashicorp/example?ref=next" -} - -# bitbucket-tags_subdir -terraform { - source = "git::https://bitbucket.com/hashicorp/example//subdir/test?ref=v1.0.1" -} - -# bitbucket-tags_http -terraform { - source = "git::http://bitbucket.com/hashicorp/example?ref=v1.0.2" -} - -# bitbucket-tags_ssh -terraform { - source = "git::ssh://git@bitbucket.com/hashicorp/example?ref=v1.0.3" -} - # gitlab-tags terraform { source = "git::https://gitlab.com/hashicorp/example?ref=v1.0.0" } -# gitlab-tags_badversion -terraform { - source = "git::https://gitlab.com/hashicorp/example?ref=next" -} - -# gitlab-tags_subdir -terraform { - source = "git::https://gitlab.com/hashicorp/example//subdir/test?ref=v1.0.1" -} - -# gitlab-tags_http -terraform { - source = "git::http://gitlab.com/hashicorp/example?ref=v1.0.2" -} - -# gitlab-tags_ssh -terraform { - source = "git::ssh://git@gitlab.com/hashicorp/example?ref=v1.0.3" -} - # gitea-tags terraform { source = "git::https://gitea.com/hashicorp/example?ref=v1.0.0" } - -# gitea-tags_badversion -terraform { - source = "git::https://gitea.com/hashicorp/example?ref=next" -} - -# gitea-tags_subdir -terraform { - source = "git::https://gitea.com/hashicorp/example//subdir/test?ref=v1.0.1" -} - -# gitea-tags_http -terraform { - source = "git::http://gitea.com/hashicorp/example?ref=v1.0.2" -} - -# gitea-tags_ssh -terraform { - source = "git::ssh://git@gitea.com/hashicorp/example?ref=v1.0.3" -} diff --git a/lib/modules/manager/terragrunt/__fixtures__/3.hcl b/lib/modules/manager/terragrunt/__fixtures__/3.hcl index 4118778e18e9b9..fe084be37eccf2 100644 --- a/lib/modules/manager/terragrunt/__fixtures__/3.hcl +++ b/lib/modules/manager/terragrunt/__fixtures__/3.hcl @@ -166,72 +166,12 @@ terraform { source = "git::https://bitbucket.com/hashicorp/example?ref=v1.0.0&depth=1" } -# bitbucket-tags_badversion -terraform { - source = "git::https://bitbucket.com/hashicorp/example?ref=next&depth=1" -} - -# bitbucket-tags_subdir -terraform { - source = "git::https://bitbucket.com/hashicorp/example//subdir/test?ref=v1.0.1&depth=1" -} - -# bitbucket-tags_http -terraform { - source = "git::http://bitbucket.com/hashicorp/example?ref=v1.0.2&depth=1" -} - -# bitbucket-tags_ssh -terraform { - source = "git::ssh://git@bitbucket.com/hashicorp/example?ref=v1.0.3&depth=1" -} - # gitlab-tags terraform { source = "git::https://gitlab.com/hashicorp/example?ref=v1.0.0&depth=1" } -# gitlab-tags_badversion -terraform { - source = "git::https://gitlab.com/hashicorp/example?ref=next&depth=1" -} - -# gitlab-tags_subdir -terraform { - source = "git::https://gitlab.com/hashicorp/example//subdir/test?ref=v1.0.1&depth=1" -} - -# gitlab-tags_http -terraform { - source = "git::http://gitlab.com/hashicorp/example?ref=v1.0.2&depth=1" -} - -# gitlab-tags_ssh -terraform { - source = "git::ssh://git@gitlab.com/hashicorp/example?ref=v1.0.3&depth=1" -} - # gitea-tags terraform { source = "git::https://gitea.com/hashicorp/example?ref=v1.0.0&depth=1" } - -# gitea-tags_badversion -terraform { - source = "git::https://gitea.com/hashicorp/example?ref=next&depth=1" -} - -# gitea-tags_subdir -terraform { - source = "git::https://gitea.com/hashicorp/example//subdir/test?ref=v1.0.1&depth=1" -} - -# gitea-tags_http -terraform { - source = "git::http://gitea.com/hashicorp/example?ref=v1.0.2&depth=1" -} - -# gitea-tags_ssh -terraform { - source = "git::ssh://git@gitea.com/hashicorp/example?ref=v1.0.3&depth=1" -} diff --git a/lib/modules/manager/terragrunt/__fixtures__/4.hcl b/lib/modules/manager/terragrunt/__fixtures__/4.hcl index dfb0a62a0d746f..0a47b8618c6803 100644 --- a/lib/modules/manager/terragrunt/__fixtures__/4.hcl +++ b/lib/modules/manager/terragrunt/__fixtures__/4.hcl @@ -165,72 +165,12 @@ terraform { source = "git::https://bitbucket.com/hashicorp/example?depth=1&ref=v1.0.0" } -# bitbucket-tags_badversion -terraform { - source = "git::https://bitbucket.com/hashicorp/example?depth=1&ref=next" -} - -# bitbucket-tags_subdir -terraform { - source = "git::https://bitbucket.com/hashicorp/example//subdir/test?depth=1&ref=v1.0.1" -} - -# bitbucket-tags_http -terraform { - source = "git::http://bitbucket.com/hashicorp/example?depth=1&ref=v1.0.2" -} - -# bitbucket-tags_ssh -terraform { - source = "git::ssh://git@bitbucket.com/hashicorp/example?depth=1&ref=v1.0.3" -} - # gitlab-tags terraform { source = "git::https://gitlab.com/hashicorp/example?depth=1&ref=v1.0.0" } -# gitlab-tags_badversion -terraform { - source = "git::https://gitlab.com/hashicorp/example?depth=1&ref=next" -} - -# gitlab-tags_subdir -terraform { - source = "git::https://gitlab.com/hashicorp/example//subdir/test?depth=1&ref=v1.0.1" -} - -# gitlab-tags_http -terraform { - source = "git::http://gitlab.com/hashicorp/example?depth=1&ref=v1.0.2" -} - -# gitlab-tags_ssh -terraform { - source = "git::ssh://git@gitlab.com/hashicorp/example?depth=1&ref=v1.0.3" -} - # gitea-tags terraform { source = "git::https://gitea.com/hashicorp/example?depth=1&ref=v1.0.0" } - -# gitea-tags_badversion -terraform { - source = "git::https://gitea.com/hashicorp/example?depth=1&ref=next" -} - -# gitea-tags_subdir -terraform { - source = "git::https://gitea.com/hashicorp/example//subdir/test?depth=1&ref=v1.0.1" -} - -# gitea-tags_http -terraform { - source = "git::http://gitea.com/hashicorp/example?depth=1&ref=v1.0.2" -} - -# gitea-tags_ssh -terraform { - source = "git::ssh://git@gitea.com/hashicorp/example?depth=1&ref=v1.0.3" -} diff --git a/lib/modules/manager/terragrunt/extract.spec.ts b/lib/modules/manager/terragrunt/extract.spec.ts index 8f4440063f5539..b35d6121a6ba44 100644 --- a/lib/modules/manager/terragrunt/extract.spec.ts +++ b/lib/modules/manager/terragrunt/extract.spec.ts @@ -200,34 +200,6 @@ describe('modules/manager/terragrunt/extract', () => { depType: 'gitTags', packageName: 'https://bitbucket.com/hashicorp/example', }, - { - currentValue: 'next', - datasource: 'bitbucket-tags', - depName: 'bitbucket.com/hashicorp/example', - depType: 'gitTags', - packageName: 'https://bitbucket.com/hashicorp/example', - }, - { - currentValue: 'v1.0.1', - datasource: 'bitbucket-tags', - depName: 'bitbucket.com/hashicorp/example', - depType: 'gitTags', - packageName: 'https://bitbucket.com/hashicorp/example', - }, - { - currentValue: 'v1.0.2', - datasource: 'bitbucket-tags', - depName: 'bitbucket.com/hashicorp/example', - depType: 'gitTags', - packageName: 'http://bitbucket.com/hashicorp/example', - }, - { - currentValue: 'v1.0.3', - datasource: 'bitbucket-tags', - depName: 'bitbucket.com/hashicorp/example', - depType: 'gitTags', - packageName: 'ssh://git@bitbucket.com/hashicorp/example', - }, { currentValue: 'v1.0.0', datasource: 'gitlab-tags', @@ -235,34 +207,6 @@ describe('modules/manager/terragrunt/extract', () => { depType: 'gitTags', packageName: 'https://gitlab.com/hashicorp/example', }, - { - currentValue: 'next', - datasource: 'gitlab-tags', - depName: 'gitlab.com/hashicorp/example', - depType: 'gitTags', - packageName: 'https://gitlab.com/hashicorp/example', - }, - { - currentValue: 'v1.0.1', - datasource: 'gitlab-tags', - depName: 'gitlab.com/hashicorp/example', - depType: 'gitTags', - packageName: 'https://gitlab.com/hashicorp/example', - }, - { - currentValue: 'v1.0.2', - datasource: 'gitlab-tags', - depName: 'gitlab.com/hashicorp/example', - depType: 'gitTags', - packageName: 'http://gitlab.com/hashicorp/example', - }, - { - currentValue: 'v1.0.3', - datasource: 'gitlab-tags', - depName: 'gitlab.com/hashicorp/example', - depType: 'gitTags', - packageName: 'ssh://git@gitlab.com/hashicorp/example', - }, { currentValue: 'v1.0.0', datasource: 'gitea-tags', @@ -270,37 +214,9 @@ describe('modules/manager/terragrunt/extract', () => { depType: 'gitTags', packageName: 'https://gitea.com/hashicorp/example', }, - { - currentValue: 'next', - datasource: 'gitea-tags', - depName: 'gitea.com/hashicorp/example', - depType: 'gitTags', - packageName: 'https://gitea.com/hashicorp/example', - }, - { - currentValue: 'v1.0.1', - datasource: 'gitea-tags', - depName: 'gitea.com/hashicorp/example', - depType: 'gitTags', - packageName: 'https://gitea.com/hashicorp/example', - }, - { - currentValue: 'v1.0.2', - datasource: 'gitea-tags', - depName: 'gitea.com/hashicorp/example', - depType: 'gitTags', - packageName: 'http://gitea.com/hashicorp/example', - }, - { - currentValue: 'v1.0.3', - datasource: 'gitea-tags', - depName: 'gitea.com/hashicorp/example', - depType: 'gitTags', - packageName: 'ssh://git@gitea.com/hashicorp/example', - }, ], }); - expect(res?.deps).toHaveLength(44); + expect(res?.deps).toHaveLength(32); expect(res?.deps.filter((dep) => dep.skipReason)).toHaveLength(4); }); @@ -463,34 +379,6 @@ describe('modules/manager/terragrunt/extract', () => { depType: 'gitTags', packageName: 'https://bitbucket.com/hashicorp/example', }, - { - currentValue: 'next', - datasource: 'bitbucket-tags', - depName: 'bitbucket.com/hashicorp/example', - depType: 'gitTags', - packageName: 'https://bitbucket.com/hashicorp/example', - }, - { - currentValue: 'v1.0.1', - datasource: 'bitbucket-tags', - depName: 'bitbucket.com/hashicorp/example', - depType: 'gitTags', - packageName: 'https://bitbucket.com/hashicorp/example', - }, - { - currentValue: 'v1.0.2', - datasource: 'bitbucket-tags', - depName: 'bitbucket.com/hashicorp/example', - depType: 'gitTags', - packageName: 'http://bitbucket.com/hashicorp/example', - }, - { - currentValue: 'v1.0.3', - datasource: 'bitbucket-tags', - depName: 'bitbucket.com/hashicorp/example', - depType: 'gitTags', - packageName: 'ssh://git@bitbucket.com/hashicorp/example', - }, { currentValue: 'v1.0.0', datasource: 'gitlab-tags', @@ -498,34 +386,6 @@ describe('modules/manager/terragrunt/extract', () => { depType: 'gitTags', packageName: 'https://gitlab.com/hashicorp/example', }, - { - currentValue: 'next', - datasource: 'gitlab-tags', - depName: 'gitlab.com/hashicorp/example', - depType: 'gitTags', - packageName: 'https://gitlab.com/hashicorp/example', - }, - { - currentValue: 'v1.0.1', - datasource: 'gitlab-tags', - depName: 'gitlab.com/hashicorp/example', - depType: 'gitTags', - packageName: 'https://gitlab.com/hashicorp/example', - }, - { - currentValue: 'v1.0.2', - datasource: 'gitlab-tags', - depName: 'gitlab.com/hashicorp/example', - depType: 'gitTags', - packageName: 'http://gitlab.com/hashicorp/example', - }, - { - currentValue: 'v1.0.3', - datasource: 'gitlab-tags', - depName: 'gitlab.com/hashicorp/example', - depType: 'gitTags', - packageName: 'ssh://git@gitlab.com/hashicorp/example', - }, { currentValue: 'v1.0.0', datasource: 'gitea-tags', @@ -533,37 +393,9 @@ describe('modules/manager/terragrunt/extract', () => { depType: 'gitTags', packageName: 'https://gitea.com/hashicorp/example', }, - { - currentValue: 'next', - datasource: 'gitea-tags', - depName: 'gitea.com/hashicorp/example', - depType: 'gitTags', - packageName: 'https://gitea.com/hashicorp/example', - }, - { - currentValue: 'v1.0.1', - datasource: 'gitea-tags', - depName: 'gitea.com/hashicorp/example', - depType: 'gitTags', - packageName: 'https://gitea.com/hashicorp/example', - }, - { - currentValue: 'v1.0.2', - datasource: 'gitea-tags', - depName: 'gitea.com/hashicorp/example', - depType: 'gitTags', - packageName: 'http://gitea.com/hashicorp/example', - }, - { - currentValue: 'v1.0.3', - datasource: 'gitea-tags', - depName: 'gitea.com/hashicorp/example', - depType: 'gitTags', - packageName: 'ssh://git@gitea.com/hashicorp/example', - }, ], }); - expect(res?.deps).toHaveLength(44); + expect(res?.deps).toHaveLength(32); expect(res?.deps.filter((dep) => dep.skipReason)).toHaveLength(4); }); @@ -726,34 +558,6 @@ describe('modules/manager/terragrunt/extract', () => { depType: 'gitTags', packageName: 'https://bitbucket.com/hashicorp/example', }, - { - currentValue: 'next', - datasource: 'bitbucket-tags', - depName: 'bitbucket.com/hashicorp/example', - depType: 'gitTags', - packageName: 'https://bitbucket.com/hashicorp/example', - }, - { - currentValue: 'v1.0.1', - datasource: 'bitbucket-tags', - depName: 'bitbucket.com/hashicorp/example', - depType: 'gitTags', - packageName: 'https://bitbucket.com/hashicorp/example', - }, - { - currentValue: 'v1.0.2', - datasource: 'bitbucket-tags', - depName: 'bitbucket.com/hashicorp/example', - depType: 'gitTags', - packageName: 'http://bitbucket.com/hashicorp/example', - }, - { - currentValue: 'v1.0.3', - datasource: 'bitbucket-tags', - depName: 'bitbucket.com/hashicorp/example', - depType: 'gitTags', - packageName: 'ssh://git@bitbucket.com/hashicorp/example', - }, { currentValue: 'v1.0.0', datasource: 'gitlab-tags', @@ -761,34 +565,6 @@ describe('modules/manager/terragrunt/extract', () => { depType: 'gitTags', packageName: 'https://gitlab.com/hashicorp/example', }, - { - currentValue: 'next', - datasource: 'gitlab-tags', - depName: 'gitlab.com/hashicorp/example', - depType: 'gitTags', - packageName: 'https://gitlab.com/hashicorp/example', - }, - { - currentValue: 'v1.0.1', - datasource: 'gitlab-tags', - depName: 'gitlab.com/hashicorp/example', - depType: 'gitTags', - packageName: 'https://gitlab.com/hashicorp/example', - }, - { - currentValue: 'v1.0.2', - datasource: 'gitlab-tags', - depName: 'gitlab.com/hashicorp/example', - depType: 'gitTags', - packageName: 'http://gitlab.com/hashicorp/example', - }, - { - currentValue: 'v1.0.3', - datasource: 'gitlab-tags', - depName: 'gitlab.com/hashicorp/example', - depType: 'gitTags', - packageName: 'ssh://git@gitlab.com/hashicorp/example', - }, { currentValue: 'v1.0.0', datasource: 'gitea-tags', @@ -796,37 +572,9 @@ describe('modules/manager/terragrunt/extract', () => { depType: 'gitTags', packageName: 'https://gitea.com/hashicorp/example', }, - { - currentValue: 'next', - datasource: 'gitea-tags', - depName: 'gitea.com/hashicorp/example', - depType: 'gitTags', - packageName: 'https://gitea.com/hashicorp/example', - }, - { - currentValue: 'v1.0.1', - datasource: 'gitea-tags', - depName: 'gitea.com/hashicorp/example', - depType: 'gitTags', - packageName: 'https://gitea.com/hashicorp/example', - }, - { - currentValue: 'v1.0.2', - datasource: 'gitea-tags', - depName: 'gitea.com/hashicorp/example', - depType: 'gitTags', - packageName: 'http://gitea.com/hashicorp/example', - }, - { - currentValue: 'v1.0.3', - datasource: 'gitea-tags', - depName: 'gitea.com/hashicorp/example', - depType: 'gitTags', - packageName: 'ssh://git@gitea.com/hashicorp/example', - }, ], }); - expect(res?.deps).toHaveLength(44); + expect(res?.deps).toHaveLength(32); expect(res?.deps.filter((dep) => dep.skipReason)).toHaveLength(4); }); From 5703e6fbc22d259b67bb644abd79c6705b842e25 Mon Sep 17 00:00:00 2001 From: lstoeferle <48953604+lstoeferle@users.noreply.github.com> Date: Mon, 18 Mar 2024 07:53:33 +0100 Subject: [PATCH 4/4] test: revert test refactorings --- .../manager/terragrunt/__fixtures__/2.hcl | 20 +++++--- .../manager/terragrunt/__fixtures__/3.hcl | 27 ++++++---- .../manager/terragrunt/__fixtures__/4.hcl | 27 ++++++---- .../manager/terragrunt/extract.spec.ts | 51 +++++++++++++------ 4 files changed, 81 insertions(+), 44 deletions(-) diff --git a/lib/modules/manager/terragrunt/__fixtures__/2.hcl b/lib/modules/manager/terragrunt/__fixtures__/2.hcl index 94cd97b3b17afa..f38c3924453967 100644 --- a/lib/modules/manager/terragrunt/__fixtures__/2.hcl +++ b/lib/modules/manager/terragrunt/__fixtures__/2.hcl @@ -125,17 +125,11 @@ terraform { foo = "bar" } -# invalid, ignored by test since it does not have source on the next line +# foobar terraform { + source = "https://mygit.com/hashicorp/example?ref=v1.0.0" } -# unsupported terragrunt, ignored by test since it does not have source on the next line -terraform { - name = "foo" - dummy = "true" -} - - # gittags terraform { source = "git::https://mygit.com/hashicorp/example?ref=v1.0.0" @@ -161,6 +155,16 @@ terraform { source = "git::ssh://git@mygit.com/hashicorp/example?ref=v1.0.3" } +# invalid, ignored by test since it does not have source on the next line +terraform { +} + +# unsupported terragrunt, ignored by test since it does not have source on the next line +terraform { + name = "foo" + dummy = "true" +} + # bitbucket-tags terraform { source = "git::https://bitbucket.com/hashicorp/example?ref=v1.0.0" diff --git a/lib/modules/manager/terragrunt/__fixtures__/3.hcl b/lib/modules/manager/terragrunt/__fixtures__/3.hcl index fe084be37eccf2..3cf9e16f8bca42 100644 --- a/lib/modules/manager/terragrunt/__fixtures__/3.hcl +++ b/lib/modules/manager/terragrunt/__fixtures__/3.hcl @@ -125,17 +125,11 @@ terraform { foo = "bar" } -# invalid, ignored by test since it does not have source on the next line -terraform { -} - -# unsupported terragrunt, ignored by test since it does not have source on the next line +# foobar terraform { - name = "foo" - dummy = "true" + source = "https://mygit.com/hashicorp/example?ref=v1.0.0&depth=1" } - # gittags terraform { source = "git::https://mygit.com/hashicorp/example?ref=v1.0.0&depth=1" @@ -161,17 +155,28 @@ terraform { source = "git::ssh://git@mygit.com/hashicorp/example?ref=v1.0.3&depth=1" } +# invalid, ignored by test since it does not have source on the next line +terraform { +} + +# unsupported terragrunt, ignored by test since it does not have source on the next line +terraform { + name = "foo" + dummy = "true" +} + # bitbucket-tags terraform { - source = "git::https://bitbucket.com/hashicorp/example?ref=v1.0.0&depth=1" + source = "git::https://bitbucket.com/hashicorp/example?ref=v1.0.0" } # gitlab-tags terraform { - source = "git::https://gitlab.com/hashicorp/example?ref=v1.0.0&depth=1" + source = "git::https://gitlab.com/hashicorp/example?ref=v1.0.0" } # gitea-tags terraform { - source = "git::https://gitea.com/hashicorp/example?ref=v1.0.0&depth=1" + source = "git::https://gitea.com/hashicorp/example?ref=v1.0.0" } + diff --git a/lib/modules/manager/terragrunt/__fixtures__/4.hcl b/lib/modules/manager/terragrunt/__fixtures__/4.hcl index 0a47b8618c6803..2eef263e14e3d5 100644 --- a/lib/modules/manager/terragrunt/__fixtures__/4.hcl +++ b/lib/modules/manager/terragrunt/__fixtures__/4.hcl @@ -125,14 +125,9 @@ terraform { foo = "bar" } -# invalid, ignored by test since it does not have source on the next line -terraform { -} - -# unsupported terragrunt, ignored by test since it does not have source on the next line +# foobar terraform { - name = "foo" - dummy = "true" + source = "https://mygit.com/hashicorp/example?depth=1&ref=v1.0.0" } # gittags @@ -160,17 +155,29 @@ terraform { source = "git::ssh://git@mygit.com/hashicorp/example?depth=1&ref=v1.0.3" } +# invalid, ignored by test since it does not have source on the next line +terraform { +} + +# unsupported terragrunt, ignored by test since it does not have source on the next line +terraform { + name = "foo" + dummy = "true" +} + + # bitbucket-tags terraform { - source = "git::https://bitbucket.com/hashicorp/example?depth=1&ref=v1.0.0" + source = "git::https://bitbucket.com/hashicorp/example?ref=v1.0.0" } # gitlab-tags terraform { - source = "git::https://gitlab.com/hashicorp/example?depth=1&ref=v1.0.0" + source = "git::https://gitlab.com/hashicorp/example?ref=v1.0.0" } # gitea-tags terraform { - source = "git::https://gitea.com/hashicorp/example?depth=1&ref=v1.0.0" + source = "git::https://gitea.com/hashicorp/example?ref=v1.0.0" } + diff --git a/lib/modules/manager/terragrunt/extract.spec.ts b/lib/modules/manager/terragrunt/extract.spec.ts index b35d6121a6ba44..bf997f14654a50 100644 --- a/lib/modules/manager/terragrunt/extract.spec.ts +++ b/lib/modules/manager/terragrunt/extract.spec.ts @@ -153,10 +153,11 @@ describe('modules/manager/terragrunt/extract', () => { skipReason: 'no-source', }, { - skipReason: 'no-source', - }, - { - skipReason: 'no-source', + currentValue: 'v1.0.0', + datasource: 'git-tags', + depName: 'mygit.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://mygit.com/hashicorp/example', }, { currentValue: 'v1.0.0', @@ -193,6 +194,12 @@ describe('modules/manager/terragrunt/extract', () => { depType: 'gitTags', packageName: 'ssh://git@mygit.com/hashicorp/example', }, + { + skipReason: 'no-source', + }, + { + skipReason: 'no-source', + }, { currentValue: 'v1.0.0', datasource: 'bitbucket-tags', @@ -216,7 +223,7 @@ describe('modules/manager/terragrunt/extract', () => { }, ], }); - expect(res?.deps).toHaveLength(32); + expect(res?.deps).toHaveLength(33); expect(res?.deps.filter((dep) => dep.skipReason)).toHaveLength(4); }); @@ -332,10 +339,11 @@ describe('modules/manager/terragrunt/extract', () => { skipReason: 'no-source', }, { - skipReason: 'no-source', - }, - { - skipReason: 'no-source', + currentValue: 'v1.0.0', + datasource: 'git-tags', + depName: 'mygit.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://mygit.com/hashicorp/example', }, { currentValue: 'v1.0.0', @@ -372,6 +380,12 @@ describe('modules/manager/terragrunt/extract', () => { depType: 'gitTags', packageName: 'ssh://git@mygit.com/hashicorp/example', }, + { + skipReason: 'no-source', + }, + { + skipReason: 'no-source', + }, { currentValue: 'v1.0.0', datasource: 'bitbucket-tags', @@ -395,7 +409,7 @@ describe('modules/manager/terragrunt/extract', () => { }, ], }); - expect(res?.deps).toHaveLength(32); + expect(res?.deps).toHaveLength(33); expect(res?.deps.filter((dep) => dep.skipReason)).toHaveLength(4); }); @@ -511,10 +525,11 @@ describe('modules/manager/terragrunt/extract', () => { skipReason: 'no-source', }, { - skipReason: 'no-source', - }, - { - skipReason: 'no-source', + currentValue: 'v1.0.0', + datasource: 'git-tags', + depName: 'mygit.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://mygit.com/hashicorp/example', }, { currentValue: 'v1.0.0', @@ -551,6 +566,12 @@ describe('modules/manager/terragrunt/extract', () => { depType: 'gitTags', packageName: 'ssh://git@mygit.com/hashicorp/example', }, + { + skipReason: 'no-source', + }, + { + skipReason: 'no-source', + }, { currentValue: 'v1.0.0', datasource: 'bitbucket-tags', @@ -574,7 +595,7 @@ describe('modules/manager/terragrunt/extract', () => { }, ], }); - expect(res?.deps).toHaveLength(32); + expect(res?.deps).toHaveLength(33); expect(res?.deps.filter((dep) => dep.skipReason)).toHaveLength(4); });