Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick authored Oct 9, 2019
2 parents 54adc24 + 1103691 commit c56dad2
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_extends: .github
tag-template: parent-$NEXT_MINOR_VERSION
18 changes: 18 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: CI
on:
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v1
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Maven
run: mvn -B -V -ntp -Dstyle.color=always package
env:
MAVEN_OPTS: -Djansi.force=true
156 changes: 155 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Finally, configure `git-changelist-maven-extension` in `.mvn/extensions.xml`. (U
<extension>
<groupId>io.jenkins.tools.incrementals</groupId>
<artifactId>git-changelist-maven-extension</artifactId>
<version>1.0-beta-3</version>
<version>1.0-beta-7</version>
</extension>
</extensions>
```
Expand Down Expand Up @@ -250,6 +250,144 @@ mvn incrementals:reincrementalify

to fix it up.

### Superseding Maven releases

If you want to use Incrementals _instead_ of MRP,
you can override `changelist.format` in your project (the default value is `-rc%d.%s`).

For a regular component whose version number is not intrinsically meaningful:

```diff
--- a/.mvn/extensions.xml
+++ b/.mvn/extensions.xml
@@ -2,6 +2,6 @@
<extension>
<groupId>io.jenkins.tools.incrementals</groupId>
<artifactId>git-changelist-maven-extension</artifactId>
- <version>1.0-beta-7</version>
+ <version>1.1</version>
</extension>
</extensions>
--- a/.mvn/maven.config
+++ b/.mvn/maven.config
@@ -1,2 +1,3 @@
-Pconsume-incrementals
-Pmight-produce-incrementals
+-Dchangelist.format=%d.%s
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
- <version>${revision}${changelist}</version>
+ <version>${changelist}</version>
<packaging>hpi</packaging>
@@ -26,8 +26,7 @@
<properties>
- <revision>1.23</revision>
- <changelist>-SNAPSHOT</changelist>
+ <changelist>999999-SNAPSHOT</changelist>
<jenkins.version>2.176.4</jenkins.version>
<java.level>8</java.level>
</properties>
```

Here a CI/release build (`-Dset.changelist` specified) will be of the form `123.abcdef456789`.
A snapshot build will be `999999-SNAPSHOT`: arbitrary but treated as a snapshot by Maven and newer than any release.

For a component whose version number ought to reflect a release version of some wrapped component:

```diff
--- a/.mvn/extensions.xml
+++ b/.mvn/extensions.xml
@@ -2,6 +2,6 @@
<extension>
<groupId>io.jenkins.tools.incrementals</groupId>
<artifactId>git-changelist-maven-extension</artifactId>
- <version>1.0-beta-7</version>
+ <version>1.1</version>
</extension>
</extensions>
--- a/.mvn/maven.config
+++ b/.mvn/maven.config
@@ -1,2 +1,3 @@
-Pconsume-incrementals
-Pmight-produce-incrementals
+-Dchangelist.format=%d.%s
--- a/pom.xml
+++ b/pom.xml
@@ -10,12 +10,12 @@
<artifactId>some-library-wrapper</artifactId>
- <version>${revision}${changelist}</version>
+ <version>${revision}-${changelist}</version>
<packaging>hpi</packaging>
<properties>
- <revision>4.0.0-1.3</revision>
- <changelist>-SNAPSHOT</changelist>
+ <revision>4.0.0</revision>
+ <changelist>999999-SNAPSHOT</changelist>
<jenkins.version>2.176.4</jenkins.version>
<java.level>8</java.level>
<some-library.version>4.0.0</some-library.version>
```

Here the version numbers will look like `4.0.0-123.abcdef456789` or `4.0.0-999999-SNAPSHOT`, respectively.
When you pick up a new third-party component like `4.0.1`, your version numbers will match.
To ensure that the two copies of that third-party version stay in synch, you can add:

```xml
<build>
<plugins>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>enforce-property</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireProperty>
<property>revision</property>
<regex>\Q${some-library.version}\E</regex>
<regexMessage>revision (${revision}) must equal some-library.version (${some-library.version})</regexMessage>
</requireProperty>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
```

Since inadvertently running MRP on such a project would result in a mess,
it is best to explicitly prevent that:

```xml
<build>
<plugins>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<preparationGoals>not-set-up-for-MRP</preparationGoals>
</configuration>
</plugin>
</plugins>
</build>
```

Pending [JEP-221](https://jenkins.io/jep/221) or similar,
there is no automatic publishing of such artifacts.
However, you can release manually if you have
[personal deployment credentials](https://github.com/jenkins-infra/repository-permissions-updater).
To cut a release:

```bash
git checkout master
git pull --ff-only
mvn -Dset.changelist -DaltDeploymentRepository=maven.jenkins-ci.org::default::https://repo.jenkins-ci.org/releases/ clean deploy
```

## Usage in other POMs

From repositories with POMs not inheriting from `org.jenkins-ci.plugins:plugin` you can follow similar steps to use Incrementals.
Expand All @@ -259,6 +397,21 @@ as well as the `incrementals.url` and `scmTag` properties,
into your parent POM or directly into your repository POM.
Some adjustment of `maven-enforcer-plugin` configuration may also be necessary.

### Publishing

Once Incrementals is enabled in a plugin repository,
the stock `buildPlugin` method takes care of publishing artifacts from stable builds up to date with the base branch.
For libraries or other components with custom `Jenkinsfile`s, you will need to set this up manually:

```groovy
node('maven') {
checkout scm
sh 'mvn -Dset.changelist install'
infra.prepareToPublishIncrementals()
}
infra.maybePublishIncrementals()
```

## Offline testing

If you wish to test usage offline, run
Expand All @@ -267,6 +420,7 @@ If you wish to test usage offline, run
docker run --rm --name nexus -p 8081:8081 -v nexus-data:/nexus-data sonatype/nexus3
```

Log in to http://localhost:8081/ and pick an admin password as per instructions, then
add to your `~/.m2/settings.xml`:

```xml
Expand Down
2 changes: 1 addition & 1 deletion enforcer-rules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>io.jenkins.tools.incrementals</groupId>
<artifactId>parent</artifactId>
<version>1.0-beta-8-SNAPSHOT</version>
<version>1.1-SNAPSHOT</version>
</parent>
<artifactId>incrementals-enforcer-rules</artifactId>
<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion git-changelist-maven-extension/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>io.jenkins.tools.incrementals</groupId>
<artifactId>parent</artifactId>
<version>1.0-beta-8-SNAPSHOT</version>
<version>1.1-SNAPSHOT</version>
</parent>
<artifactId>git-changelist-maven-extension</artifactId>
<name>Git Changelist Maven Extension</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void afterSessionStart(MavenSession session) throws MavenExecutionExcepti
throw new MavenExecutionException("Git operations failed", x);
}
log.debug("Spent " + (System.nanoTime() - start) / 1000 / 1000 + "ms on calculations");
String value = "-rc" + count + "." + hash;
String value = String.format(props.getProperty("changelist.format", "-rc%d.%s"), count, hash);
log.info("Setting: -Dchangelist=" + value + " -DscmTag=" + fullHash);
props.setProperty("changelist", value);
props.setProperty("scmTag", fullHash);
Expand Down
2 changes: 1 addition & 1 deletion lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>io.jenkins.tools.incrementals</groupId>
<artifactId>parent</artifactId>
<version>1.0-beta-8-SNAPSHOT</version>
<version>1.1-SNAPSHOT</version>
</parent>
<artifactId>lib</artifactId>
<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>io.jenkins.tools.incrementals</groupId>
<artifactId>parent</artifactId>
<version>1.0-beta-8-SNAPSHOT</version>
<version>1.1-SNAPSHOT</version>
</parent>
<artifactId>incrementals-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</parent>
<groupId>io.jenkins.tools.incrementals</groupId>
<artifactId>parent</artifactId>
<version>1.0-beta-8-SNAPSHOT</version>
<version>1.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Incrementals Tools POM</name>
<description>Tools for working with JEP-305 “Incrementals”.</description>
Expand Down

0 comments on commit c56dad2

Please sign in to comment.