Skip to content

Commit

Permalink
Merge pull request #4568 from JetBrains/core-api-libs
Browse files Browse the repository at this point in the history
API References: generate sitemap.xml and add  for sitemap_index.xml for libraries
  • Loading branch information
zoobestik authored Nov 22, 2024
2 parents 15f69e1 + 4f6a8c2 commit 0e38dd3
Show file tree
Hide file tree
Showing 14 changed files with 313 additions and 359 deletions.
9 changes: 9 additions & 0 deletions .teamcity/BuildParams.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,13 @@ object BuildParams {

const val SEARCH_APP_ID = "7961PKYRXV"
const val SEARCH_INDEX_NAME = "prod_KOTLINLANG_WEBHELP"

val API_URLS = listOf(
"api/core",
"api/$KOTLINX_COROUTINES_ID",
"api/$KOTLINX_SERIALIZATION_ID",
"api/$KOTLINX_DATETIME_ID",
"api/$KOTLINX_IO_ID",
"api/$KOTLINX_METADATA_ID",
)
}
49 changes: 28 additions & 21 deletions .teamcity/builds/TemplateSearchIndex.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,29 @@ package builds

import BuildParams.SEARCH_APP_ID
import builds.kotlinlang.buidTypes.PageViews
import jetbrains.buildServer.configs.kotlin.BuildSteps
import jetbrains.buildServer.configs.kotlin.BuildType
import jetbrains.buildServer.configs.kotlin.buildSteps.ScriptBuildStep
import jetbrains.buildServer.configs.kotlin.triggers.schedule
import vcsRoots.KotlinLangOrg

const val SCRIPT_PATH = "scripts/doindex";

fun BuildSteps.scriptDistAnalyze(block: ScriptBuildStep.() -> Unit) = step(
ScriptBuildStep {
name = "Run dist/ analyzer"
//language=bash
scriptContent = """
#!/bin/sh
set -e
npm install
npm run generate-metadata
""".trimIndent()
dockerImage = "node:22-alpine"
workingDir = SCRIPT_PATH
dockerPull = true

block()
}
)
fun scriptDistAnalyze(block: ScriptBuildStep.() -> Unit) = ScriptBuildStep {
id = "script-dist-analyze"
name = "Run dist/ analyzer"
//language=bash
scriptContent = """
#!/bin/sh
set -e
npm install
npm run generate-metadata
""".trimIndent()
dockerImage = "node:22-alpine"
workingDir = SCRIPT_PATH
dockerPull = true
}.apply(block)

