Skip to content

Commit

Permalink
Add ability to skip merging release into production branch - closes #74
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandr-m committed Sep 23, 2020
1 parent 717be90 commit af7a8a1
Show file tree
Hide file tree
Showing 11 changed files with 169 additions and 8 deletions.
7 changes: 7 additions & 0 deletions src/it/release-finish-7-it/expected-development-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.amashchenko.maven.plugin</groupId>
<artifactId>gitflow-maven-test</artifactId>
<packaging>pom</packaging>
<version>0.0.4-SNAPSHOT</version>
</project>
7 changes: 7 additions & 0 deletions src/it/release-finish-7-it/expected-production-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.amashchenko.maven.plugin</groupId>
<artifactId>gitflow-maven-test</artifactId>
<packaging>pom</packaging>
<version>0.0.1</version>
</project>
6 changes: 6 additions & 0 deletions src/it/release-finish-7-it/gitignorefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
build.log
expected-development-pom.xml
expected-production-pom.xml
invoker.properties
init.bsh
verify.bsh
41 changes: 41 additions & 0 deletions src/it/release-finish-7-it/init.bsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import org.codehaus.plexus.util.FileUtils;

try {
new File(basedir, "gitignorefile").renameTo(new File(basedir, ".gitignore"));

Process p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " init");
p.waitFor();

Process p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " config user.email 'a@a.aa'");
p.waitFor();
Process p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " config user.name 'a'");
p.waitFor();

p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " add .");
p.waitFor();

p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " commit -m init");
p.waitFor();

p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " branch develop");
p.waitFor();

p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " checkout -b release/0.0.3");
p.waitFor();

File pomfile = new File(basedir, "pom.xml");
String pomfilestr = FileUtils.fileRead(pomfile, "UTF-8");
pomfilestr = pomfilestr.replaceAll("0.0.1", "0.0.3");
FileUtils.fileWrite(basedir + "/pom.xml", "UTF-8", pomfilestr);

p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " add .");
p.waitFor();

p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " commit -m 0.0.3");
p.waitFor();

} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
3 changes: 3 additions & 0 deletions src/it/release-finish-7-it/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:release-finish -DpushRemote=false -DskipReleaseMergeProdBranch

invoker.description=Test release-finish with skipReleaseMergeProdBranch parameter.
7 changes: 7 additions & 0 deletions src/it/release-finish-7-it/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.amashchenko.maven.plugin</groupId>
<artifactId>gitflow-maven-test</artifactId>
<packaging>pom</packaging>
<version>0.0.1</version>
</project>
61 changes: 61 additions & 0 deletions src/it/release-finish-7-it/verify.bsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import org.codehaus.plexus.util.FileUtils;

try {
File gitTag = new File(basedir, ".git/refs/tags/0.0.3");
if (!gitTag.exists()) {
System.out.println("release-finish .git/refs/tags/0.0.3 doesn't exist");
return false;
}

File gitReleaseRef = new File(basedir, ".git/refs/heads/release/0.0.3");
if (gitReleaseRef.exists()) {
System.out.println("release-finish .git/refs/heads/release/0.0.3 exists");
return false;
}
File gitDevelopRef = new File(basedir, ".git/refs/heads/develop");
if (!gitDevelopRef.exists()) {
System.out.println("release-finish .git/refs/heads/develop doesn't exist");
return false;
}
File gitMasterRef = new File(basedir, ".git/refs/heads/master");
if (!gitMasterRef.exists()) {
System.out.println("release-finish .git/refs/heads/master doesn't exist");
return false;
}

File file = new File(basedir, "pom.xml");
File expectedFile = new File(basedir, "expected-development-pom.xml");

String actual = FileUtils.fileRead(file, "UTF-8");
String expected = FileUtils.fileRead(expectedFile, "UTF-8");

actual = actual.replaceAll("\\r?\\n", "");
expected = expected.replaceAll("\\r?\\n", "");

if (!expected.equals(actual)) {
System.out.println("release-finish expected development pom: " + expected + " actual was:" + actual);
return false;
}

p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " checkout master");
p.waitFor();

