Skip to content

Commit 20d1dec

Browse files
TeamCity: Enable 'MM Upstream' projects (#8646) (#6076)
* Make adding a cron trigger dependent on the user-supplied environment value * Rename helpers.kt to test_utils.kt * Add unit tests for `ShouldAddTrigger` function * Update capitalisation of test util function names * Add `ENVIRONMENT` param to TeamCity projects, making it visible to non-admins * Fix copyright header and package for new helpers.kt file Signed-off-by: Modular Magician <[email protected]>
1 parent 766fd07 commit 20d1dec

File tree

7 files changed

+69
-14
lines changed

7 files changed

+69
-14
lines changed

.changelog/8646.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:none
2+
3+
```

.teamcity/components/generated/project.kt

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ fun GoogleBeta(environment: String, manualVcsRoot: AbsoluteId, branchRef: String
2222
val preSweeperConfig = buildConfigurationForSweeper("Pre-Sweeper", sweepers, providerName, manualVcsRoot, configuration)
2323
val postSweeperConfig = buildConfigurationForSweeper("Post-Sweeper", sweepers, providerName, manualVcsRoot, configuration)
2424

25-
// Add trigger to last step of build chain (post-sweeper)
26-
val triggerConfig = NightlyTriggerConfiguration(environment, branchRef)
27-
postSweeperConfig.addTrigger(triggerConfig)
25+
// Add trigger to last step of build chain (post-sweeper) if the project allows
26+
if (ShouldAddTrigger(environment)){
27+
val triggerConfig = NightlyTriggerConfiguration(environment, branchRef)
28+
postSweeperConfig.addTrigger(triggerConfig)
29+
}
30+
2831

2932
return Project{
3033

@@ -56,6 +59,9 @@ fun GoogleBeta(environment: String, manualVcsRoot: AbsoluteId, branchRef: String
5659

5760
params {
5861
param("BRANCH_NAME", branchRef)
62+
63+
// Not used, but making `environment` a param makes the value visible to non-admins in TeamCity
64+
param("ENVIRONMENT", environment)
5965
}
6066
}
6167
}
@@ -85,6 +91,16 @@ fun buildConfigurationForSweeper(sweeperName: String, packages: Map<String, Map<
8591
return s.sweeperBuildConfig(sweeperName, sweeperPath, providerName, manualVcsRoot, defaultParallelism, environmentVariables)
8692
}
8793

94+
fun ShouldAddTrigger(environment: String): Boolean {
95+
if (environment == MM_UPSTREAM) {
96+
// The 'MM uptream' projects are only ever used for ad hoc builds,
97+
// never run on a schedule, so no cron trigger is needed
98+
return false
99+
}
100+
101+
return true
102+
}
103+
88104
class NightlyTriggerConfiguration(environment: String, branchRef: String, nightlyTestsEnabled: Boolean = true, startHour: Int = defaultStartHour, daysOfWeek: String = defaultDaysOfWeek, daysOfMonth: String = defaultDaysOfMonth) {
89105

90106
// Default values are used below unless

.teamcity/components/generated/settings.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ const val defaultBuildTimeoutDuration = 60 * 12 //12 hours in minutes
2626
// Values that `environment` parameter is checked against,
2727
// when deciding to change how TeamCity objects are configured
2828
const val MAJOR_RELEASE_TESTING = "major-release-5.0.0-testing"
29+
const val MM_UPSTREAM = "mm-upstream"

.teamcity/tests/generated/configuration.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ import useTeamCityGoTest
1515
class ConfigurationTests {
1616
@Test
1717
fun buildShouldFailOnError() {
18-
val project = GoogleBeta("default", TestVcsRootId(), "refs/heads/main", TestConfiguration())
18+
val project = GoogleBeta("default", testVcsRootId(), "refs/heads/main", testConfiguration())
1919
project.buildTypes.forEach { bt ->
2020
assertTrue("Build '${bt.id}' should fail on errors!", bt.failureConditions.errorMessage)
2121
}
2222
}
2323

2424
@Test
2525
fun buildShouldHaveGoTestFeature() {
26-
val project = GoogleBeta("default", TestVcsRootId(), "refs/heads/main",TestConfiguration())
26+
val project = GoogleBeta("default", testVcsRootId(), "refs/heads/main",testConfiguration())
2727
project.buildTypes.forEach{ bt ->
2828
var exists = false
2929
bt.features.items.forEach { f ->
@@ -42,7 +42,7 @@ class ConfigurationTests {
4242
// Once I have the ability to run tests I'll address this - writing new tests for the new config
4343
// @Test
4444
// fun buildShouldHaveTrigger() {
45-
// val project = Google("default", TestVcsRootId(), "refs/heads/main", TestConfiguration())
45+
// val project = Google("default", testVcsRootId(), "refs/heads/main", testConfiguration())
4646
// var exists = false
4747
// project.buildTypes.forEach{ bt ->
4848
// bt.triggers.items.forEach { t ->

.teamcity/tests/generated/vcs_roots.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import org.junit.Test
1414
class VcsTests {
1515
@Test
1616
fun buildsHaveCleanCheckOut() {
17-
val project = GoogleBeta("default", TestVcsRootId(), "refs/heads/main", TestConfiguration())
17+
val project = GoogleBeta("default", testVcsRootId(), "refs/heads/main", testConfiguration())
1818
project.buildTypes.forEach { bt ->
1919
assertTrue("Build '${bt.id}' doesn't use clean checkout", bt.vcs.cleanCheckout)
2020
}

.teamcity/tests/helpers.kt

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,29 @@
77

88
package tests
99

10-
import jetbrains.buildServer.configs.kotlin.AbsoluteId
10+
import org.junit.Assert.assertTrue
11+
import org.junit.Assert.assertFalse
12+
import org.junit.Test
13+
import ShouldAddTrigger
14+
import MM_UPSTREAM
15+
import MAJOR_RELEASE_TESTING
1116

12-
import ClientConfiguration
17+
class HelperTests {
18+
@Test
19+
fun funShouldAddTrigger_random_string() {
20+
val environment = "foobar"
21+
assertTrue("Cron triggers should be added to projects with a random environment value" , ShouldAddTrigger(environment))
22+
}
1323

14-
fun TestConfiguration() : ClientConfiguration {
15-
return ClientConfiguration("custId", "org", "org2", "billingAccount", "billingAccount2", "masterBillingAccount", "credentials", "project", "orgDomain", "projectNumber", "region", "serviceAccount", "zone", "firestoreProject", "identityUser")
16-
}
24+
@Test
25+
fun funShouldAddTrigger_MAJOR_RELEASE_TESTING() {
26+
val environment = MAJOR_RELEASE_TESTING
27+
assertTrue("Cron triggers should be added to projects used for testing the 5.0.0 major release" , ShouldAddTrigger(environment))
28+
}
1729

18-
fun TestVcsRootId() : AbsoluteId {
19-
return AbsoluteId("TerraformProviderFoobar")
30+
@Test
31+
fun funShouldAddTrigger_MM_UPSTREAM() {
32+
val environment = MM_UPSTREAM
33+
assertFalse("Cron triggers should NOT be added to projects using the MM upstream repo" , ShouldAddTrigger(environment))
34+
}
2035
}

.teamcity/tests/test_utils.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) HashiCorp, Inc.
3+
* SPDX-License-Identifier: MPL-2.0
4+
*/
5+
6+
// this file is copied from mmv1, any changes made here will be overwritten
7+
8+
package tests
9+
10+
import jetbrains.buildServer.configs.kotlin.AbsoluteId
11+
12+
import ClientConfiguration
13+
14+
fun testConfiguration() : ClientConfiguration {
15+
return ClientConfiguration("custId", "org", "org2", "billingAccount", "billingAccount2", "masterBillingAccount", "credentials", "project", "orgDomain", "projectNumber", "region", "serviceAccount", "zone", "firestoreProject", "identityUser")
16+
}
17+
18+
fun testVcsRootId() : AbsoluteId {
19+
return AbsoluteId("TerraformProviderFoobar")
20+
}

0 commit comments

Comments
 (0)