Skip to content

Commit cf96b50

Browse files
authored
Merge pull request #94 from egineering-llc/release/2.0.0
Release/2.0.0
2 parents 3a3e33f + 0b5407a commit cf96b50

29 files changed

+1379
-180
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ language: java
33
script: mvn verify
44

55
jdk:
6-
- openjdk7
7-
- oraclejdk8
6+
- openjdk8
87

98
cache:
109
directories:
@@ -14,3 +13,6 @@ notifications:
1413
email:
1514
recipients:
1615
- eg.oss@e-gineering.com
16+
17+
after_success:
18+
- mvn jacoco:report coveralls:report

README.md

Lines changed: 67 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# gitflow-helper-maven-plugin [![Build Status](https://travis-ci.org/egineering-llc/gitflow-helper-maven-plugin.svg?branch=master)](https://travis-ci.org/egineering-llc/gitflow-helper-maven-plugin)
1+
# gitflow-helper-maven-plugin [![Build Status](https://travis-ci.org/egineering-llc/gitflow-helper-maven-plugin.svg?branch=master)](https://travis-ci.org/egineering-llc/gitflow-helper-maven-plugin) [![Coverage Status](https://coveralls.io/repos/github/egineering-llc/gitflow-helper-maven-plugin/badge.svg)](https://coveralls.io/github/egineering-llc/gitflow-helper-maven-plugin)
22

33
A build extension and plugin that helps Maven play nicely with gitflow projects, CI servers and local development.
44

