Skip to content

Commit 828c936

Browse files
teamcity: add release_tests subproject (#14628) (#23714)
[upstream:ffd69b0e2cabca605cd233a0be544cc44181c6ad] Signed-off-by: Modular Magician <[email protected]>
1 parent ed805b8 commit 828c936

10 files changed

+148
-13
lines changed

.teamcity/components/builds/build_configuration_per_package.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ import replaceCharsId
2020

2121
// BuildConfigurationsForPackages accepts a map containing details of multiple packages in a provider and returns a list of build configurations for them all.
2222
// Intended to be used in projects where we're testing all packages, e.g. the nightly test projects
23-
fun BuildConfigurationsForPackages(packages: Map<String, Map<String, String>>, providerName: String, parentProjectName: String, vcsRoot: GitVcsRoot, sharedResources: List<String>, environmentVariables: AccTestConfiguration, testPrefix: String = "TestAcc"): List<BuildType> {
23+
fun BuildConfigurationsForPackages(packages: Map<String, Map<String, String>>, providerName: String, parentProjectName: String, vcsRoot: GitVcsRoot, sharedResources: List<String>, environmentVariables: AccTestConfiguration, testPrefix: String = "TestAcc", releaseDiffTest: String = "false"): List<BuildType> {
2424
val list = ArrayList<BuildType>()
2525

2626
// Create build configurations for all packages, except sweeper
2727
packages.forEach { (packageName, info) ->
2828
val path: String = info.getValue("path").toString()
2929
val displayName: String = info.getValue("displayName").toString()
3030

31-
val pkg = PackageDetails(packageName, displayName, providerName, parentProjectName)
31+
val pkg = PackageDetails(packageName, displayName, providerName, parentProjectName, releaseDiffTest)
3232
val buildConfig = pkg.buildConfiguration(path, vcsRoot, sharedResources, environmentVariables, testPrefix = testPrefix)
3333
list.add(buildConfig)
3434
}
@@ -38,12 +38,12 @@ fun BuildConfigurationsForPackages(packages: Map<String, Map<String, String>>, p
3838

3939
// BuildConfigurationForSinglePackage accepts details of a single package in a provider and returns a build configuration for it
4040
// Intended to be used in short-lived projects where we're testing specific packages, e.g. feature branch testing
41-
fun BuildConfigurationForSinglePackage(packageName: String, packagePath: String, packageDisplayName: String, providerName: String, parentProjectName: String, vcsRoot: GitVcsRoot, sharedResources: List<String>, environmentVariables: AccTestConfiguration, testPrefix: String = "TestAcc"): BuildType{
42-
val pkg = PackageDetails(packageName, packageDisplayName, providerName, parentProjectName)
41+
fun BuildConfigurationForSinglePackage(packageName: String, packagePath: String, packageDisplayName: String, providerName: String, parentProjectName: String, vcsRoot: GitVcsRoot, sharedResources: List<String>, environmentVariables: AccTestConfiguration, testPrefix: String = "TestAcc", releaseDiffTest: String = "false"): BuildType{
42+
val pkg = PackageDetails(packageName, packageDisplayName, providerName, parentProjectName, releaseDiffTest)
4343
return pkg.buildConfiguration(packagePath, vcsRoot, sharedResources, environmentVariables, testPrefix = testPrefix)
4444
}
4545

46-
class PackageDetails(private val packageName: String, private val displayName: String, private val providerName: String, private val parentProjectName: String) {
46+
class PackageDetails(private val packageName: String, private val displayName: String, private val providerName: String, private val parentProjectName: String, private val releaseDiffTest: String) {
4747

4848
// buildConfiguration returns a BuildType for a service package
4949
// For BuildType docs, see https://teamcity.jetbrains.com/app/dsl-documentation/root/build-type/index.html
@@ -91,7 +91,7 @@ class PackageDetails(private val packageName: String, private val displayName: S
9191

9292
params {
9393
configureGoogleSpecificTestParameters(environmentVariables)
94-
acceptanceTestBuildParams(parallelism, testPrefix, testTimeout)
94+
acceptanceTestBuildParams(parallelism, testPrefix, testTimeout, releaseDiffTest)
9595
terraformLoggingParameters(environmentVariables, providerName)
9696
terraformCoreBinaryTesting()
9797
terraformShouldPanicForSchemaErrors()
@@ -124,4 +124,4 @@ class PackageDetails(private val packageName: String, private val displayName: S
124124
var id = "%s_%s_PACKAGE_%s".format(this.parentProjectName, this.providerName, this.packageName)
125125
return replaceCharsId(id)
126126
}
127-
}
127+
}

.teamcity/components/builds/build_configuration_sweepers.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class SweeperDetails(private val sweeperName: String, private val parentProjectN
6161
// These hardcoded values affect the sweeper CLI command's behaviour
6262
val testPrefix = "TestAcc"
6363
val testTimeout = "12"
64+
val releaseDiffTest = "false"
6465

6566
return BuildType {
6667

@@ -97,7 +98,7 @@ class SweeperDetails(private val sweeperName: String, private val parentProjectN
9798

9899
params {
99100
configureGoogleSpecificTestParameters(environmentVariables)
100-
acceptanceTestBuildParams(parallelism, testPrefix, testTimeout)
101+
acceptanceTestBuildParams(parallelism, testPrefix, testTimeout, releaseDiffTest)
101102
sweeperParameters(sweeperRegions, sweeperRun)
102103
terraformLoggingParameters(environmentVariables, providerName)
103104
terraformCoreBinaryTesting()
@@ -131,4 +132,4 @@ class SweeperDetails(private val sweeperName: String, private val parentProjectN
131132
var id = "%s_%s".format(this.parentProjectName, this.sweeperName)
132133
return replaceCharsId(id)
133134
}
134-
}
135+
}

.teamcity/components/builds/build_configuration_vcr_recording.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class VcrDetails(private val providerName: String, private val buildId: String,
2727
val testTimeout = "12"
2828
val parallelism = DefaultParallelism
2929
val buildTimeout: Int = DefaultBuildTimeoutDuration
30+
val releaseDiffTest = "false"
3031

3132
// Path is just ./google(-beta) here, whereas nightly test builds use paths like ./google/something/specific
3233
// This helps VCR testing builds to run tests across multiple packages
@@ -70,7 +71,7 @@ class VcrDetails(private val providerName: String, private val buildId: String,
7071
params {
7172
configureGoogleSpecificTestParameters(environmentVariables)
7273
vcrEnvironmentVariables(environmentVariables, providerName)
73-
acceptanceTestBuildParams(parallelism, testPrefix, testTimeout)
74+
acceptanceTestBuildParams(parallelism, testPrefix, testTimeout, releaseDiffTest)
7475
terraformLoggingParameters(environmentVariables, providerName)
7576
terraformCoreBinaryTesting()
7677
terraformShouldPanicForSchemaErrors()

.teamcity/components/builds/build_parameters.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,12 @@ fun ParametrizedWithType.configureGoogleSpecificTestParameters(config: AccTestCo
205205

206206
// ParametrizedWithType.acceptanceTestBuildParams sets build params that affect how commands to run
207207
// acceptance tests are templated
208-
fun ParametrizedWithType.acceptanceTestBuildParams(parallelism: Int, prefix: String, timeout: String) {
208+
fun ParametrizedWithType.acceptanceTestBuildParams(parallelism: Int, prefix: String, timeout: String, releaseDiffTest: String) {
209209
hiddenVariable("env.TF_ACC", "1", "Set to a value to run the Acceptance Tests")
210210
text("PARALLELISM", "%d".format(parallelism))
211211
text("TEST_PREFIX", prefix)
212212
text("TIMEOUT", timeout)
213+
text("RELEASE_DIFF", "true")
213214
}
214215

215216
// ParametrizedWithType.sweeperParameters sets build parameters that affect how sweepers are run
@@ -301,4 +302,4 @@ fun ParametrizedWithType.hiddenVariable(name: String, value: String, description
301302

302303
fun ParametrizedWithType.hiddenPasswordVariable(name: String, value: String, description: String) {
303304
password(name, value, "", description, ParameterDisplay.HIDDEN)
304-
}
305+
}

.teamcity/components/constants.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// Provider name that matches the name in the Registry
99
const val ProviderNameGa = "google"
1010
const val ProviderNameBeta = "google-beta"
11+
const val ProviderNameBetaDiffTest = "google-beta-diff-test"
1112

1213
// specifies the default hour (UTC) at which tests should be triggered, if enabled
1314
const val DefaultStartHour = 4
@@ -42,10 +43,11 @@ const val ServiceSweeperCronName = "$ServiceSweeperName - Cron"
4243
const val ServiceSweeperManualName = "$ServiceSweeperName - Manual"
4344
const val ProjectSweeperName = "Project Sweeper"
4445
const val NightlyTestsProjectId = "NightlyTests"
46+
const val WeeklyDiffTestsProjectId = "WeeklyDiffTests"
4547
const val MMUpstreamProjectId = "MMUpstreamTests"
4648
const val VcrRecordingProjectId = "VCRRecording"
4749

4850
// Artifact rules controls which artifacts are uploaded to S3
4951
// https://www.jetbrains.com/help/teamcity/2024.07/configuring-general-settings.html#Artifact+Paths
5052
// The value below lacks a file extension, to allow upload of individual .txt files or a single .tar.gz file
51-
const val ArtifactRules = "%teamcity.build.checkoutDir%/debug*"
53+
const val ArtifactRules = "%teamcity.build.checkoutDir%/debug*"

.teamcity/components/projects/google_beta_subproject.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import builds.*
1212
import jetbrains.buildServer.configs.kotlin.Project
1313
import projects.reused.mmUpstream
1414
import projects.reused.nightlyTests
15+
import projects.reused.weeklyDiffTests
1516
import projects.reused.vcrRecording
1617
import replaceCharsId
1718
import vcs_roots.HashiCorpVCSRootBeta
@@ -41,6 +42,9 @@ fun googleSubProjectBeta(allConfig: AllContextParameters): Project {
4142
// This is only present for the Beta provider, as only TPGB VCR recordings are used.
4243
subProject(vcrRecording(betaId, ProviderNameBeta, HashiCorpVCSRootBeta, ModularMagicianVCSRootBeta, vcrConfig))
4344

45+
// Beta Diff Test project that uses hashicorp/terraform-provider-google-beta-diff-test
46+
subProject(weeklyDiffTests(betaId + "_DIFF_TEST", ProviderNameBeta, HashiCorpVCSRootBeta, betaConfig, NightlyTriggerConfiguration(daysOfWeek = "SAT", nightlyTestsEnabled = false)))
47+
4448
params {
4549
readOnlySettings()
4650
}

.teamcity/components/projects/reused/nightly_tests.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package projects.reused
1010
import NightlyTestsProjectId
1111
import ProviderNameBeta
1212
import ProviderNameGa
13+
import ProviderNameBetaDiffTest
1314
import ServiceSweeperName
1415
import SharedResourceNameBeta
1516
import SharedResourceNameGa
@@ -32,6 +33,7 @@ fun nightlyTests(parentProject:String, providerName: String, vcsRoot: GitVcsRoot
3233
when(providerName) {
3334
ProviderNameGa -> sharedResources = arrayListOf(SharedResourceNameGa)
3435
ProviderNameBeta -> sharedResources = arrayListOf(SharedResourceNameBeta)
36+
ProviderNameBetaDiffTest -> sharedResources = arrayListOf(SharedResourceNameBeta)
3537
else -> throw Exception("Provider name not supplied when generating a nightly test subproject")
3638
}
3739

@@ -48,6 +50,7 @@ fun nightlyTests(parentProject:String, providerName: String, vcsRoot: GitVcsRoot
4850
when(providerName) {
4951
ProviderNameGa -> sweepersList = SweepersListGa
5052
ProviderNameBeta -> sweepersList = SweepersListBeta
53+
ProviderNameBetaDiffTest -> sweepersList = SweepersListBeta
5154
else -> throw Exception("Provider name not supplied when generating a nightly test subproject")
5255
}
5356
val serviceSweeperConfig = BuildConfigurationForServiceSweeper(providerName, ServiceSweeperName, sweepersList, projectId, vcsRoot, sharedResources, config)
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright (c) HashiCorp, Inc.
3+
* SPDX-License-Identifier: MPL-2.0
4+
*/
5+
6+
// This file is maintained in the GoogleCloudPlatform/magic-modules repository and copied into the downstream provider repositories. Any changes to this file in the downstream will be overwritten.
7+
8+
package projects.reused
9+
10+
import NightlyTestsProjectId
11+
import ProviderNameGa
12+
import ProviderNameBeta
13+
import ServiceSweeperName
14+
import SharedResourceNameBeta
15+
import SharedResourceNameGa
16+
import builds.*
17+
import generated.SweepersListBeta
18+
import generated.SweepersListGa
19+
import jetbrains.buildServer.configs.kotlin.Project
20+
import jetbrains.buildServer.configs.kotlin.vcs.GitVcsRoot
21+
import replaceCharsId
22+
23+
fun weeklyDiffTests(parentProject:String, providerName: String, vcsRoot: GitVcsRoot, config: AccTestConfiguration, cron: NightlyTriggerConfiguration): Project {
24+
25+
var projectId = "${parentProject}_${NightlyTestsProjectId}"
26+
projectId = replaceCharsId(projectId)
27+
28+
// Nightly test projects run all acceptance tests overnight
29+
// Here we ensure the project uses the appropriate Shared Resource to ensure no clashes between builds and/or sweepers
30+
var sharedResources: ArrayList<String>
31+
when(providerName) {
32+
ProviderNameGa -> sharedResources = arrayListOf(SharedResourceNameGa)
33+
ProviderNameBeta -> sharedResources = arrayListOf(SharedResourceNameBeta)
34+
else -> throw Exception("Provider name not supplied when generating a weekly diff test subproject")
35+
}
36+
37+
// Create build configs to run acceptance tests for each package defined in packages.kt and services.kt files
38+
// and add cron trigger to them all
39+
val allPackages = getAllPackageInProviderVersion(providerName)
40+
val packageBuildConfigs = BuildConfigurationsForPackages(allPackages, providerName, projectId, vcsRoot, sharedResources, config, releaseDiffTest = "true")
41+
packageBuildConfigs.forEach { buildConfiguration ->
42+
buildConfiguration.addTrigger(cron)
43+
}
44+
45+
// Create build config for sweeping the nightly test project
46+
var sweepersList: Map<String,Map<String,String>>
47+
when(providerName) {
48+
ProviderNameGa -> sweepersList = SweepersListGa
49+
ProviderNameBeta -> sweepersList = SweepersListBeta
50+
else -> throw Exception("Provider name not supplied when generating a weekly diff test subproject")
51+
}
52+
val serviceSweeperConfig = BuildConfigurationForServiceSweeper(providerName, ServiceSweeperName, sweepersList, projectId, vcsRoot, sharedResources, config)
53+
val sweeperCron = cron.clone()
54+
sweeperCron.startHour += 5 // Ensure triggered after the package test builds are triggered
55+
serviceSweeperConfig.addTrigger(sweeperCron)
56+
57+
return Project {
58+
id(projectId)
59+
name = "Weekly Diff Tests"
60+
description = "A project connected to the hashicorp/terraform-provider-${providerName} repository, where scheduled weekly diff tests run and users can trigger ad-hoc builds"
61+
62+
// Register build configs in the project
63+
packageBuildConfigs.forEach { buildConfiguration ->
64+
buildType(buildConfiguration)
65+
}
66+
buildType(serviceSweeperConfig)
67+
68+
params{
69+
configureGoogleSpecificTestParameters(config)
70+
}
71+
}
72+
}

.teamcity/tests/test_utils.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import org.junit.Assert.fail
1515
const val gaProjectName = "Google"
1616
const val betaProjectName = "Google Beta"
1717
const val nightlyTestsProjectName = "Nightly Tests"
18+
const val weeklyDiffTestsProjectName = "Weekly Diff Tests"
1819
const val mmUpstreamProjectName = "Upstream MM Testing"
1920
const val projectSweeperProjectName = "Project Sweeper"
2021

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) HashiCorp, Inc.
3+
* SPDX-License-Identifier: MPL-2.0
4+
*/
5+
6+
// This file is maintained in the GoogleCloudPlatform/magic-modules repository and copied into the downstream provider repositories. Any changes to this file in the downstream will be overwritten.
7+
8+
package tests
9+
10+
import jetbrains.buildServer.configs.kotlin.triggers.ScheduleTrigger
11+
import org.junit.Assert.assertTrue
12+
import org.junit.Test
13+
import projects.googleCloudRootProject
14+
15+
class WeeklyDiffTestProjectsTests {
16+
@Test
17+
fun allBuildsShouldHaveTrigger() {
18+
val root = googleCloudRootProject(testContextParameters())
19+
20+
// Find GA nightly test project
21+
// var gaNightlyTestProject = getNestedProjectFromRoot(root, gaProjectName, weeklyDiffTestsProjectName)
22+
23+
// Find Beta nightly test project
24+
var betaWeeklyDiffTestProject = getNestedProjectFromRoot(root, betaProjectName, weeklyDiffTestsProjectName)
25+
26+
// Make assertions about builds in both weekly diff test projects
27+
(betaWeeklyDiffTestProject.buildTypes).forEach{bt ->
28+
assertTrue("Build configuration `${bt.name}` should contain at least one trigger", bt.triggers.items.isNotEmpty())
29+
// Look for at least one CRON trigger
30+
var found: Boolean = false
31+
lateinit var schedulingTrigger: ScheduleTrigger
32+
for (item in bt.triggers.items){
33+
if (item.type == "schedulingTrigger") {
34+
schedulingTrigger = item as ScheduleTrigger
35+
found = true
36+
break
37+
}
38+
}
39+
40+
assertTrue("Build configuration `${bt.name}` should contain a CRON/'schedulingTrigger' trigger", found)
41+
42+
// Check that weekly diff test is being ran on the nightly-test branch
43+
var isNightlyTestBranch: Boolean = false
44+
if (schedulingTrigger.branchFilter == "+:refs/heads/nightly-test"){
45+
isNightlyTestBranch = true
46+
}
47+
assertTrue("Build configuration `${bt.name}` is using the nightly-test branch filter;", isNightlyTestBranch)
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)