]> source.dussan.org Git - sonarqube.git/commitdiff
BUILD-1745 execute only on CI and main branch or explicit call
authorJulien Carsique <julien.carsique@sonarsource.com>
Fri, 2 Sep 2022 15:55:10 +0000 (17:55 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 8 Sep 2022 20:03:10 +0000 (20:03 +0000)
fix: remove sonar-web from bom inputs.files, a dedicated yarn bom build is to be implemented if needed

build.gradle
sonar-application/build.gradle

index 5ae2fa30754198498d04e9475833571077b7e887..e353e1501b3c16d1d57950058e48129f52890272 100644 (file)
@@ -17,6 +17,20 @@ if (!JavaVersion.current().java11Compatible) {
   throw new GradleException("JDK 11+ is required to perform this build. It's currently " + System.getProperty("java.home") + ".")
 }
 
+/**
+ * The BOM related tasks are disabled by default, activated by:
+ * - running in the CI and being on a main branch or a nightly build,
+ * - or using '-Dbom' project property
+ * - or by explicit call to 'cyclonedxBom' Gradle task
+ */
+def bomTasks = "cyclonedxBom"
+def ghBranch = System.getenv()["GITHUB_BRANCH"]
+def isMainBranch = ghBranch in ['master'] || ghBranch ==~ 'branch-[\\d.]+'
+def isNightlyBuild = ghBranch == "branch-nightly-build"
+boolean enableBom = System.getenv('CI') == "true" && (isMainBranch || isNightlyBuild) ||
+        System.getProperty("bom") != null ||
+        gradle.startParameter.taskNames.findAll({ it.matches(".*:($bomTasks)") })
+
 allprojects {
   apply plugin: 'com.jfrog.artifactory'
   apply plugin: 'maven-publish'
@@ -37,6 +51,14 @@ allprojects {
     official = project.hasProperty('official') && project.getProperty('official')
   }
 
+  ext.enableBom = enableBom
+  if (!enableBom) {
+    tasks.matching { it.name.matches(bomTasks) }.all({
+      logger.info("{} disabled", it.name);
+      it.enabled = false
+    })
+  }
+
   repositories {
     def repository = project.hasProperty('qa') ? 'sonarsource-qa' : 'sonarsource'
     maven {
@@ -78,7 +100,7 @@ allprojects {
             'build.number': System.getenv('BUILD_NUMBER'),
             'pr.branch.target': System.getenv('GITHUB_BASE_BRANCH'),
             'pr.number': System.getenv('PULL_REQUEST'),
-            'vcs.branch': System.getenv('GITHUB_BRANCH'),
+            'vcs.branch': ghBranch,
             'vcs.revision': System.getenv('GIT_SHA1'),
             'version': version
         ]
@@ -507,7 +529,7 @@ subprojects {
     }
   }
 
-  if (System.getenv('GITHUB_BRANCH') == "branch-nightly-build") {
+  if (isNightlyBuild) {
     tasks.withType(Test) {
 
       configurations {
@@ -536,19 +558,14 @@ subprojects {
     def signingPassword = findProperty("signingPassword")
     useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
     required {
-      def branch = System.getenv()["GITHUB_BRANCH"]
-      return (branch in ['master'] || branch ==~ 'branch-[\\d.]+') &&
-             gradle.taskGraph.hasTask(":artifactoryPublish")
+      return isMainBranch && gradle.taskGraph.hasTask(":artifactoryPublish")
     }
     sign publishing.publications
   }
 
   tasks.withType(Sign) {
     onlyIf {
-      def branch = System.getenv()["GITHUB_BRANCH"]
-      return !artifactoryPublish.skip &&
-             (branch in ['master'] || branch ==~ 'branch-[\\d.]+') &&
-             gradle.taskGraph.hasTask(":artifactoryPublish")
+      return !artifactoryPublish.skip && isMainBranch && gradle.taskGraph.hasTask(":artifactoryPublish")
     }
   }
 }
index 59f09a9d7806d1c3d26fa06dfc7603c8aac687ec..9f24ddbccd3fca42e1d9fe3efd801e03e678c9d7 100644 (file)
@@ -340,7 +340,7 @@ cyclonedxBom {
   outputs.file bomFile
 }
 tasks.cyclonedxBom {
-  inputs.files(configurations.runtimeClasspath, configurations.web, configurations.shutdowner, configurations.jdbc_mssql,
+  inputs.files(configurations.runtimeClasspath, configurations.shutdowner, configurations.jdbc_mssql,
           configurations.jdbc_postgresql, configurations.jdbc_h2, configurations.bundledPlugin_deps, configurations.cyclonedx)
 }
 def bomArtifact = artifacts.add('archives', bomFile.get().asFile) {
@@ -354,8 +354,10 @@ publishing {
     mavenJava(MavenPublication) {
       artifact zip
     }
-    mavenJava(MavenPublication) {
-      artifact bomArtifact
+    if (enableBom) {
+      mavenJava(MavenPublication) {
+        artifact bomArtifact
+      }
     }
   }
 }