@@ -10,6 +10,7 @@ It does so by:
1010
* SCM tagging builds for master and support branches. You can use the project SCM definition, or if you omit it, you can resolve the CI server's repository connection information. (Zero Maven scm configuration necessary)
1111
* Promoting existing tested (staged) artifacts for release, rather than re-building the artifacts. Eliminates the risk of accidental master merges or commits resulting in untested code being released, and provides digest hash traceability for the history of artifacts.
1212
* Enabling the decoupling of repository deployment and execution environment delivery based on the current git branch.
13+
* Allowing for long-running non-release branches to be deployed to snapshots, automatically reversioning the artifacts based off the branch name.
1314
* Automated deployment, promotion, and delivery of projects without the [maven-release-plugin](http://maven.apache.org/maven-release/maven-release-plugin/) or some other [*almost there* solution](https://axelfontaine.com/blog/final-nail.html).
1415
* Customizing maven project and system properties based upon the current branch being built. This allows test cases to target different execution environments without changing the artifact results.
1516
* Enabling automatic purging and resolving (force update) of 'release' and 'hotfix' release versioned dependencies resolved from the 'stage' repository.
@@ -24,6 +25,7 @@ This plugin solves a few specific issues common in consolidated Hudson/Jenkins C
2425
4. Set arbitrary project properties based upon the type of GIT branch being built.
2526
5. Reliably tag deploy builds from the master and support branches
2627
6. Enable split 'deploy' vs. 'deliver' maven CI job configuration, without rebuilding artifacts for the 'deliver' phase.
28+
7. Allow for deployment of long-running feature branches to repositories without having to mangle the version in the pom.xml.
2729

2830
In addition to supporting these goals for the project, this plugin does it in a manner that tries to be as effortless (yet configurable) as possible.
2931
If you use non-standard gitflow branch names (emer instead of hotfix), this plugin supports that. If you don't want to do version enforcement, this plugin supports that.
@@ -107,14 +109,16 @@ All of the solutions to these issues are implemented independently in different
107109
<releaseDeploymentRepository>localnexus-releases</releaseDeploymentRepository>
108110
<stageDeploymentRepository>localnexus-stage</stageDeploymentRepository>
109111
<snapshotDeploymentRepository>localnexus-snapshots</snapshotDeploymentRepository>
112+
<!-- Allow branches starting with feature/poc to be published as automagically versioned branch-name-SNAPSHOT artifacts -->
113+
<otherDeploymentBranchPattern>(origin/)feature/poc/.*</otherDeploymentBranchPattern>
110114
</configuration>
111115
<executions>
112116
<execution>
113117
<goals>
114118
<goal>enforce-versions</goal>
119+
<goal>set-properties</goal>
115120
<goal>retarget-deploy</goal>
116121
<goal>update-stage-dependencies</goal>
117-
<goal>set-properties</goal>
118122
<goal>tag-master</goal>
119123
<goal>promote-master</goal>
120124
</goals>
@@ -124,7 +128,6 @@ All of the solutions to these issues are implemented independently in different
124128
<hotfixBranchPropertyFile>foo/bar/emer.props</hotfixBranchPropertyFile>
125129
<releaseBranchPropertyFile>foo/bar/test.props</releaseBranchPropertyFile>
126130
<developmentBranchPropertyFile>foo/bar/dev.props</developmentBranchPropertyFile>
127-
<featureOrBugfixBranchPropertyFile>foo/bar/feat.props</featureOrBugfixBranchPropertyFile>
128131
<otherBranchPropertyFile>foo/bar/ci.props</otherBranchPropertyFile>
129132
<undefinedBranchPropertyFile>foo/bar/local.props</undefinedBranchPropertyFile>
130133
</configuration>
@@ -144,9 +147,9 @@ One common stumbling block for teams adjusting to gitflow with Maven projects is
144147
In practice, the Maven versions should:
145148

146149
* Be synchronized with release branch and hotfix branch names.
147-
* Never be -SNAPSHOT in the master, support, release, or hotfix branches. Also, no -SNAPSHOT parent or (plugin) dependencies are allowed. (This condition may be disabled by setting `enforceNonSnapshots` = `false`.)
148-
* Always be -SNAPSHOT in the feature and develop branches.
149-
* Be irrelevant if there's no git branch resolvable from your environment.
150+
* Never be -SNAPSHOT in the master, support, release, or hotfix branches. Also, no -SNAPSHOT parent or (plugin) dependencies are allowed.
151+
* Always be -SNAPSHOT in the develop branch.
152+
* Be irrelevant if there's no git branch resolvable from your environment or working in a branch which is not deployed to remote repositories.
150153

151154
The `enforce-versions` goal asserts these semantics when it can resolve the `gitBranchExpression`.
152155

@@ -166,9 +169,21 @@ The following properties change the behavior of this goal:
166169
| supportBranchPattern | (origin/)?support/(.*) | No | Regex. When matches, signals a support branch (long term master-equivalent for older release) being built. Last subgroup, if present, must be start of the Maven project version. |
167170
| releaseBranchPattern | (origin/)?release/(.*) | No | Regex. When matched, signals a release branch being built. Last subgroup, if present, must match the Maven project version. |
168171
| hotfixBranchPattern | (origin/)?hotfix/(.*) | No | Regex. When matched, signals a hotfix branch is being built. Last subgroup, if present, must match the Maven project version. |
169-
| featureOrBugfixBranchPattern | (origin/)?(?:feature&#124;bugfix)/(.*) | Yes | Regex. When matched, signals a feature or bugfix branch is being built. |
170172
| developmentBranchPattern | (origin/)?develop | Yes | Regex. When matched, signals a development branch is being built. Note the lack of a subgroup. |
171173

174+
## Goal: `set-properties` (Dynamically Set Maven Project / System Properties)
175+
176+
Some situations with automated testing (and integration testing in particular) demand changing configuration properties
177+
based upon the branch type being built. This is a common necessity when configuring automated DB refactorings as part of
178+
a build, or needing to setup / configure datasources for automated tests to run against.
179+
180+
The `set-properties` goal allows for setting project (or system) properties, dynamically based on the detected git
181+
branch being built. Properties can be specified as a Properties collection in plugin configuration, or can be loaded
182+
from a property file during the build. Both property key names and property values will have placeholders resolved.
183+
184+
Multiple executions can be configured, and each execution can target different scopes (system or project), and can load
185+
properties from files with an assigned keyPrefix, letting you name-space properties from execution ids.
186+
172187

173188
## Goal: `retarget-deploy` (Branch Specific Deploy Targets & Staging)
174189

@@ -185,11 +200,10 @@ plugins in the build process (deploy, site-deploy, etc.) will use the repositori
185200
| Property | Default Value | Description |
186201
| -------- | ------------- | ----------- |
187202
| gitBranchExpression | current git branch resolved from SCM or ${env.GIT_BRANCH} | Maven property expression to resolve in order to determine the current git branch |
188-
| deploySnapshotTypeBranches | `false` | When `true`, feature branches will also be deployed to the snapshots repository. |
189203
| releaseDeploymentRepository | n/a | The repository to use for releases. (Builds with a GIT_BRANCH matching `masterBranchPattern` or `supportBranchPattern`) |
190204
| stageDeploymentRepository | n/a | The repository to use for staging. (Builds with a GIT_BRANCH matching `releaseBranchPattern` or `hotfixBranchPattern`) |
191205
| snapshotDeploymentRepository | n/a | The repository to use for snapshots. (Builds matching `developmentBranchPattern`) |
192-
206+
| otherDeploymentBranchPattern | n/a | Regex. When matched, the branch name is normalized and any artifacts produced by the build will include the normalized branch name and -SNAPSHOT. Deployment will target the snapshot repository |
193207

194208
**The repository properties should follow the following format**, `id::layout::url::uniqueVersion`.
195209

@@ -238,20 +252,15 @@ Can be replaced with the following plugin configuration, which also introduces t
238252
...
239253
</build>
240254

255+
### Deploying non-release (OTHER) type branches as -SNAPSHOT releases.
241256

242-
## Goal: `set-properties` (Dynamically Set Maven Project / System Properties)
243-
244-
Some situations with automated testing (and integration testing in particular) demand changing configuration properties
245-
based upon the branch type being built. This is a common necessity when configuring automated DB refactorings as part of
246-
a build, or needing to setup / configure datasources for automated tests to run against.
247-
248-
The `set-properties` goal allows for setting project (or system) properties, dynamically based on the detected git
249-
branch being built. Properties can be specified as a Properties collection in plugin configuration, or can be loaded
250-
from a property file during the build. Both property key names and property values will have placeholders resolved.
251-
252-
Multiple executions can be configured, and each execution can target different scopes (system or project), and can load
253-
properties from files with an assigned keyPrefix, letting you name-space properties from execution ids.
254-
257+
In addition to setting up repository targets for release branches, the `retarget-depoy` branch can deploy other branches
258+
matching the `otherDeploymentBranchPattern` as -SNAPSHOT artifacts which include the branch name as build metadata.
259+
This is loosely based on the [semVer](https://semver.org) semantic version scheme, in that the plugin will reversion any
260+
artifacts to be produced with `+feature-branch-name-normalized-SNAPSHOT` where any characters not in `[0-9A-Za-z-.]` will
261+
be replaced with `-`. Artifact versions for feature branches will _always_ be -SNAPSHOT, and will _always_ target the
262+
Snapshots repository. The intent for this configuration setting is to provide a way for long-running branches (matching
263+
a naming convention you define) can be published to a SNAPSHOT repo for use by other projects.
255264

256265
## Goal: `update-stage-dependencies` (Force update of dependency staged Releases)
257266

@@ -339,8 +348,8 @@ The following table describes the git branch expression -> repository used for r
339348
| supportBranchPattern | release |
340349
| releaseBranchPattern | stage |
341350
| hotfixBranchPattern | stage |
342-
| featureOrBugfixBranchPattern | snapshots |
343351
| developmentBranchPattern | snapshots |
352+
| otherBranchesToDeploy | snapshots |
344353
| All Others | local |
345354

346355
As an example, assume you have two CI jobs.
@@ -361,15 +370,40 @@ it's building. The attach-deploy will 'clean' the maven project, then download t
361370
that the first build deployed into. Once they're attached to the project, the `jboss-as:deploy-only` goal will deliver
362371
the artifacts built by the first job into a jboss application server.
363372

373+
# Additional Notes
374+
## How Git branch name resolution works
375+
1. If the `<scm>` sections of the pom points to a git repository, `git symbolic-ref HEAD` to is used to check the local branch name.
376+
2. If the `symbolic-ref` fails then it's likely due to a detached HEAD.
377+
This is typical of CI servers like Jenkins, where the commit hash that was just pushed is pulled.
378+
This can also be done as a consequene of attempting to rebuild from a tag, without branching, or in some
379+
workflows where code reviews are done without branches.
380+
381+
In the case of a detached HEAD the plugin will:
382+
* Resolve the HEAD to a commit using `git rev-parse HEAD`.
383+
* `git show-ref` to resolve which (local/remote) branches point to the commit.
384+
* If the detached HEAD commit resolves to a single branch type, it uses that branch name.
385+
3. If the first two methods fail, the plugin attempts to resolve `${env.GIT_BRANCH}`.
386+
387+
## To Debug the plugin (replicating a test-case but without being run from jUnit)
388+
You can 'bootstrap' the plugin into your local repository and get the test project stubbed by running:
389+
`mvn -Dmaven.test.skip=true install`
390+
391+
Then, change directories:
392+
`cd target/test-classes/project-stub`
393+
394+
From there, you'll need to supply the required environment variables or commandline arguments to `mvnDebug`:
395+
```
396+
export GIT_BRANCH=origin/feature/mybranch-foo-bar
397+
mvnDebug -Dstub.project.version=5.0.0-SNAPSHOT -DotherBranchDeploy=semver -DallowGitflowPluginSnapshot=true deploy
398+
```
399+
You can then connect a remote debugger and step through the plugin code.
364400

365-
# Resolving the Git branch name
366-
As stated before, the plugin determines what to do by resolving the Git branch name.
401+
## Building with IntelliJ IDEA notes
402+
### To Debug Test Code:
403+
Configure the Maven commandline to include
404+
`-DforkMode=never` You will likely get warnings when you run maven with this argument.
367405

368-
* The first try is a `git symbolic-ref HEAD` to check the local branch name. If it's found, that's the branch name that's used.
369-
* If the `symbolic-ref` fails then it's probably due to a detached HEAD. This typically happens on Jenkins, when it simply checks out the commit hash that was just pushed.
370-
Or, it's because of a developer doing a `git checkout origin/feature/x`, e.g. when doing a code review and no local branch is required.
371-
In such a case:
372-
* The plugin will first resolve the HEAD to a commit using `git rev-parse HEAD`.
373-
* Next, it will do a `git show-ref` to check which (local/remote) branches point to the commit.
374-
* If it can resolve the commit to a single branch type (e.g. develop or master) then that's the branch name that's used.
375-
* If all of the above fails, `${env.GIT_BRANCH}` is tried.
406+
### To inspect code-coverage results from Integration Tests:
407+
* Select the **Analyze** -> **Show Coverage Data** menu.
408+
* In the dialog that appears, click the **+** in the upper left corner to `Add (Insert)`, and browse to `target/jacoco.exec`.
409+
* Selecting that file will show coverage data in the code editor.

0 commit comments

Comments
 (0)