open class TemplateSearchIndex(init: BuildType.() -> Unit) : BuildType({
abstract class TemplateSearchIndex(init: BuildType.() -> Unit) : BuildType({
artifactRules = """
reports/** => reports.zip
""".trimIndent()
Expand All @@ -54,8 +51,18 @@ open class TemplateSearchIndex(init: BuildType.() -> Unit) : BuildType({
showDependenciesChanges = true
}

triggers {
schedule {
schedulingPolicy = cron {
hours = "4"
dayOfMonth = "*/2"
}
branchFilter = "+:<default>"
}
}

steps {
scriptDistAnalyze {}
step(scriptDistAnalyze {})
}

dependencies {
Expand All @@ -69,5 +76,5 @@ open class TemplateSearchIndex(init: BuildType.() -> Unit) : BuildType({
}
}

init()
init(this)
})
145 changes: 145 additions & 0 deletions .teamcity/builds/apiReferences/BuildApiPages.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package builds.apiReferences

import BuildParams.DOKKA_TEMPLATES_VERSION
import builds.scriptDistAnalyze
import jetbrains.buildServer.configs.kotlin.BuildStep
import jetbrains.buildServer.configs.kotlin.BuildSteps
import jetbrains.buildServer.configs.kotlin.BuildType
import jetbrains.buildServer.configs.kotlin.buildSteps.GradleBuildStep
import jetbrains.buildServer.configs.kotlin.buildSteps.ScriptBuildStep
import jetbrains.buildServer.configs.kotlin.triggers.VcsTrigger
import jetbrains.buildServer.configs.kotlin.triggers.vcs
import vcsRoots.KotlinLangOrg

const val DEFAULT_DOKKA_PATH = "build/dokka/htmlMultiModule"
private const val DOKKA_SPACE_REPO = "https://maven.pkg.jetbrains.space/kotlin/p/dokka/dev/"

abstract class BuildApiPages(
apiId: String,
releaseTag: String,
pagesRoot: String = DEFAULT_DOKKA_PATH,

stepDropSnapshot: BuildSteps.() -> BuildStep? = { scriptDropSnapshot() },
stepDokkaVersionSync: BuildSteps.() -> BuildStep? = { scriptDokkaVersionSync() },
stepBuildHtml: BuildSteps.() -> BuildStep? = { scriptBuildHtml() },
stepNoRobots: BuildSteps.(pagesRoot: String) -> BuildStep? = { pagesRoot -> scriptNoRobots(pagesRoot) },
stepCopyDokkaApiResult: BuildSteps.(appId: String, pagesRoot: String) -> BuildStep? = { appId, pagesRoot ->
copyDokkaApiResult(appId, pagesRoot)
},
stepSitemapGenerate: BuildSteps.(pagesRoot: String) -> BuildStep? = { pagesRoot ->
scriptGenerateSitemap(pagesRoot)
},

vcsDefaultTrigger: VcsTrigger.() -> Unit = {},
init: BuildType.() -> Unit = {}
) : BuildType({
name = "/api/$apiId pages"
description = "Build pages for /api/$apiId"

artifactRules = "$pagesRoot/** => pages.zip"

vcs {
root(KotlinLangOrg, "scripts/doindex/")
}

params {
param("release.tag", releaseTag)
param("DOKKA_TEMPLATES_VERSION", DOKKA_TEMPLATES_VERSION)
}

triggers {
vcs {
id = "trigger-vcs-default-trigger-id"
branchFilter = "+:<default>"
}.apply(vcsDefaultTrigger)
}

requirements {
doesNotContain("docker.server.osType", "windows")
}

steps {
stepDropSnapshot()?.also { step -> step(step) }
stepDokkaVersionSync()?.also { step -> (step) }
stepBuildHtml()?.also { step -> step(step) }
stepNoRobots(pagesRoot)?.also { step -> step(step) }
stepCopyDokkaApiResult(apiId, pagesRoot)?.also { step -> step(step) }
stepSitemapGenerate(pagesRoot)?.also { step -> step(step) }
}

init(this)
})


fun scriptDokkaVersionSync(init: ScriptBuildStep.() -> Unit = {}): BuildStep = ScriptBuildStep {
id = "step-dokka-version-sync-id"
name = "Sync dokka version with main repository templates"
dockerImage = "debian"
// language=bash
scriptContent = """
#!/bin/bash
sed -i -E "s/^(dokka_version|dokkaVersion)=.+/\1=%DOKKA_TEMPLATES_VERSION%/gi" ./gradle.properties
find . -name "*.gradle.kts" -exec sed -i -E "s|mavenCentral|maven(url = \"$DOKKA_SPACE_REPO\")\nmavenCentral|" {} \;
find . -name "*.gradle" -exec sed -i -E "s|mavenCentral|maven \{ url \"$DOKKA_SPACE_REPO\" \}\nmavenCentral|" {} \;
""".trimIndent()
}.apply(init)

fun scriptDropSnapshot(init: ScriptBuildStep.() -> Unit = {}): BuildStep = ScriptBuildStep {
id = "step-drop-snapshot-id"
name = "Drop SNAPSHOT word for deploy"
dockerImage = "debian"
// language=bash
scriptContent = """
#!/bin/bash
CURRENT_VERSION="$(sed -E s/^v?//g <<<%release.tag%)"
sed -i -E "s/^version=.+(-SNAPSHOT)?/version=${'$'}CURRENT_VERSION/gi" ./gradle.properties
""".trimIndent()
}.apply(init)

fun scriptBuildHtml(init: GradleBuildStep.() -> Unit = {}): BuildStep = GradleBuildStep {
id = "step-build-dokka-html-id"
name = "Build dokka html"
tasks = "dokkaHtmlMultiModule"
useGradleWrapper = true
}.apply(init)

fun copyDokkaApiResult(
apiId: String, pagesRoot: String = DEFAULT_DOKKA_PATH, init: ScriptBuildStep.() -> Unit = {}
): BuildStep = ScriptBuildStep {
val processDir = "dist/api/$apiId"

id = "copy-dokka-api-result"
name = "Copy files to $processDir"
enabled = pagesRoot !== processDir
//language=sh
scriptContent = """
echo "$processDir"
echo "$pagesRoot"
rm -rf "dist/"
mkdir -p "dist/api"
cp -r "$pagesRoot" "$processDir"
ls -la "dist/api"
ls -la "$processDir"
""".trimIndent()
dockerImage = "alpine"
}.apply(init)

fun scriptGenerateSitemap(pagesRoot: String = DEFAULT_DOKKA_PATH): BuildStep = scriptDistAnalyze {
//language=sh
scriptContent += "\n" + """
cd ../../dist
cp ./sitemap.xml "../$pagesRoot/"
""".trimIndent()
}

fun scriptNoRobots(pagesRoot: String, block: ScriptBuildStep.() -> Unit = {}) = ScriptBuildStep {
name = "Add no robots for older versions"
workingDir = pagesRoot
//language=bash
scriptContent = """
#!/bin/sh
find . -type f -path "*/api/*/older/*.html" -exec sed -i -E 's/(<head[^>]*>)/\1<meta name="robots" content="noindex, nofollow">/g' {} \;
""".trimIndent()
dockerImage = "alpine"
}.apply(block)
2 changes: 0 additions & 2 deletions .teamcity/builds/apiReferences/BuildApiReferencesProject.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import builds.apiReferences.kotlinx.serialization.KotlinxSerializationBuildSearc
import builds.apiReferences.kotlinx.serialization.KotlinxSerializationPrepareDokkaTemplates
import builds.apiReferences.stdlib.BuildStdlibApiReference
import builds.apiReferences.stdlib.StdlibPrepareDokkaTemplates
import builds.apiReferences.templates.BuildApiReference
import builds.apiReferences.templates.PrepareDokkaTemplate
import builds.apiReferences.vcsRoots.*
import jetbrains.buildServer.configs.kotlin.Project
Expand Down Expand Up @@ -56,5 +55,4 @@ object BuildApiReferencesProject : Project({
vcsRoot(KotlinMetadataJvm)

template(PrepareDokkaTemplate)
template(BuildApiReference)
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,16 @@ package builds.apiReferences.kotlinx.coroutines

import BuildParams.KOTLINX_COROUTINES_ID
import BuildParams.KOTLINX_COROUTINES_RELEASE_TAG
import builds.apiReferences.BuildApiPages
import builds.apiReferences.dependsOnDokkaTemplate
import builds.apiReferences.stdlib.copyDokkaFiles
import builds.apiReferences.stdlib.sitemapGenerate
import builds.apiReferences.templates.BuildApiReference
import jetbrains.buildServer.configs.kotlin.BuildType
import builds.apiReferences.vcsRoots.KotlinxCoroutines

object KotlinxCoroutinesBuildApiReference : BuildType({
name = "$KOTLINX_COROUTINES_ID pages"
description = "Build pages for Kotlinx Coroutines"

templates(BuildApiReference)

params {
param("release.tag", KOTLINX_COROUTINES_RELEASE_TAG)
}

vcs {
root(builds.apiReferences.vcsRoots.KotlinxCoroutines)
}

dependencies {
dependsOnDokkaTemplate(KotlinxCoroutinesPrepareDokkaTemplates)
}

steps {
copyDokkaFiles(KOTLINX_COROUTINES_ID)
sitemapGenerate(KOTLINX_COROUTINES_ID)
}
})
object KotlinxCoroutinesBuildApiReference : BuildApiPages(
apiId = KOTLINX_COROUTINES_ID, releaseTag = KOTLINX_COROUTINES_RELEASE_TAG, init = {
vcs {
root(KotlinxCoroutines)
}
dependencies {
dependsOnDokkaTemplate(KotlinxCoroutinesPrepareDokkaTemplates)
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,35 @@ package builds.apiReferences.kotlinx.datetime

import BuildParams.KOTLINX_DATETIME_ID
import BuildParams.KOTLINX_DATETIME_RELEASE_TAG
import builds.apiReferences.BuildApiPages
import builds.apiReferences.dependsOnDokkaTemplate
import builds.apiReferences.stdlib.copyDokkaFiles
import builds.apiReferences.stdlib.sitemapGenerate
import builds.apiReferences.templates.BuildApiReference
import builds.apiReferences.templates.buildDokkaHTML
import builds.apiReferences.templates.scriptDropSnapshot
import jetbrains.buildServer.configs.kotlin.BuildType
import builds.apiReferences.scriptBuildHtml
import builds.apiReferences.scriptDropSnapshot
import builds.apiReferences.vcsRoots.KotlinxDatetime

private const val HTML_RESULT = "core/build/dokka/html"
private const val DOKKA_HTML_RESULT = "core/build/dokka/html"

object KotlinxDatetimeBuildApiReference : BuildType({
name = "$KOTLINX_DATETIME_ID pages"
description = "Build pages for Kotlinx Datetime"

templates(BuildApiReference)

artifactRules = "$HTML_RESULT/** => pages.zip"

params {
param("release.tag", KOTLINX_DATETIME_RELEASE_TAG)
}

vcs {
root(builds.apiReferences.vcsRoots.KotlinxDatetime)
}

dependencies {
dependsOnDokkaTemplate(KotlinxDatetimePrepareDokkaTemplates, "core/dokka-templates")
}

steps {
object KotlinxDatetimeBuildApiReference : BuildApiPages(
apiId = KOTLINX_DATETIME_ID,
releaseTag = KOTLINX_DATETIME_RELEASE_TAG,
pagesRoot = DOKKA_HTML_RESULT,
stepDropSnapshot = {
scriptDropSnapshot {
// language=bash
scriptContent = """
#!/bin/bash
sed -i -E "s/versionSuffix=SNAPSHOT//gi" ./gradle.properties
""".trimIndent()
}
buildDokkaHTML {
tasks = ":kotlinx-datetime:dokkaHtml"
},
stepBuildHtml = {
scriptBuildHtml { tasks = ":kotlinx-datetime:dokkaHtml" }
},
init = {
vcs {
root(KotlinxDatetime)
}
dependencies {
dependsOnDokkaTemplate(KotlinxDatetimePrepareDokkaTemplates, "core/dokka-templates")
}
copyDokkaFiles(KOTLINX_DATETIME_ID, HTML_RESULT)
sitemapGenerate(KOTLINX_DATETIME_ID)
}
})
})
Loading

0 comments on commit 0e38dd3

Please sign in to comment.