diff --git a/.teamcity/settings.kts b/.teamcity/settings.kts index cabbc30..d8137b6 100644 --- a/.teamcity/settings.kts +++ b/.teamcity/settings.kts @@ -28,5 +28,5 @@ To debug in IntelliJ Idea, open the 'Maven Projects' tool window (View version = "2024.03" project { - buildType(BuildFileEvents) + FileEventsProject(this) } diff --git a/.teamcity/src/main/kotlin/FileEventsBaseBuildType.kt b/.teamcity/src/main/kotlin/FileEventsBaseBuildType.kt index 58e1be4..be2ce80 100644 --- a/.teamcity/src/main/kotlin/FileEventsBaseBuildType.kt +++ b/.teamcity/src/main/kotlin/FileEventsBaseBuildType.kt @@ -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%") diff --git a/.teamcity/src/main/kotlin/Build.kt b/.teamcity/src/main/kotlin/FileEventsBuild.kt similarity index 82% rename from .teamcity/src/main/kotlin/Build.kt rename to .teamcity/src/main/kotlin/FileEventsBuild.kt index 2f8e2ed..b296e66 100644 --- a/.teamcity/src/main/kotlin/Build.kt +++ b/.teamcity/src/main/kotlin/FileEventsBuild.kt @@ -16,12 +16,13 @@ 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 { @@ -29,8 +30,6 @@ object BuildFileEvents : FileEventsBaseBuildType({ 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 { @@ -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) }) diff --git a/.teamcity/src/main/kotlin/FileEventsProject.kt b/.teamcity/src/main/kotlin/FileEventsProject.kt new file mode 100644 index 0000000..c19c7e5 --- /dev/null +++ b/.teamcity/src/main/kotlin/FileEventsProject.kt @@ -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) + } +} diff --git a/.teamcity/src/main/kotlin/FileEventsPublish.kt b/.teamcity/src/main/kotlin/FileEventsPublish.kt new file mode 100644 index 0000000..6e77cd4 --- /dev/null +++ b/.teamcity/src/main/kotlin/FileEventsPublish.kt @@ -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) +}) diff --git a/.teamcity/src/main/kotlin/FileEventsTestProject.kt b/.teamcity/src/main/kotlin/FileEventsTestProject.kt new file mode 100644 index 0000000..2c3c7fa --- /dev/null +++ b/.teamcity/src/main/kotlin/FileEventsTestProject.kt @@ -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) +} diff --git a/.teamcity/src/main/kotlin/FileEventsTestTrigger.kt b/.teamcity/src/main/kotlin/FileEventsTestTrigger.kt new file mode 100644 index 0000000..75b5018 --- /dev/null +++ b/.teamcity/src/main/kotlin/FileEventsTestTrigger.kt @@ -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) : 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 + } + } + } +}) diff --git a/.teamcity/src/main/kotlin/Platform.kt b/.teamcity/src/main/kotlin/Platform.kt new file mode 100644 index 0000000..be8af25 --- /dev/null +++ b/.teamcity/src/main/kotlin/Platform.kt @@ -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 +} diff --git a/.teamcity/src/main/kotlin/extensions.kt b/.teamcity/src/main/kotlin/extensions.kt new file mode 100644 index 0000000..e945959 --- /dev/null +++ b/.teamcity/src/main/kotlin/extensions.kt @@ -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) + } +}