Skip to content

Commit

Permalink
TeamCity: add testing on multiple platforms
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Obexer <[email protected]>
  • Loading branch information
cobexer committed Sep 5, 2024
1 parent d995874 commit 3e5e319
Show file tree
Hide file tree
Showing 9 changed files with 335 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .teamcity/settings.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ To debug in IntelliJ Idea, open the 'Maven Projects' tool window (View
version = "2024.03"

project {
buildType(BuildFileEvents)
FileEventsProject(this)
}
2 changes: 1 addition & 1 deletion .teamcity/src/main/kotlin/FileEventsBaseBuildType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import jetbrains.buildServer.configs.kotlin.buildFeatures.commitStatusPublisher
import jetbrains.buildServer.configs.kotlin.buildFeatures.freeDiskSpace

open class FileEventsBaseBuildType(
init: BuildType.() -> Unit,
val init: BuildType.() -> Unit,
): BuildType({
params {
param("env.DEVELOCITY_ACCESS_KEY", "%ge.gradle.org.access.key%")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@

import jetbrains.buildServer.configs.kotlin.buildSteps.gradle

object BuildFileEvents : FileEventsBaseBuildType({
class FileEventsBuild : FileEventsBaseBuildType({
name = "Build File Events"

artifactRules = """
build/reports/** => file-events/reports
build-logic/build/reports/** => build-logic/reports
build/libs => repo
""".trimIndent()

params {
param("env.PGP_SIGNING_KEY", "%pgpSigningKey%")
param("env.PGP_SIGNING_KEY_PASSPHRASE", "%pgpSigningPassphrase%")

param("env.GRADLE_INTERNAL_REPO_URL", "%gradle.internal.repository.url%")
param("env.JAVA_HOME", "%macos.java17.openjdk.aarch64%")

}

steps {
Expand All @@ -40,8 +39,5 @@ object BuildFileEvents : FileEventsBaseBuildType({
}
}

requirements {
contains("teamcity.agent.jvm.os.name", "Mac OS X")
contains("teamcity.agent.jvm.os.arch", "aarch64")
}
runOn(Agent.MacOsAarch64, 17)
})
30 changes: 30 additions & 0 deletions .teamcity/src/main/kotlin/FileEventsProject.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import jetbrains.buildServer.configs.kotlin.Project

@SuppressWarnings("unused") // actually used in .teamcity/settings.kts
class FileEventsProject(project: Project) {
init {
val build = FileEventsBuild()
val tests = FileEventsTestProject(build)

project.buildType(build)
project.subProject(tests)
project.buildType(tests.trigger)
FileEventsPublish(build, tests.trigger)
}
}
63 changes: 63 additions & 0 deletions .teamcity/src/main/kotlin/FileEventsPublish.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright 2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import jetbrains.buildServer.configs.kotlin.FailureAction
import jetbrains.buildServer.configs.kotlin.ParameterDisplay
import jetbrains.buildServer.configs.kotlin.buildSteps.gradle

class FileEventsPublish(build: FileEventsBuild, tests: FileEventsTestTrigger) : FileEventsBaseBuildType({
name = "Publish File Events"
type = Type.DEPLOYMENT

artifactRules = """
build/reports/** => file-events/reports
build-logic/build/reports/** => build-logic/reports
""".trimIndent()

params {
param("env.GRADLE_INTERNAL_REPO_URL", "%gradle.internal.repository.url%")
param("ARTIFACTORY_USERNAME", "%gradle.internal.repository.build-tool.publish.username%")
password("ARTIFACTORY_PASSWORD", "gradle.internal.repository.build-tool.publish.password%", display = ParameterDisplay.HIDDEN)
param("env.ORG_GRADLE_PROJECT_publishApiKey", "%ARTIFACTORY_PASSWORD%")
param("env.ORG_GRADLE_PROJECT_publishUserName", "%ARTIFACTORY_USERNAME%")
}

steps {
gradle {
name = "Gradle publish"
tasks = "publish"
}
}

dependencies {
snapshot(build) {
onDependencyFailure = FailureAction.FAIL_TO_START
onDependencyCancel = FailureAction.FAIL_TO_START
}
dependency(build) {
artifacts {
cleanDestination = true
artifactRules = "repo => build/remote/"
}
}
snapshot(tests) {
onDependencyFailure = FailureAction.FAIL_TO_START
onDependencyCancel = FailureAction.FAIL_TO_START
}
}

runOn(Agent.MacOsAarch64, 17)
})
57 changes: 57 additions & 0 deletions .teamcity/src/main/kotlin/FileEventsTestProject.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import jetbrains.buildServer.configs.kotlin.FailureAction
import jetbrains.buildServer.configs.kotlin.Project
import jetbrains.buildServer.configs.kotlin.RelativeId
import jetbrains.buildServer.configs.kotlin.buildSteps.gradle
import jetbrains.buildServer.configs.kotlin.ui.id

class FileEventsTestProject(build: FileEventsBuild) : Project({
name = "Test File Events"
id(RelativeId("Test"))

Agent.entries.forEach { agent ->
buildType(FileEventsBaseBuildType {
name = "Test on $agent"
id = RelativeId("Test$agent")

runOn(agent, 17)

steps {
gradle {
name = "Gradle externalTest"
tasks = "externalTest"
}
}

dependencies {
snapshot(build) {
onDependencyFailure = FailureAction.FAIL_TO_START
onDependencyCancel = FailureAction.FAIL_TO_START
}
dependency(build) {
artifacts {
cleanDestination = true
artifactRules = "repo => build/remote/"
}
}
}
})
}
}) {
val trigger = FileEventsTestTrigger(this.buildTypes)
}
55 changes: 55 additions & 0 deletions .teamcity/src/main/kotlin/FileEventsTestTrigger.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import jetbrains.buildServer.configs.kotlin.BuildType
import jetbrains.buildServer.configs.kotlin.FailureAction
import jetbrains.buildServer.configs.kotlin.buildFeatures.PullRequests
import jetbrains.buildServer.configs.kotlin.buildFeatures.pullRequests
import jetbrains.buildServer.configs.kotlin.triggers.vcs

class FileEventsTestTrigger(dependencies: List<BuildType>) : FileEventsBaseBuildType({
name = "Test File Events (Trigger)"
type = Type.COMPOSITE

triggers {
vcs {
branchFilter = """
+:refs/heads/(*)
-:pull/*
""".trimIndent()
}
}

features {
pullRequests {
provider = github {
authType = vcsRoot()
filterTargetBranch = "main"
filterAuthorRole = PullRequests.GitHubRoleFilter.MEMBER
ignoreDrafts = true
}
}
}

dependencies {
dependencies.forEach {
snapshot(it) {
onDependencyFailure = FailureAction.ADD_PROBLEM
onDependencyCancel = FailureAction.FAIL_TO_START
}
}
}
})
92 changes: 92 additions & 0 deletions .teamcity/src/main/kotlin/Platform.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright 2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import jetbrains.buildServer.configs.kotlin.Requirements

enum class Agent(val os: Os, val architecture: Architecture) {
UbuntuAmd64(os = Os.Ubuntu16, architecture = Architecture.Amd64),
UbuntuAarch64(os = Os.Ubuntu24, architecture = Architecture.Aarch64),
AmazonLinuxAmd64(os = Os.AmazonLinux, architecture = Architecture.Amd64),
AmazonLinuxAarch64(os = Os.AmazonLinux, architecture = Architecture.Aarch64),
CentOsAmd64(os = Os.CentOs, architecture = Architecture.Amd64),
FreeBsdAmd64(os = Os.FreeBsd, architecture = Architecture.Amd64),
WindowsAmd64(os = Os.Windows, architecture = Architecture.Amd64),
MacOsAmd64(os = Os.MacOs, architecture = Architecture.Amd64),
MacOsAarch64(os = Os.MacOs, architecture = Architecture.Aarch64),
}

interface Os {
fun addAgentRequirements(requirements: Requirements)
val osType: String

object Ubuntu16 : Ubuntu(16)

object Ubuntu24 : Ubuntu(24)

object AmazonLinux : Linux() {
override fun Requirements.additionalRequirements() {
contains(osDistributionNameParameter, "amazon")
}
}

object CentOs : Linux() {
override fun Requirements.additionalRequirements() {
contains(osDistributionNameParameter, "centos")
contains(osDistributionVersionParameter, "9")
}
}

object MacOs : OsWithNameRequirement("Mac OS X", "MacOs")

object Windows : OsWithNameRequirement("Windows", "Windows")

object FreeBsd : OsWithNameRequirement("FreeBSD", "FreeBsd")
}

private const val osDistributionNameParameter = "system.agent.os.distribution.name"
private const val osDistributionVersionParameter = "system.agent.os.distribution.version"

abstract class OsWithNameRequirement(private val osName: String, override val osType: String) : Os {
override fun addAgentRequirements(requirements: Requirements) {
requirements.contains("teamcity.agent.jvm.os.name", osName)
requirements.additionalRequirements()
}

open fun Requirements.additionalRequirements() {}
}

abstract class Linux : OsWithNameRequirement("Linux", "Linux")

abstract class Ubuntu(val version: Int) : Linux() {
override fun Requirements.additionalRequirements() {
contains(osDistributionNameParameter, "ubuntu")
contains(osDistributionVersionParameter, version.toString())
}
}

enum class Architecture(val paramName: String) {
Aarch64("aarch64") {
override fun agentRequirementForOs(os: Os): String = "aarch64"
},
Amd64("64bit") {
override fun agentRequirementForOs(os: Os): String = when (os) {
Os.MacOs -> "x86_64"
else -> "amd64"
}
};

abstract fun agentRequirementForOs(os: Os): String
}
33 changes: 33 additions & 0 deletions .teamcity/src/main/kotlin/extensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import jetbrains.buildServer.configs.kotlin.BuildType
import jetbrains.buildServer.configs.kotlin.Requirements

fun Requirements.requireAgent(agent: Agent) {
agent.os.addAgentRequirements(this)
contains("teamcity.agent.jvm.os.arch", agent.architecture.agentRequirementForOs(agent.os))
}

fun BuildType.runOn(agent: Agent, javaVersion: Int) {
params {
param("env.JAVA_HOME", "%${agent.os.osType.lowercase()}.java${javaVersion}.openjdk.${agent.architecture.paramName}%")
}

requirements {
requireAgent(agent)
}
}

0 comments on commit 3e5e319

Please sign in to comment.