Skip to content

Commit

Permalink
Add support to publish "incrementals"
Browse files Browse the repository at this point in the history
  • Loading branch information
alextu committed Apr 21, 2023
1 parent 633c389 commit fcb1095
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 6 deletions.
11 changes: 11 additions & 0 deletions test/groovy/BuildPluginWithGradleStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,15 @@ class BuildPluginWithGradleStepTests extends BaseTest {
assertTrue(assertMethodCallContainsPattern('error', 'There were test failures'))
assertJobStatusFailure()
}

@Test
void test_buildPluginWithGradle_with_incrementals() throws Exception {
def mockInfra = new Infra()
binding.setProperty('infra', mockInfra)
def script = loadScript(scriptName)

script.call(incrementals: true)

assertTrue(assertMethodCallContainsPattern('fingerprint', '**/*-rc*.*/*-rc*.*'))
}
}
6 changes: 6 additions & 0 deletions test/groovy/mock/Infra.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Infra implements Serializable {
private boolean release
private boolean infra
private boolean buildError
private String recordedCommand

public void checkoutSCM(String repo = null) { }

Expand All @@ -33,10 +34,15 @@ class Infra implements Serializable {
if (buildError) {
throw new RuntimeException('build error')
} else {
recordedCommand = command
return command
}
}

String gradleCommand(List<String> gradleOptions) {
return "gradlew ${gradleOptions.join(' ')}"
}

public boolean isTrusted() {
return trusted
}
Expand Down
40 changes: 34 additions & 6 deletions vars/buildPluginWithGradle.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def call(Map params = [:]) {
timeoutValue = 180
}

def incrementals = params.containsKey('incrementals')
boolean publishingIncrementals = false
boolean archivedArtifacts = false
Map tasks = [failFast: failFast]
Expand All @@ -38,7 +39,11 @@ def call(Map params = [:]) {
infra.checkoutSCM(repo)
}

String m2repo
String changelist

stage("Build (${stageIdentifier})") {
m2repo = "${pwd tmp: true}/m2repo"
if (config.containsKey('javaLevel')) {
infra.publishDeprecationCheck('Remove javaLevel', 'Ignoring deprecated "javaLevel" parameter. This parameter should be removed from your "Jenkinsfile".')
}
Expand All @@ -51,12 +56,21 @@ def call(Map params = [:]) {
if (skipTests) {
gradleOptions += '--exclude-task test'
}
String command = "gradlew ${gradleOptions.join(' ')}"
if (isUnix()) {
command = "./" + command
}

try {
infra.runWithJava(command, jdk)
if (incrementals) {
def changelistF = "${pwd tmp: true}/changelist"
// TODO remove "-Dmaven.repo.local=$m2repo" only here for testing local changes
infra.runWithJava(infra.gradleCommand(['--no-daemon', 'cleanTest', 'generateGitVersion', "-Dmaven.repo.local=$m2repo", "-PgitVersionFile=${changelistF}", '-PgitVersionFormat=rc-%d.%s', '-PgitVersionSanitize=true']), jdk)

changelist = readFile(changelistF)

// assumes the project does not set its own version in build.gradle with `version=foo`, it can be set
// in gradle.properties though.
infra.runWithJava(infra.gradleCommand([*gradleOptions, 'publishToMavenLocal', "-Dmaven.repo.local=$m2repo", "-Pversion=$changelist"]), jdk)
} else {
infra.runWithJava(infra.gradleCommand(gradleOptions), jdk)
}
} finally {
if (!skipTests) {
junit('**/build/test-results/**/*.xml')
Expand All @@ -70,8 +84,19 @@ def call(Map params = [:]) {
if (failFast && currentBuild.result == 'UNSTABLE') {
error 'There were test failures; halting early'
}

if (doArchiveArtifacts) {
archiveArtifacts artifacts: '**/build/libs/*.hpi,**/build/libs/*.jpi', fingerprint: true, allowEmptyArchive: true
if (incrementals) {
dir(m2repo) {
fingerprint '**/*-rc*.*/*-rc*.*' // includes any incrementals consumed
archiveArtifacts artifacts: "**/*$changelist/*$changelist*",
excludes: '**/*.lastUpdated',
allowEmptyArchive: true // in case we forgot to reincrementalify
}
publishingIncrementals = true
} else {
archiveArtifacts artifacts: '**/build/libs/*.hpi,**/build/libs/*.jpi', fingerprint: true, allowEmptyArchive: true
}
}
}
}
Expand All @@ -80,4 +105,7 @@ def call(Map params = [:]) {
}

parallel(tasks)
if (publishingIncrementals) {
infra.maybePublishIncrementals()
}
}
8 changes: 8 additions & 0 deletions vars/infra.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,14 @@ Object runWithJava(String command, String jdk = '8', List<String> extraEnv = nul
}
}

String gradleCommand(List<String> gradleOptions) {
String command = "gradlew ${gradleOptions.join(' ')}"
if (isUnix()) {
command = "./" + command
}
return command
}

/**
* Make sure the code block is run in a node with the all the specified nodeLabels as labels, if already running in that
* it simply executes the code block, if not allocates the desired node and runs the code inside it
Expand Down

0 comments on commit fcb1095

Please sign in to comment.