-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4313 from JetBrains/ktl-1516-migration-ga-in-search
KTL-1516: migration ga in search
- Loading branch information
Showing
5 changed files
with
149 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,58 @@ | ||
package builds.kotlinlang.buidTypes | ||
|
||
import jetbrains.buildServer.configs.kotlin.AbsoluteId | ||
import jetbrains.buildServer.configs.kotlin.BuildType | ||
import jetbrains.buildServer.configs.kotlin.buildSteps.ScriptBuildStep | ||
import jetbrains.buildServer.configs.kotlin.buildSteps.script | ||
import jetbrains.buildServer.configs.kotlin.triggers.finishBuildTrigger | ||
import java.io.File | ||
import java.nio.file.Paths | ||
|
||
private fun readScript(name: String): String { | ||
val file = File(Paths.get("scripts/$name.mjs").toAbsolutePath().toString()) | ||
return file.readText() | ||
} | ||
|
||
private val pageViewsCollectId = AbsoluteId("WebTeam_BuildsForDeploymentJetBrainsCom_Algolia_PageViewsFromGoogle") | ||
|
||
object PageViews : BuildType({ | ||
name = "Fetch Page Views" | ||
description = "Build data files with page views statistics for kotlin websites" | ||
|
||
artifactRules = """ | ||
page_views_list.json | ||
page_views_map.json | ||
""".trimIndent() | ||
|
||
triggers { | ||
finishBuildTrigger { | ||
buildType = pageViewsCollectId.absoluteId | ||
branchFilter = "+:<default>" | ||
successfulOnly = true | ||
} | ||
} | ||
|
||
steps { | ||
script { | ||
name = "Prepare page views" | ||
scriptContent = """ | ||
#!/usr/bin/env bash | ||
":" //# comment; exec /usr/bin/env node --input-type=module - "${'$'}@" < "${'$'}0" | ||
${readScript("stats/pageviews")} | ||
""".trimIndent() | ||
dockerImage = "node:lts-slim" | ||
dockerImagePlatform = ScriptBuildStep.ImagePlatform.Linux | ||
dockerPull = true | ||
} | ||
} | ||
|
||
dependencies { | ||
artifacts(pageViewsCollectId) { | ||
buildRule = lastSuccessful() | ||
artifactRules = """ | ||
+:unique_pageviews_pages_000000000000.json => data | ||
""".trimIndent() | ||
} | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { open } from 'node:fs/promises'; | ||
|
||
const INPUT_FILE_PATH = 'data/unique_pageviews_pages_000000000000.json'; | ||
const input = await open(INPUT_FILE_PATH, 'r'); | ||
|
||
async function openReportFile(name) { | ||
const file = await open(name, 'w'); | ||
await file.truncate(0); | ||
return file; | ||
} | ||
|
||
const [listViews, mapViews] = await Promise.all([ | ||
openReportFile('page_views_list.json'), | ||
openReportFile('page_views_map.json'), | ||
]); | ||
|
||
try { | ||
async function append(line) { | ||
const { webpage: url, unique_pageviews: views } = JSON.parse(line); | ||
|
||
const pageviews = Number(views); | ||
|
||
if (views === '' || isNaN(pageviews)) { | ||
console.warn(`${url} has incorrect unique_pageviews=${views}`); | ||
return; | ||
} | ||
|
||
if (pageviews < 1) return; | ||
if (!(new URL(url).host.includes('kotlinlang.org'))) return; | ||
|
||
await Promise.all([ | ||
listViews.appendFile(JSON.stringify({ url, pageviews }) + ','), | ||
mapViews.appendFile(`${JSON.stringify(url)}: ${pageviews},`), | ||
]); | ||
} | ||
|
||
const lines = []; | ||
|
||
await Promise.all([ | ||
listViews.write('['), | ||
mapViews.write('{'), | ||
]); | ||
|
||
const readlineInterface = input.readLines(); | ||
|
||
readlineInterface.on('line', line => { | ||
lines.push(append(line)); | ||
}); | ||
|
||
const waitInputRead = new Promise(resolve => { | ||
readlineInterface.on('close', () => { | ||
resolve(); | ||
}); | ||
}); | ||
|
||
await waitInputRead; | ||
await Promise.all(lines); | ||
|
||
async function replaceLastCharacter(file, ch) { | ||
const { size } = await file.stat(); | ||
file.write(ch, size - 1); | ||
} | ||
|
||
await Promise.all([ | ||
replaceLastCharacter(listViews, ']'), | ||
replaceLastCharacter(mapViews, '}'), | ||
]); | ||
} finally { | ||
await Promise.all([ | ||
input.close(), | ||
listViews.close(), | ||
mapViews.close(), | ||
]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters