|
| 1 | +/* |
| 2 | + * Copyright 2019-2025 JetBrains s.r.o. and contributors. |
| 3 | + * Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file. |
| 4 | + */ |
| 5 | + |
| 6 | +import jetbrains.buildServer.configs.kotlin.* |
| 7 | +import jetbrains.buildServer.configs.kotlin.buildSteps.* |
| 8 | +import jetbrains.buildServer.configs.kotlin.triggers.finishBuildTrigger |
| 9 | + |
| 10 | +fun deploymentProject() = Project { |
| 11 | + this.id("Deployment") |
| 12 | + this.name = "Deployment" |
| 13 | + |
| 14 | + params { |
| 15 | + param("teamcity.ui.settings.readOnly", "true") |
| 16 | + } |
| 17 | + |
| 18 | + val startDeploymentTask = startDeployment() |
| 19 | + |
| 20 | + val copyToCentralTask = copyToCentral(startDeploymentTask) |
| 21 | + val copyZoneInfoTask = copyZoneInfoToCentral(startDeploymentTask) |
| 22 | + |
| 23 | + val deployTasks = buildList { |
| 24 | + Platform.entries.forEach { |
| 25 | + add(deployToCentral(it, startDeploymentTask)) |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | + deployTasks.forEach { deploy -> |
| 30 | + copyToCentralTask.dependsOnSnapshot(deploy, onFailure = FailureAction.CANCEL) |
| 31 | + copyZoneInfoTask.dependsOnSnapshot(deploy, onFailure = FailureAction.CANCEL) |
| 32 | + } |
| 33 | + |
| 34 | + buildTypesOrder = listOf(startDeploymentTask, *deployTasks.toTypedArray()) + listOf(copyToCentralTask, copyZoneInfoTask) |
| 35 | +} |
| 36 | + |
| 37 | +fun Project.startDeployment() = BuildType { |
| 38 | + id("StartDeployment") |
| 39 | + this.name = "Start Deployment [RUN THIS ONE]" |
| 40 | + type = BuildTypeSettings.Type.DEPLOYMENT |
| 41 | + |
| 42 | + params { |
| 43 | + text( |
| 44 | + "Version", |
| 45 | + "", |
| 46 | + display = ParameterDisplay.PROMPT, |
| 47 | + allowEmpty = false |
| 48 | + ) |
| 49 | + text( |
| 50 | + "VersionSuffix", |
| 51 | + "", |
| 52 | + display = ParameterDisplay.PROMPT |
| 53 | + ) |
| 54 | + select( |
| 55 | + "Repository", |
| 56 | + "central", |
| 57 | + options = listOf("central", "sonatype"), |
| 58 | + display = ParameterDisplay.PROMPT |
| 59 | + ) |
| 60 | + text( |
| 61 | + "ZoneInfoVersion", |
| 62 | + "", |
| 63 | + display = ParameterDisplay.HIDDEN |
| 64 | + ) |
| 65 | + } |
| 66 | + |
| 67 | + steps { |
| 68 | + gradle { |
| 69 | + name = "Get ZoneInfoVersion" |
| 70 | + jdkHome = "%env.$jdk%" |
| 71 | + jvmArgs = "-Xmx1g" |
| 72 | + gradleParams = |
| 73 | + "--info --stacktrace -P$versionSuffixParameter=%VersionSuffix% -P$releaseVersionParameter=%Version% -Pzoneinfo.version.tc.parameter=ZoneInfoVersion" |
| 74 | + tasks = ":kotlinx-datetime-zoneinfo:setZoneInfoVersionToTeamcity" |
| 75 | + buildFile = "" |
| 76 | + gradleWrapperPath = "" |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + commonConfigure() |
| 81 | +}.also { buildType(it) } |
| 82 | + |
| 83 | +fun Project.deployToCentral(platform: Platform, startDeployment: BuildType) = buildType("DeployCentral", platform) { |
| 84 | + type = BuildTypeSettings.Type.DEPLOYMENT |
| 85 | + enablePersonalBuilds = false |
| 86 | + maxRunningBuilds = 1 |
| 87 | + params { |
| 88 | + param(versionSuffixParameter, "${startDeployment.depParamRefs["VersionSuffix"]}") |
| 89 | + param(releaseVersionParameter, "${startDeployment.depParamRefs["Version"]}") |
| 90 | + param("system.publication_repository", "${startDeployment.depParamRefs["Repository"]}") |
| 91 | + } |
| 92 | + |
| 93 | + vcs { |
| 94 | + cleanCheckout = true |
| 95 | + } |
| 96 | + |
| 97 | + val taskNames = buildList { |
| 98 | + add("clean") |
| 99 | + when (platform) { |
| 100 | + Platform.Linux -> { |
| 101 | + addAll( |
| 102 | + listOf( |
| 103 | + "publishAndroidNativeArm32PublicationToCentralRepository", |
| 104 | + "publishAndroidNativeArm64PublicationToCentralRepository", |
| 105 | + "publishAndroidNativeX64PublicationToCentralRepository", |
| 106 | + "publishAndroidNativeX86PublicationToCentralRepository", |
| 107 | + "publishLinuxArm64PublicationToCentralRepository", |
| 108 | + "publishLinuxX64PublicationToCentralRepository" |
| 109 | + ) |
| 110 | + ) |
| 111 | + } |
| 112 | + |
| 113 | + Platform.Windows -> { |
| 114 | + add("publishMingwX64PublicationToCentralRepository") |
| 115 | + } |
| 116 | + |
| 117 | + Platform.MacOS -> { |
| 118 | + addAll( |
| 119 | + listOf( |
| 120 | + // metadata |
| 121 | + "publishKotlinMultiplatformPublicationToCentralRepository", |
| 122 | + // web |
| 123 | + "publishJsPublicationToCentralRepository", |
| 124 | + "publishWasmJsPublicationToCentralRepository", |
| 125 | + "publishWasmWasiPublicationToCentralRepository", |
| 126 | + // jvm |
| 127 | + "publishJvmPublicationToCentralRepository", |
| 128 | + // native |
| 129 | + "publishIosArm64PublicationToCentralRepository", |
| 130 | + "publishIosSimulatorArm64PublicationToCentralRepository", |
| 131 | + "publishIosX64PublicationToCentralRepository", |
| 132 | + "publishMacosArm64PublicationToCentralRepository", |
| 133 | + "publishMacosX64PublicationToCentralRepository", |
| 134 | + "publishTvosArm64PublicationToCentralRepository", |
| 135 | + "publishTvosSimulatorArm64PublicationToCentralRepository", |
| 136 | + "publishTvosX64PublicationToCentralRepository", |
| 137 | + "publishWatchosArm32PublicationToCentralRepository", |
| 138 | + "publishWatchosArm64PublicationToCentralRepository", |
| 139 | + "publishWatchosDeviceArm64PublicationToCentralRepository", |
| 140 | + "publishWatchosSimulatorArm64PublicationToCentralRepository", |
| 141 | + "publishWatchosX64PublicationToCentralRepository" |
| 142 | + ) |
| 143 | + ) |
| 144 | + } |
| 145 | + } |
| 146 | + } |
| 147 | + |
| 148 | + steps { |
| 149 | + gradle { |
| 150 | + name = "Deploy ${platform.buildTypeName()} Binaries" |
| 151 | + jdkHome = "%env.$jdk%" |
| 152 | + jvmArgs = "-Xmx1g" |
| 153 | + gradleParams = |
| 154 | + "--info --stacktrace -P$versionSuffixParameter=%$versionSuffixParameter% -P$releaseVersionParameter=%$releaseVersionParameter%" |
| 155 | + tasks = taskNames.joinToString(" ") |
| 156 | + buildFile = "" |
| 157 | + gradleWrapperPath = "" |
| 158 | + } |
| 159 | + } |
| 160 | +}.dependsOnSnapshot(startDeployment) |
| 161 | + |
| 162 | +fun Project.copyToCentral(startDeployment: BuildType) = BuildType { |
| 163 | + id("CopyToCentral") |
| 164 | + this.name = "Deploy To Central" |
| 165 | + type = BuildTypeSettings.Type.DEPLOYMENT |
| 166 | + |
| 167 | + templates(AbsoluteId("KotlinTools_DeployToCentral")) |
| 168 | + |
| 169 | + params { |
| 170 | + param("DeployVersion", startDeployment.depParamRefs["Version"].ref) |
| 171 | + param("ArtifactPrefixes", "[kotlinx-datetime]") |
| 172 | + } |
| 173 | + |
| 174 | + requirements { |
| 175 | + doesNotMatch("teamcity.agent.jvm.os.name", "Windows") |
| 176 | + } |
| 177 | + |
| 178 | + dependsOnSnapshot(startDeployment) |
| 179 | + |
| 180 | + triggers { |
| 181 | + finishBuildTrigger { |
| 182 | + buildType = "${startDeployment.id}" |
| 183 | + successfulOnly = true |
| 184 | + branchFilter = "+:*" |
| 185 | + } |
| 186 | + } |
| 187 | +}.also { buildType(it) } |
| 188 | + |
| 189 | +fun Project.copyZoneInfoToCentral(startDeployment: BuildType) = BuildType { |
| 190 | + id("CopyZoneInfoToCentral") |
| 191 | + this.name = "Deploy ZoneInfo To Central" |
| 192 | + type = BuildTypeSettings.Type.DEPLOYMENT |
| 193 | + |
| 194 | + templates(AbsoluteId("KotlinTools_DeployToCentral")) |
| 195 | + |
| 196 | + params { |
| 197 | + param("DeployVersion", startDeployment.depParamRefs["ZoneInfoVersion"].ref) |
| 198 | + param("ArtifactPrefixes", "[kotlinx-datetime-zoneinfo]") |
| 199 | + } |
| 200 | + |
| 201 | + requirements { |
| 202 | + doesNotMatch("teamcity.agent.jvm.os.name", "Windows") |
| 203 | + } |
| 204 | + |
| 205 | + dependsOnSnapshot(startDeployment) |
| 206 | + |
| 207 | + triggers { |
| 208 | + finishBuildTrigger { |
| 209 | + buildType = "${startDeployment.id}" |
| 210 | + successfulOnly = true |
| 211 | + branchFilter = "+:*" |
| 212 | + } |
| 213 | + } |
| 214 | +}.also { buildType(it) } |
0 commit comments