diff --git a/mmv1/third_party/terraform/.teamcity/components/build_config_package.kt b/mmv1/third_party/terraform/.teamcity/components/build_config_package.kt index c443f1373ff8..d46cf0c6e52e 100644 --- a/mmv1/third_party/terraform/.teamcity/components/build_config_package.kt +++ b/mmv1/third_party/terraform/.teamcity/components/build_config_package.kt @@ -35,6 +35,7 @@ class packageDetails(packageName: String, displayName: String, providerName: Str steps { SetGitCommitBuildId() + TagBuildToIndicatePurpose() ConfigureGoEnv() DownloadTerraformBinary() RunAcceptanceTests() diff --git a/mmv1/third_party/terraform/.teamcity/components/generated/build_components.erb b/mmv1/third_party/terraform/.teamcity/components/generated/build_components.erb index a2d75245b48a..9ab4c6b60d1a 100644 --- a/mmv1/third_party/terraform/.teamcity/components/generated/build_components.erb +++ b/mmv1/third_party/terraform/.teamcity/components/generated/build_components.erb @@ -59,6 +59,29 @@ fun BuildSteps.SetGitCommitBuildId() { }) } +fun BuildSteps.TagBuildToIndicatePurpose() { + step(ScriptBuildStep { + name = "Set build tag to indicate if build is run automatically or manually triggered" + scriptContent = """ + #!/bin/bash + TRIGGERED_BY_USERNAME=%teamcity.build.triggeredBy.username% + + if [[ "${'$'}TRIGGERED_BY_USERNAME" = "n/a" ]] ; then + echo "Build was triggered as part of automated testing. We know this because the `triggeredBy.username` value was `n/a`, value: ${'$'}{TRIGGERED_BY_USERNAME}" + TAG="nightly-test" + echo "##teamcity[addBuildTag '${'$'}{TAG}']" + else + echo "Build wasn't triggered as part of automated testing. We know this because the `triggeredBy.username` value was not `n/a`, value: ${'$'}{TRIGGERED_BY_USERNAME}" + TAG="one-off-build" + echo "##teamcity[addBuildTag '${'$'}{TAG}']" + fi + """.trimIndent() + // ${'$'} is required to allow creating a script in TeamCity that contains + // parts like ${GIT_HASH_SHORT} without having Kotlin syntax issues. For more info see: + // https://youtrack.jetbrains.com/issue/KT-2425/Provide-a-way-for-escaping-the-dollar-sign-symbol-in-multiline-strings-and-string-templates + }) +} + fun BuildSteps.DownloadTerraformBinary() { // https://releases.hashicorp.com/terraform/0.12.28/terraform_0.12.28_linux_amd64.zip var terraformUrl = "https://releases.hashicorp.com/terraform/%env.TERRAFORM_CORE_VERSION%/terraform_%env.TERRAFORM_CORE_VERSION%_linux_amd64.zip" diff --git a/mmv1/third_party/terraform/.teamcity/components/generated/project.erb b/mmv1/third_party/terraform/.teamcity/components/generated/project.erb index c943d0b87b47..6896cb8f7ad3 100644 --- a/mmv1/third_party/terraform/.teamcity/components/generated/project.erb +++ b/mmv1/third_party/terraform/.teamcity/components/generated/project.erb @@ -13,7 +13,7 @@ const val providerName = "google<%= "-" + version unless version == 'ga' -%>" // Google<%= version.capitalize unless version == 'ga' -%> returns an instance of Project, // which has multiple build configurations defined within it. // See https://teamcity.jetbrains.com/app/dsl-documentation/root/project/index.html -fun Google<%= version.capitalize unless version == 'ga' -%>(environment: String, manualVcsRoot: AbsoluteId, branchRef: String, configuration: ClientConfiguration) : Project { +fun Google<%= version.capitalize unless version == 'ga' -%>(environment: String, projDescription: String, manualVcsRoot: AbsoluteId, branchRef: String, configuration: ClientConfiguration) : Project { // Create build configs for each package defined in packages.kt and services.kt files val allPackages = packages + services @@ -29,9 +29,10 @@ fun Google<%= version.capitalize unless version == 'ga' -%>(environment: String, postSweeperConfig.addTrigger(triggerConfig) } - return Project{ + description = projDescription + // Register build configs in the project buildType(preSweeperConfig) packageConfigs.forEach { buildConfiguration -> diff --git a/mmv1/third_party/terraform/.teamcity/components/sweepers.kt b/mmv1/third_party/terraform/.teamcity/components/sweepers.kt index 6f3076b5e382..9614f12b17ec 100644 --- a/mmv1/third_party/terraform/.teamcity/components/sweepers.kt +++ b/mmv1/third_party/terraform/.teamcity/components/sweepers.kt @@ -37,6 +37,7 @@ class sweeperDetails() { steps { SetGitCommitBuildId() + TagBuildToIndicatePurpose() ConfigureGoEnv() DownloadTerraformBinary() RunSweepers(sweeperName) diff --git a/mmv1/third_party/terraform/.teamcity/generated/settings.kts.erb b/mmv1/third_party/terraform/.teamcity/generated/settings.kts.erb index dff1c18f446b..09f769720994 100644 --- a/mmv1/third_party/terraform/.teamcity/generated/settings.kts.erb +++ b/mmv1/third_party/terraform/.teamcity/generated/settings.kts.erb @@ -42,9 +42,10 @@ var manualVcsRoot = DslContext.settingsRootId // Values of these context parameters change configuration code behaviour. var environment = DslContext.getParameter("environment", "default") var branchRef = DslContext.getParameter("branch", "refs/heads/main") +var projDescription = DslContext.getParameter("description", "") var clientConfig = ClientConfiguration(custId, org, org2, billingAccount, billingAccount2, masterBillingAccount, credentials, project, orgDomain, projectNumber, region, serviceAccount, zone, firestoreProject, identityUser) // This is the entry point of the code in .teamcity/ // See https://teamcity.jetbrains.com/app/dsl-documentation/root/project.html -project(Google<%= version.capitalize unless version == 'ga' -%>(environment, manualVcsRoot, branchRef, clientConfig)) +project(Google<%= version.capitalize unless version == 'ga' -%>(environment, projDescription, manualVcsRoot, branchRef, clientConfig)) diff --git a/mmv1/third_party/terraform/.teamcity/tests/generated/configuration.erb b/mmv1/third_party/terraform/.teamcity/tests/generated/configuration.erb index c9387ca57e21..9c9af7a26f52 100644 --- a/mmv1/third_party/terraform/.teamcity/tests/generated/configuration.erb +++ b/mmv1/third_party/terraform/.teamcity/tests/generated/configuration.erb @@ -17,7 +17,7 @@ import useTeamCityGoTest class ConfigurationTests { @Test fun buildShouldFailOnError() { - val project = Google<%= version.capitalize unless version == 'ga' -%>("default", testVcsRootId(), "refs/heads/main", testConfiguration()) + val project = Google<%= version.capitalize unless version == 'ga' -%>("default", "description", testVcsRootId(), "refs/heads/main", testConfiguration()) project.buildTypes.forEach { bt -> assertTrue("Build '${bt.id}' should fail on errors!", bt.failureConditions.errorMessage) } @@ -25,7 +25,7 @@ class ConfigurationTests { @Test fun buildShouldHaveGoTestFeature() { - val project = Google<%= version.capitalize unless version == 'ga' -%>("default", testVcsRootId(), "refs/heads/main",testConfiguration()) + val project = Google<%= version.capitalize unless version == 'ga' -%>("default", "description", testVcsRootId(), "refs/heads/main", testConfiguration()) project.buildTypes.forEach{ bt -> var exists = false bt.features.items.forEach { f -> @@ -44,7 +44,7 @@ class ConfigurationTests { // Once I have the ability to run tests I'll address this - writing new tests for the new config // @Test // fun buildShouldHaveTrigger() { - // val project = Google("default", testVcsRootId(), "refs/heads/main", testConfiguration()) + // val project = Google("default", "description", testVcsRootId(), "refs/heads/main", testConfiguration()) // var exists = false // project.buildTypes.forEach{ bt -> // bt.triggers.items.forEach { t -> diff --git a/mmv1/third_party/terraform/.teamcity/tests/generated/vcs_roots.erb b/mmv1/third_party/terraform/.teamcity/tests/generated/vcs_roots.erb index 514dae3f765c..da0b7237b21a 100644 --- a/mmv1/third_party/terraform/.teamcity/tests/generated/vcs_roots.erb +++ b/mmv1/third_party/terraform/.teamcity/tests/generated/vcs_roots.erb @@ -16,7 +16,7 @@ import org.junit.Test class VcsTests { @Test fun buildsHaveCleanCheckOut() { - val project = Google<%= version.capitalize unless version == 'ga' -%>("default", testVcsRootId(), "refs/heads/main", testConfiguration()) + val project = Google<%= version.capitalize unless version == 'ga' -%>("default", "description", testVcsRootId(), "refs/heads/main", testConfiguration()) project.buildTypes.forEach { bt -> assertTrue("Build '${bt.id}' doesn't use clean checkout", bt.vcs.cleanCheckout) }