diff --git a/core/src/config/config-context.ts b/core/src/config/config-context.ts index 63ef4acb15..37cdd07b58 100644 --- a/core/src/config/config-context.ts +++ b/core/src/config/config-context.ts @@ -289,11 +289,24 @@ class LocalContext extends ConfigContext { @schema( joi .string() - .description("The current username (as resolved by https://github.com/sindresorhus/username)") + .description("The current username (as resolved by https://github.com/sindresorhus/username).") .example("tenzing_norgay") ) public username?: string + @schema( + joi + .string() + .description( + deline` + The current username (as resolved by https://github.com/sindresorhus/username), with any upper case + characters converted to lower case. + ` + ) + .example("tenzing_norgay") + ) + public usernameLowerCase?: string + constructor(root: ConfigContext, artifactsPath: string, projectRoot: string, username?: string) { super(root) this.artifactsPath = artifactsPath @@ -301,6 +314,7 @@ class LocalContext extends ConfigContext { this.platform = process.platform this.projectPath = projectRoot this.username = username + this.usernameLowerCase = username ? username.toLowerCase() : undefined } } diff --git a/core/test/unit/src/config/config-context.ts b/core/test/unit/src/config/config-context.ts index 6f44b26c4d..2aff10a988 100644 --- a/core/test/unit/src/config/config-context.ts +++ b/core/test/unit/src/config/config-context.ts @@ -400,6 +400,23 @@ describe("ProjectConfigContext", () => { resolved: process.platform, }) }) + + it("should resolve the local username (both regular and lower case versions)", () => { + const c = new ProjectConfigContext({ + projectName: "some-project", + projectRoot: "/tmp", + artifactsPath: "/tmp", + branch: "main", + username: "SomeUser", + secrets: {}, + }) + expect(c.resolve({ key: ["local", "username"], nodePath: [], opts: {} })).to.eql({ + resolved: "SomeUser", + }) + expect(c.resolve({ key: ["local", "usernameLowerCase"], nodePath: [], opts: {} })).to.eql({ + resolved: "someuser", + }) + }) }) describe("ProviderConfigContext", () => { diff --git a/docs/reference/template-strings.md b/docs/reference/template-strings.md index 2dc0fecdc6..9766c79511 100644 --- a/docs/reference/template-strings.md +++ b/docs/reference/template-strings.md @@ -82,7 +82,7 @@ my-variable: ${local.projectPath} ### `${local.username}` -The current username (as resolved by https://github.com/sindresorhus/username) +The current username (as resolved by https://github.com/sindresorhus/username). | Type | | -------- | @@ -94,6 +94,20 @@ Example: my-variable: ${local.username} ``` +### `${local.usernameLowerCase}` + +The current username (as resolved by https://github.com/sindresorhus/username), with any upper case characters converted to lower case. + +| Type | +| -------- | +| `string` | + +Example: + +```yaml +my-variable: ${local.usernameLowerCase} +``` + ### `${project.*}` Information about the Garden project. @@ -220,7 +234,7 @@ my-variable: ${local.projectPath} ### `${local.username}` -The current username (as resolved by https://github.com/sindresorhus/username) +The current username (as resolved by https://github.com/sindresorhus/username). | Type | | -------- | @@ -232,6 +246,20 @@ Example: my-variable: ${local.username} ``` +### `${local.usernameLowerCase}` + +The current username (as resolved by https://github.com/sindresorhus/username), with any upper case characters converted to lower case. + +| Type | +| -------- | +| `string` | + +Example: + +```yaml +my-variable: ${local.usernameLowerCase} +``` + ### `${project.*}` Information about the Garden project. @@ -390,7 +418,7 @@ my-variable: ${local.projectPath} ### `${local.username}` -The current username (as resolved by https://github.com/sindresorhus/username) +The current username (as resolved by https://github.com/sindresorhus/username). | Type | | -------- | @@ -402,6 +430,20 @@ Example: my-variable: ${local.username} ``` +### `${local.usernameLowerCase}` + +The current username (as resolved by https://github.com/sindresorhus/username), with any upper case characters converted to lower case. + +| Type | +| -------- | +| `string` | + +Example: + +```yaml +my-variable: ${local.usernameLowerCase} +``` + ### `${project.*}` Information about the Garden project. @@ -653,7 +695,7 @@ my-variable: ${local.projectPath} ### `${local.username}` -The current username (as resolved by https://github.com/sindresorhus/username) +The current username (as resolved by https://github.com/sindresorhus/username). | Type | | -------- | @@ -665,6 +707,20 @@ Example: my-variable: ${local.username} ``` +### `${local.usernameLowerCase}` + +The current username (as resolved by https://github.com/sindresorhus/username), with any upper case characters converted to lower case. + +| Type | +| -------- | +| `string` | + +Example: + +```yaml +my-variable: ${local.usernameLowerCase} +``` + ### `${project.*}` Information about the Garden project. @@ -1084,7 +1140,7 @@ my-variable: ${local.projectPath} ### `${local.username}` -The current username (as resolved by https://github.com/sindresorhus/username) +The current username (as resolved by https://github.com/sindresorhus/username). | Type | | -------- | @@ -1096,6 +1152,20 @@ Example: my-variable: ${local.username} ``` +### `${local.usernameLowerCase}` + +The current username (as resolved by https://github.com/sindresorhus/username), with any upper case characters converted to lower case. + +| Type | +| -------- | +| `string` | + +Example: + +```yaml +my-variable: ${local.usernameLowerCase} +``` + ### `${project.*}` Information about the Garden project. @@ -1512,7 +1582,7 @@ my-variable: ${local.projectPath} ### `${local.username}` -The current username (as resolved by https://github.com/sindresorhus/username) +The current username (as resolved by https://github.com/sindresorhus/username). | Type | | -------- | @@ -1524,6 +1594,20 @@ Example: my-variable: ${local.username} ``` +### `${local.usernameLowerCase}` + +The current username (as resolved by https://github.com/sindresorhus/username), with any upper case characters converted to lower case. + +| Type | +| -------- | +| `string` | + +Example: + +```yaml +my-variable: ${local.usernameLowerCase} +``` + ### `${project.*}` Information about the Garden project.