Skip to content

Commit 03fb1d3

Browse files
authored
ci: add semgrep check (#360)
1 parent 9872463 commit 03fb1d3

File tree

6 files changed

+99
-2
lines changed

6 files changed

+99
-2
lines changed

.teamcity/builds/Build.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class Build(
2222
buildType(WhiteListCheck("${name}-whitelist-check", "white-list check"))
2323
if (forPullRequests) dependentBuildType(PRCheck("${name}-pr-check", "pr check"))
2424
parallel {
25+
dependentBuildType(SemgrepCheck("${name}-semgrep-check", "semgrep check"))
26+
2527
listOf("17", "21").forEach { java ->
2628
dependentBuildType(
2729
Maven(

.teamcity/builds/Common.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ const val MAVEN_DEFAULT_ARGS = "--no-transfer-progress --batch-mode --show-versi
1616
const val DEFAULT_JAVA_VERSION = "17"
1717
const val LTS_JAVA_VERSION = "21"
1818

19+
const val SEMGREP_DOCKER_IMAGE = "semgrep/semgrep:1.146.0"
20+
21+
const val FULL_GITHUB_REPOSITORY = "$GITHUB_OWNER/$GITHUB_REPOSITORY"
22+
const val GITHUB_URL = "https://github.com/$FULL_GITHUB_REPOSITORY"
23+
1924
enum class LinuxSize(val value: String) {
2025
SMALL("small"),
2126
LARGE("large")

.teamcity/builds/Maven.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,25 @@ package builds
22

33
import jetbrains.buildServer.configs.kotlin.BuildType
44
import jetbrains.buildServer.configs.kotlin.buildFeatures.dockerSupport
5+
import jetbrains.buildServer.configs.kotlin.buildSteps.MavenBuildStep
56
import jetbrains.buildServer.configs.kotlin.toId
67

7-
class Maven(
8+
open class Maven(
89
id: String,
910
name: String,
1011
goals: String,
1112
args: String? = null,
1213
javaVersion: String = DEFAULT_JAVA_VERSION,
13-
size: LinuxSize = LinuxSize.SMALL
14+
size: LinuxSize = LinuxSize.SMALL,
15+
mavenVersion: MavenBuildStep.MavenVersion? = null,
1416
) :
1517
BuildType({
1618
this.id(id.toId())
1719
this.name = name
1820

1921
steps {
2022
runMaven(javaVersion) {
23+
this.mavenVersion = mavenVersion
2124
this.goals = goals
2225
this.runnerArgs = "$MAVEN_DEFAULT_ARGS ${args ?: ""}"
2326
}

.teamcity/builds/NightlyBuild.kt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package builds
2+
3+
import jetbrains.buildServer.configs.kotlin.Project
4+
import jetbrains.buildServer.configs.kotlin.sequential
5+
import jetbrains.buildServer.configs.kotlin.toId
6+
import jetbrains.buildServer.configs.kotlin.triggers.schedule
7+
import jetbrains.buildServer.configs.kotlin.triggers.vcs
8+
9+
class NightlyBuild(name: String): Project({
10+
this.id(name.toId())
11+
this.name = name
12+
13+
val complete = Empty("${name}-complete", "complete")
14+
15+
val bts = sequential {
16+
dependentBuildType(SemgrepCheck("${name}-semgrep-check", "semgrep check"))
17+
dependentBuildType(complete)
18+
}
19+
20+
bts.buildTypes().forEach {
21+
it.thisVcs()
22+
23+
it.features {
24+
enableCommitStatusPublisher()
25+
}
26+
27+
buildType(it)
28+
}
29+
30+
complete.triggers {
31+
vcs { enabled = false }
32+
33+
schedule {
34+
branchFilter = buildString {
35+
appendLine("+:main")
36+
appendLine("+:refs/heads/main")
37+
}
38+
schedulingPolicy = daily {
39+
hour = 7
40+
minute = 0
41+
}
42+
triggerBuild = always()
43+
withPendingChangesOnly = false
44+
enforceCleanCheckout = true
45+
enforceCleanCheckoutForDependencies = true
46+
}
47+
}
48+
49+
})

.teamcity/builds/SemgrepCheck.kt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package builds
2+
3+
import jetbrains.buildServer.configs.kotlin.buildSteps.MavenBuildStep
4+
import jetbrains.buildServer.configs.kotlin.buildSteps.ScriptBuildStep
5+
6+
class SemgrepCheck(
7+
id: String,
8+
name: String
9+
): Maven(
10+
id,
11+
name,
12+
"dependency:tree",
13+
"-DoutputFile=maven_dep_tree.txt",
14+
mavenVersion = MavenBuildStep.MavenVersion.Bundled_3_9()
15+
) {
16+
17+
init {
18+
19+
params.password("env.SEMGREP_APP_TOKEN", "%semgrep-app-token%")
20+
params.text("env.SEMGREP_REPO_NAME", FULL_GITHUB_REPOSITORY)
21+
params.text("env.SEMGREP_REPO_URL", GITHUB_URL)
22+
params.text("env.SEMGREP_BRANCH", "%teamcity.build.branch%")
23+
params.text("env.SEMGREP_JOB_URL", "%env.BUILD_URL%")
24+
params.text("env.SEMGREP_COMMIT", "%env.BUILD_VCS_NUMBER%")
25+
26+
steps.step(ScriptBuildStep {
27+
scriptContent="semgrep ci --no-git-ignore"
28+
dockerImagePlatform = ScriptBuildStep.ImagePlatform.Linux
29+
dockerImage = SEMGREP_DOCKER_IMAGE
30+
dockerRunParameters =
31+
"--volume /var/run/docker.sock:/var/run/docker.sock --volume %teamcity.build.checkoutDir%/signingkeysandbox:/root/.gnupg"
32+
})
33+
}
34+
35+
}

.teamcity/settings.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import builds.Build
2+
import builds.NightlyBuild
23
import jetbrains.buildServer.configs.kotlin.project
34
import jetbrains.buildServer.configs.kotlin.version
45

@@ -11,6 +12,7 @@ project {
1112
password("signing-key-passphrase", "%publish-signing-key-password%")
1213
password("github-commit-status-token", "%github-token%")
1314
password("github-pull-request-token", "%github-token%")
15+
password("semgrep-app-token", "%semgrep-token%")
1416
}
1517

1618
subProject(
@@ -37,4 +39,5 @@ project {
3739
"""
3840
.trimIndent(),
3941
forPullRequests = true))
42+
subProject(NightlyBuild("nightly"))
4043
}

0 commit comments

Comments
 (0)