file = new File(basedir, "pom.xml");
expectedFile = new File(basedir, "expected-production-pom.xml");

actual = FileUtils.fileRead(file, "UTF-8");
expected = FileUtils.fileRead(expectedFile, "UTF-8");

actual = actual.replaceAll("\\r?\\n", "");
expected = expected.replaceAll("\\r?\\n", "");

if (!expected.equals(actual)) {
System.out.println("release-finish expected production pom: " + expected + " actual was:" + actual);
return false;
}

} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
17 changes: 15 additions & 2 deletions src/it/release-finish-it/init.bsh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.codehaus.plexus.util.FileUtils;

try {
new File(basedir, "gitignorefile").renameTo(new File(basedir, ".gitignore"));

Expand All @@ -15,10 +17,21 @@ try {
p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " commit -m init");
p.waitFor();

p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " branch release/0.0.3");
p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " branch develop");
p.waitFor();

p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " checkout -b release/0.0.3");
p.waitFor();

File pomfile = new File(basedir, "pom.xml");
String pomfilestr = FileUtils.fileRead(pomfile, "UTF-8");
pomfilestr = pomfilestr.replaceAll("0.0.1", "0.0.3");
FileUtils.fileWrite(basedir + "/pom.xml", "UTF-8", pomfilestr);

p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " add .");
p.waitFor();

p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " checkout -b develop");
p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " commit -m 0.0.3");
p.waitFor();

} catch (Exception e) {
Expand Down
2 changes: 1 addition & 1 deletion src/it/release-finish-it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
<groupId>com.amashchenko.maven.plugin</groupId>
<artifactId>gitflow-maven-test</artifactId>
<packaging>pom</packaging>
<version>0.0.3</version>
<version>0.0.1</version>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ public class GitFlowReleaseFinishMojo extends AbstractGitFlowMojo {
@Parameter(property = "useSnapshotInRelease", defaultValue = "false")
private boolean useSnapshotInRelease;

/**
* Whether to skip merging release into the production branch.
*
*/
@Parameter(property = "skipReleaseMergeProdBranch", defaultValue = "false")
private boolean skipReleaseMergeProdBranch = false;

/** {@inheritDoc} */
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
Expand Down Expand Up @@ -252,11 +259,13 @@ public void execute() throws MojoExecutionException, MojoFailureException {
gitCommit(commitMessages.getReleaseFinishMessage(), messageProperties);
}

// git checkout master
gitCheckout(gitFlowConfig.getProductionBranch());
if (!skipReleaseMergeProdBranch) {
// git checkout master
gitCheckout(gitFlowConfig.getProductionBranch());

gitMerge(releaseBranch, releaseRebase, releaseMergeNoFF, releaseMergeFFOnly,
commitMessages.getReleaseFinishMergeMessage(), messageProperties);
gitMerge(releaseBranch, releaseRebase, releaseMergeNoFF, releaseMergeFFOnly, commitMessages.getReleaseFinishMergeMessage(),
messageProperties);
}

// get current project version from pom
final String currentVersion = getCurrentProjectVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ public class GitFlowReleaseMojo extends AbstractGitFlowMojo {
@Parameter(property = "gpgSignTag", defaultValue = "false")
private boolean gpgSignTag = false;

/**
* Whether to skip merging release into the production branch.
*
*/
@Parameter(property = "skipReleaseMergeProdBranch", defaultValue = "false")
private boolean skipReleaseMergeProdBranch = false;

/** {@inheritDoc} */
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
Expand Down Expand Up @@ -259,7 +266,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
gitCommit(commitMessages.getReleaseStartMessage(), messageProperties);
}

if (notSameProdDevName()) {
if (!skipReleaseMergeProdBranch && notSameProdDevName()) {
// git checkout master
gitCheckout(gitFlowConfig.getProductionBranch());

Expand Down

0 comments on commit af7a8a1

Please sign in to comment.