From 375630fb7917e2ba1bee15f0be6995c7a24f5983 Mon Sep 17 00:00:00 2001 From: Martin Duhem Date: Tue, 20 May 2025 13:13:39 +0200 Subject: [PATCH] Add sbt-develocity-common-custom-user-data This sbt plugin can be used to simplify the build. Currently, there's some custom logic that extracts some environment variables set by CI, so that their values show up in Develocity. sbt-develocity-common-custom-user-data actually extracts the same values, except `GITHUB_REPOSITORY`, and can be used instead. This plugin is open source, distributed under Apache 2 license. Its sources are available at https://github.com/gradle/common-custom-user-data-sbt-plugin. Differences: - Tags: - "Local" becomes "LOCAL" - Custom values: - "GITHUB_REPOSITORY" is not extracted anymore. - "GITHUB_SHA" becomes "Git commit id" - "GITHUB_WORKFLOW" becomes "CI workflow" - Links: - "GitHub Run" becomes "GitHub Actions build" - "GitHub Commit" becomes "GitHub Source" In addition, the following will be captured: - Tags: - The OS name (e.g. Linux, Mac OS X, etc.) - The IDE, if available (e.g. IntelliJ, Eclipse, etc.) - The Git branch name (on CI only) - "Dirty", if the repo is dirty (on CI only) - Custom values: - "$ide version", containing the IDE version, if available - "CI provider" (e.g. "GitHub Actions") - "Git repository" (e.g. "https://github.com/scala/scala3") - "PR branch" (e.g. mduhem/sbt-ccud) - "Git status", containing the git status (on CI only) - Links: - "CI workflow", linking to other Build Scans running the same CI workflow - "CI run", linking to other Build Scans produced in the same CI run - "Git commit id", linking to other Build Scans produced using the same commit --- project/Build.scala | 3 --- project/GithubEnv.scala | 30 ------------------------------ project/plugins.sbt | 2 ++ 3 files changed, 2 insertions(+), 33 deletions(-) delete mode 100644 project/GithubEnv.scala diff --git a/project/Build.scala b/project/Build.scala index 6339b26243e3..7ca187959306 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -345,9 +345,6 @@ object Build { buildScan .withPublishing(Publishing.onlyIf(_.authenticated)) .withBackgroundUpload(!isInsideCI) - .withTag(if (isInsideCI) "CI" else "Local") - .withLinks(buildScan.links ++ GithubEnv.develocityLinks) - .withValues(buildScan.values ++ GithubEnv.develocityValues) .withObfuscation(buildScan.obfuscation.withIpAddresses(_.map(_ => "0.0.0.0"))) ) .withBuildCache( diff --git a/project/GithubEnv.scala b/project/GithubEnv.scala deleted file mode 100644 index 7e629d53f3a7..000000000000 --- a/project/GithubEnv.scala +++ /dev/null @@ -1,30 +0,0 @@ -import scala.util.Properties -import sbt.url -import java.net.URL - - -// https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/variables#default-environment-variables -object GithubEnv { - lazy val repositoryVar: Option[(String, String)] = envVar("GITHUB_REPOSITORY") - lazy val runIdVar: Option[(String, String)] = envVar("GITHUB_RUN_ID") - lazy val shaVar: Option[(String, String)] = envVar("GITHUB_SHA") - lazy val workflowVar: Option[(String, String)] = envVar("GITHUB_WORKFLOW") - - lazy val runUrl: Option[(String, URL)] = - for { - (_, repository) <- repositoryVar - (_, runId) <- runIdVar - } yield "GitHub Run" -> url(s"https://github.com/$repository/actions/runs/$runId") - lazy val treeUrl: Option[(String, URL)] = - for { - (_, repository) <- repositoryVar - (_, sha) <- shaVar - } yield "GitHub Commit" -> url(s"https://github.com/$repository/tree/$sha") - - - def develocityValues: Seq[(String, String)] = repositoryVar.toSeq ++ shaVar ++ workflowVar - def develocityLinks: Seq[(String, URL)] = runUrl.toSeq ++ treeUrl - - private def envVar(key: String): Option[(String, String)] = - Properties.envOrNone(key).map(key -> _) -} diff --git a/project/plugins.sbt b/project/plugins.sbt index fea55b9fd9e6..f8adc793095f 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -27,4 +27,6 @@ resolvers += addSbtPlugin("com.gradle" % "sbt-develocity" % "1.2.2-rc-1") +addSbtPlugin("com.gradle" % "sbt-develocity-common-custom-user-data" % "1.1") + addSbtPlugin("com.github.sbt" % "sbt-jdi-tools" % "1.2.0")