diff --git a/docs/development/shareable-configs.md b/docs/development/shareable-configs.md index 1add3fc2f1f00afd18ce614001c1121f5ec9e75f..3f665feac1a548621783ede831fa58471822c066 100644 --- a/docs/development/shareable-configs.md +++ b/docs/development/shareable-configs.md @@ -54,40 +54,44 @@ You can set a Git tag (like a SemVer) to use a specific release of your shared c #### GitHub -| name | example use | preset | resolves as | filename | Git tag | -| ------------------------------------------- | ------------------------------- | --------- | ---------------------------- | --------------- | -------------- | -| GitHub default | `github>abc/foo` | `default` | `https://github.com/abc/foo` | `default.json` | Default branch | -| GitHub with preset name | `github>abc/foo:xyz` | `xyz` | `https://github.com/abc/foo` | `xyz.json` | Default branch | -| GitHub default with a tag | `github>abc/foo#1.5.4` | `default` | `https://github.com/abc/foo` | `default.json` | `1.5.4` | -| GitHub with preset name with a tag | `github>abc/foo:xyz#1.5.4` | `xyz` | `https://github.com/abc/foo` | `xyz.json` | `1.5.4` | -| GitHub with preset name and path with a tag | `github>abc/foo:path/xyz#1.5.4` | `xyz` | `https://github.com/abc/foo` | `path/xyz.json` | `1.5.4` | +| name | example use | preset | resolves as | filename | Git tag | +| ------------------------------------------- | -------------------------------- | --------- | ---------------------------- | --------------- | -------------- | +| GitHub default | `github>abc/foo` | `default` | `https://github.com/abc/foo` | `default.json` | Default branch | +| GitHub with preset name | `github>abc/foo:xyz` | `xyz` | `https://github.com/abc/foo` | `xyz.json` | Default branch | +| GitHub default with a tag | `github>abc/foo#1.5.4` | `default` | `https://github.com/abc/foo` | `default.json` | `1.5.4` | +| GitHub with preset name with a tag | `github>abc/foo:xyz#1.5.4` | `xyz` | `https://github.com/abc/foo` | `xyz.json` | `1.5.4` | +| GitHub with preset name and path with a tag | `github>abc/foo//path/xyz#1.5.4` | `xyz` | `https://github.com/abc/foo` | `path/xyz.json` | `1.5.4` | +| GitHub with subpreset name and tag | `github>abc/foo:xyz/sub#1.5.4` | `sub` | `https://github.com/abc/foo` | `xyz.json` | `1.5.4` | #### GitLab -| name | example use | preset | resolves as | filename | Git tag | -| ------------------------------------------- | ------------------------------- | --------- | ---------------------------- | --------------- | -------------- | -| GitLab default | `gitlab>abc/foo` | `default` | `https://gitlab.com/abc/foo` | `default.json` | Default branch | -| GitLab with preset name | `gitlab>abc/foo:xyz` | `xyz` | `https://gitlab.com/abc/foo` | `xyz.json` | Default branch | -| GitLab default with a tag | `gitlab>abc/foo#1.5.4` | `default` | `https://gitlab.com/abc/foo` | `default.json` | `1.5.4` | -| GitLab with preset name with a tag | `gitlab>abc/foo:xyz#1.5.4` | `xyz` | `https://gitlab.com/abc/foo` | `xyz.json` | `1.5.4` | -| GitLab with preset name and path with a tag | `gitlab>abc/foo:path/xyz#1.5.4` | `xyz` | `https://gitlab.com/abc/foo` | `path/xyz.json` | `1.5.4` | +| name | example use | preset | resolves as | filename | Git tag | +| ------------------------------------------- | -------------------------------- | --------- | ---------------------------- | --------------- | -------------- | +| GitLab default | `gitlab>abc/foo` | `default` | `https://gitlab.com/abc/foo` | `default.json` | Default branch | +| GitLab with preset name | `gitlab>abc/foo:xyz` | `xyz` | `https://gitlab.com/abc/foo` | `xyz.json` | Default branch | +| GitLab default with a tag | `gitlab>abc/foo#1.5.4` | `default` | `https://gitlab.com/abc/foo` | `default.json` | `1.5.4` | +| GitLab with preset name with a tag | `gitlab>abc/foo:xyz#1.5.4` | `xyz` | `https://gitlab.com/abc/foo` | `xyz.json` | `1.5.4` | +| GitLab with preset name and path with a tag | `gitlab>abc/foo//path/xyz#1.5.4` | `xyz` | `https://gitlab.com/abc/foo` | `path/xyz.json` | `1.5.4` | +| GitLab with subpreset name and tag | `gitlab>abc/foo:xyz/sub#1.5.4` | `sub` | `https://gitlab.com/abc/foo` | `xyz.json` | `1.5.4` | #### Gitea -| name | example use | preset | resolves as | filename | Git tag | -| ------------------------------------------ | ------------------------------ | --------- | --------------------------- | --------------- | -------------- | -| Gitea default | `gitea>abc/foo` | `default` | `https://gitea.com/abc/foo` | `default.json` | Default branch | -| Gitea with preset name | `gitea>abc/foo:xyz` | `xyz` | `https://gitea.com/abc/foo` | `xyz.json` | Default branch | -| Gitea default with a tag | `gitea>abc/foo#1.5.4` | `default` | `https://gitea.com/abc/foo` | `default.json` | `1.5.4` | -| Gitea with preset name with a tag | `gitea>abc/foo:xyz#1.5.4` | `xyz` | `https://gitea.com/abc/foo` | `xyz.json` | `1.5.4` | -| Gitea with preset name and path with a tag | `gitea>abc/foo:path/xyz#1.5.4` | `xyz` | `https://gitea.com/abc/foo` | `path/xyz.json` | `1.5.4` | +| name | example use | preset | resolves as | filename | Git tag | +| ------------------------------------------ | ------------------------------- | --------- | --------------------------- | --------------- | -------------- | +| Gitea default | `gitea>abc/foo` | `default` | `https://gitea.com/abc/foo` | `default.json` | Default branch | +| Gitea with preset name | `gitea>abc/foo:xyz` | `xyz` | `https://gitea.com/abc/foo` | `xyz.json` | Default branch | +| Gitea default with a tag | `gitea>abc/foo#1.5.4` | `default` | `https://gitea.com/abc/foo` | `default.json` | `1.5.4` | +| Gitea with preset name with a tag | `gitea>abc/foo:xyz#1.5.4` | `xyz` | `https://gitea.com/abc/foo` | `xyz.json` | `1.5.4` | +| Gitea with preset name and path with a tag | `gitea>abc/foo//path/xyz#1.5.4` | `xyz` | `https://gitea.com/abc/foo` | `path/xyz.json` | `1.5.4` | +| Gitea with subpreset name and tag | `gitea>abc/foo:xyz/sub#1.5.4` | `sub` | `https://gitea.com/abc/foo` | `xyz.json` | `1.5.4` | #### Self-hosted Git -| name | example use | preset | resolves as | filename | Git tag | -| ------------------------------------------ | ------------------------------ | --------- | ------------------------------------ | --------------- | -------------- | -| Local default | `local>abc/foo` | `default` | `https://github.company.com/abc/foo` | `default.json` | Default branch | -| Local with preset path | `local>abc/foo:path/xyz` | `default` | `https://github.company.com/abc/foo` | `path/xyz.json` | Default branch | -| Local default with a tag | `local>abc/foo#1.5.4` | `default` | `https://github.company.com/abc/foo` | `default.json` | `1.5.4` | -| Local with preset name with a tag | `local>abc/foo:xyz#1.5.4` | `default` | `https://github.company.com/abc/foo` | `xyz.json` | `1.5.4` | -| Local with preset name and path with a tag | `local>abc/foo:path/xyz#1.5.4` | `default` | `https://github.company.com/abc/foo` | `path/xyz.json` | `1.5.4` | +| name | example use | preset | resolves as | filename | Git tag | +| ------------------------------------------ | ------------------------------- | --------- | ------------------------------------ | --------------- | -------------- | +| Local default | `local>abc/foo` | `default` | `https://github.company.com/abc/foo` | `default.json` | Default branch | +| Local with preset path | `local>abc/foo:path/xyz` | `default` | `https://github.company.com/abc/foo` | `path/xyz.json` | Default branch | +| Local default with a tag | `local>abc/foo#1.5.4` | `default` | `https://github.company.com/abc/foo` | `default.json` | `1.5.4` | +| Local with preset name with a tag | `local>abc/foo:xyz#1.5.4` | `default` | `https://github.company.com/abc/foo` | `xyz.json` | `1.5.4` | +| Local with preset name and path with a tag | `local>abc/foo//path/xyz#1.5.4` | `default` | `https://github.company.com/abc/foo` | `path/xyz.json` | `1.5.4` | +| Local with subpreset name and tag | `local>abc/foo:xyz/sub#1.5.4` | `sub` | `https://github.company.com/abc/foo` | `xyz.json` | `1.5.4` | diff --git a/docs/usage/config-presets.md b/docs/usage/config-presets.md index 3fa8da053fc23e6ad47d4a5ec7f4cc396d59f405..2d304497d7bbf7ee9da184c1631e2047f2d14632 100644 --- a/docs/usage/config-presets.md +++ b/docs/usage/config-presets.md @@ -45,13 +45,14 @@ You can set a Git tag (like a SemVer) to use a specific release of your shared c ### GitHub -| name | example use | preset | resolves as | filename | Git tag | -| ------------------------------------------- | ------------------------------- | --------- | ---------------------------- | --------------- | -------------- | -| GitHub default | `github>abc/foo` | `default` | `https://github.com/abc/foo` | `default.json` | Default branch | -| GitHub with preset name | `github>abc/foo:xyz` | `xyz` | `https://github.com/abc/foo` | `xyz.json` | Default branch | -| GitHub default with a tag | `github>abc/foo#1.5.4` | `default` | `https://github.com/abc/foo` | `default.json` | `1.5.4` | -| GitHub with preset name with a tag | `github>abc/foo:xyz#1.5.4` | `xyz` | `https://github.com/abc/foo` | `xyz.json` | `1.5.4` | -| GitHub with preset name and path with a tag | `github>abc/foo:path/xyz#1.5.4` | `xyz` | `https://github.com/abc/foo` | `path/xyz.json` | `1.5.4` | +| name | example use | preset | resolves as | filename | Git tag | +| ------------------------------------------- | -------------------------------- | --------- | ---------------------------- | --------------- | -------------- | +| GitHub default | `github>abc/foo` | `default` | `https://github.com/abc/foo` | `default.json` | Default branch | +| GitHub with preset name | `github>abc/foo:xyz` | `xyz` | `https://github.com/abc/foo` | `xyz.json` | Default branch | +| GitHub default with a tag | `github>abc/foo#1.5.4` | `default` | `https://github.com/abc/foo` | `default.json` | `1.5.4` | +| GitHub with preset name with a tag | `github>abc/foo:xyz#1.5.4` | `xyz` | `https://github.com/abc/foo` | `xyz.json` | `1.5.4` | +| GitHub with preset name and path with a tag | `github>abc/foo//path/xyz#1.5.4` | `xyz` | `https://github.com/abc/foo` | `path/xyz.json` | `1.5.4` | +| GitHub with subpreset name and tag | `github>abc/foo:xyz/sub#1.5.4` | `sub` | `https://github.com/abc/foo` | `xyz.json` | `1.5.4` | ### GitLab @@ -62,6 +63,7 @@ You can set a Git tag (like a SemVer) to use a specific release of your shared c | GitLab default with a tag | `gitlab>abc/foo#1.5.4` | `default` | `https://gitlab.com/abc/foo` | `default.json` | `1.5.4` | | GitLab with preset name with a tag | `gitlab>abc/foo:xyz#1.5.4` | `xyz` | `https://gitlab.com/abc/foo` | `xyz.json` | `1.5.4` | | GitLab with preset name and path with a tag | `gitlab>abc/foo:path/xyz#1.5.4` | `xyz` | `https://gitlab.com/abc/foo` | `path/xyz.json` | `1.5.4` | +| GitLab with subpreset name and tag | `gitlab>abc/foo:xyz/sub#1.5.4` | `sub` | `https://gitlab.com/abc/foo` | `xyz.json` | `1.5.4` | ### Gitea @@ -72,6 +74,7 @@ You can set a Git tag (like a SemVer) to use a specific release of your shared c | Gitea default with a tag | `gitea>abc/foo#1.5.4` | `default` | `https://gitea.com/abc/foo` | `default.json` | `1.5.4` | | Gitea with preset name with a tag | `gitea>abc/foo:xyz#1.5.4` | `xyz` | `https://gitea.com/abc/foo` | `xyz.json` | `1.5.4` | | Gitea with preset name and path with a tag | `gitea>abc/foo:path/xyz#1.5.4` | `xyz` | `https://gitea.com/abc/foo` | `path/xyz.json` | `1.5.4` | +| Gitea with subpreset name and tag | `gitea>abc/foo:xyz/sub#1.5.4` | `sub` | `https://gitea.com/abc/foo` | `xyz.json` | `1.5.4` | ### Self-hosted Git @@ -82,6 +85,7 @@ You can set a Git tag (like a SemVer) to use a specific release of your shared c | Local default with a tag | `local>abc/foo#1.5.4` | `default` | `https://github.company.com/abc/foo` | `default.json` | `1.5.4` | | Local with preset name with a tag | `local>abc/foo:xyz#1.5.4` | `xyz` | `https://github.company.com/abc/foo` | `xyz.json` | `1.5.4` | | Local with preset name and path with a tag | `local>abc/foo:path/xyz#1.5.4` | `xyz` | `https://github.company.com/abc/foo` | `path/xyz.json` | `1.5.4` | +| Local with subpreset name and tag | `local>abc/foo:xyz/sub#1.5.4` | `sub` | `https://github.company.com/abc/foo` | `xyz.json` | `1.5.4` | Note that you can't combine the path and sub-preset syntaxes. This means that anything in the form `provider>owner/repo//path/to/file:subsubpreset` is not supported. diff --git a/lib/config/presets/index.spec.ts b/lib/config/presets/index.spec.ts index 71563487ef8a29e910c73d64a3d014b682a01744..523484bdfc839e8dc337f8fdd7280a31dde44008 100644 --- a/lib/config/presets/index.spec.ts +++ b/lib/config/presets/index.spec.ts @@ -342,8 +342,8 @@ describe('config/presets/index', () => { ).toEqual({ packageName: 'some/repo', params: undefined, - presetName: 'somepreset', - presetPath: 'somefile', + presetName: 'somefile/somepreset', + presetPath: undefined, presetSource: 'github', }); }); @@ -355,8 +355,8 @@ describe('config/presets/index', () => { ).toEqual({ packageName: 'some/repo', params: undefined, - presetName: 'somesubpreset', - presetPath: 'somefile/somepreset', + presetName: 'somefile/somepreset/somesubpreset', + presetPath: undefined, presetSource: 'github', }); }); @@ -427,6 +427,34 @@ describe('config/presets/index', () => { presetSource: 'local', }); }); + it('parses local with sub preset and tag', () => { + expect( + presets.parsePreset( + 'local>some-group/some-repo:some-file/subpreset#1.2.3' + ) + ).toEqual({ + packageName: 'some-group/some-repo', + params: undefined, + presetName: 'some-file/subpreset', + presetPath: undefined, + presetSource: 'local', + packageTag: '1.2.3', + }); + }); + it('parses local with subdirectory and tag', () => { + expect( + presets.parsePreset( + 'local>some-group/some-repo//some-dir/some-file#1.2.3' + ) + ).toEqual({ + packageName: 'some-group/some-repo', + params: undefined, + presetName: 'some-file', + presetPath: 'some-dir', + presetSource: 'local', + packageTag: '1.2.3', + }); + }); it('parses no prefix as local', () => { expect(presets.parsePreset('some/repo')).toEqual({ packageName: 'some/repo', diff --git a/lib/config/presets/index.ts b/lib/config/presets/index.ts index 16a39c1ac17941f0a326a8dd90d904ffc6a0d7ed..4dc90acb3a3acd202057b76b2a801f01bda5a494 100644 --- a/lib/config/presets/index.ts +++ b/lib/config/presets/index.ts @@ -40,7 +40,7 @@ const nonScopedPresetWithSubdirRegex = regEx( /^(?<packageName>~?[\w\-./]+?)\/\/(?:(?<presetPath>[\w\-./]+)\/)?(?<presetName>[\w\-.]+)(?:#(?<packageTag>[\w\-.]+?))?$/ ); const gitPresetRegex = regEx( - /^(?<packageName>[\w\-. /]+)(?::(?<presetPath>[\w-./]+\/))?(?::?(?<presetName>[\w\-.+]+))?(?:#(?<packageTag>[\w\-.]+?))?$/ + /^(?<packageName>[\w\-. /]+)(?::(?<presetName>[\w\-.+/]+))?(?:#(?<packageTag>[\w\-.]+?))?$/ ); export function replaceArgs( @@ -75,10 +75,10 @@ export function replaceArgs( export function parsePreset(input: string): ParsedPreset { let str = input; let presetSource: string; - let presetPath: string; + let presetPath: string | undefined; let packageName: string; let presetName: string; - let packageTag: string; + let packageTag: string | undefined; let params: string[]; if (str.startsWith('github>')) { presetSource = 'github'; @@ -159,13 +159,9 @@ export function parsePreset(input: string): ParsedPreset { ({ packageName, presetPath, presetName, packageTag } = nonScopedPresetWithSubdirRegex.exec(str)?.groups || {}); } else { - ({ packageName, presetPath, presetName, packageTag } = + ({ packageName, presetName, packageTag } = gitPresetRegex.exec(str)?.groups || {}); - if (is.nonEmptyString(presetPath) && presetPath.endsWith('/')) { - presetPath = presetPath.slice(0, -1); - } - if (presetSource === 'npm' && !packageName.startsWith('renovate-config-')) { packageName = `renovate-config-${packageName}`; }