Skip to content

Commit c1fd16c

Browse files
committed
minor upgrade/downgrade detection is implemented
1 parent a651648 commit c1fd16c

File tree

4 files changed

+304
-174
lines changed

4 files changed

+304
-174
lines changed

src/main/java/org/scm4j/releaser/ExtendedStatusBuilder.java

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.scm4j.releaser.branch.ReleaseBranchFactory;
99
import org.scm4j.releaser.branch.ReleaseBranchPatch;
1010
import org.scm4j.releaser.conf.*;
11+
import org.scm4j.releaser.exceptions.EMinorUpgradeDowngrade;
1112
import org.scm4j.releaser.exceptions.ENoReleaseBranchForPatch;
1213
import org.scm4j.releaser.exceptions.ENoReleases;
1314
import org.scm4j.releaser.exceptions.EReleaseMDepsNotLocked;
@@ -106,7 +107,7 @@ private ExtendedStatus getMinorStatus(Component comp, CachedStatuses cache, IPro
106107
status = BuildStatus.LOCK;
107108
} else if (hasMDepsNotInDONEStatus(rb.getMDeps(), cache)) {
108109
status = BuildStatus.BUILD_MDEPS;
109-
} else if (!areMDepsPatchesActual(rb.getMDeps(), cache)) {
110+
} else if (!areMDepsPatchesActual(comp, repo, rb.getMDeps(), cache)) {
110111
status = BuildStatus.ACTUALIZE_PATCHES;
111112
} else {
112113
status = BuildStatus.BUILD;
@@ -152,7 +153,7 @@ private ExtendedStatus getPatchStatus(Component comp, CachedStatuses cache, IPro
152153

153154
if (hasMDepsNotInDONEStatus(rb.getMDeps(), cache)) {
154155
buildStatus = BuildStatus.BUILD_MDEPS;
155-
} else if (!areMDepsPatchesActual(rb.getMDeps(), cache)) {
156+
} else if (!areMDepsPatchesActual(comp, repo, rb.getMDeps(), cache)) {
156157
buildStatus = BuildStatus.ACTUALIZE_PATCHES;
157158
} else if (reportDuration(() -> noValueableCommitsAfterLastTag(repo, rb), "is release branch modified check", comp, progress)) {
158159
buildStatus = BuildStatus.DONE;
@@ -217,15 +218,34 @@ private <T> T walkOnCommits(VCSRepository repo, ReleaseBranchPatch rb, Function<
217218
return null;
218219
}
219220

220-
private boolean areMDepsPatchesActual(List<Component> mDeps, CachedStatuses cache) {
221+
private boolean areMDepsPatchesActual(Component rootComp, VCSRepository repo, List<Component> mDeps, CachedStatuses cache) {
221222
for (Component mDep : mDeps) {
222223
String url = repoFactory.getUrl(mDep);
223224
Version nextMDepVersion = cache.get(url).getNextVersion();
224-
if (!nextMDepVersion.equals(mDep.getVersion().toNextPatch())) {
225-
DelayedTagsFile mdf = new DelayedTagsFile();
226-
if (!(nextMDepVersion.getPatch().equals(ZERO_PATCH) && mdf.getDelayedTagByUrl(url) != null)) {
227-
return false;
228-
}
225+
if (!nextMDepVersion.toReleaseNoPatch().equals(mDep.getVersion().toReleaseNoPatch())) {
226+
cache.remove(repo.getUrl());
227+
throw new EMinorUpgradeDowngrade(rootComp, mDep, nextMDepVersion.toPreviousPatch());
228+
}
229+
DelayedTagsFile mdf = new DelayedTagsFile();
230+
Integer cachedMDepPatch;
231+
if (!(nextMDepVersion.getPatch().equals(ZERO_PATCH) && mdf.getDelayedTagByUrl(url) != null)) {
232+
cachedMDepPatch = Integer.parseInt(nextMDepVersion.toPreviousPatch().getPatch());
233+
} else {
234+
cachedMDepPatch = Integer.parseInt(nextMDepVersion.getPatch());
235+
}
236+
237+
Integer mDepPatch = Integer.parseInt(mDep.getVersion().getPatch());
238+
if (cachedMDepPatch == mDepPatch) {
239+
continue;
240+
}
241+
242+
if (cachedMDepPatch < mDepPatch) {
243+
cache.remove(repo.getUrl());
244+
throw new EMinorUpgradeDowngrade(rootComp, mDep, nextMDepVersion.toPreviousPatch());
245+
}
246+
247+
if (!(nextMDepVersion.getPatch().equals(ZERO_PATCH) && mdf.getDelayedTagByUrl(url) != null)) {
248+
return false;
229249
}
230250
}
231251
return true;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.scm4j.releaser.exceptions;
2+
3+
import org.scm4j.commons.Version;
4+
import org.scm4j.releaser.conf.Component;
5+
6+
public class EMinorUpgradeDowngrade extends EReleaserException {
7+
8+
private static final long serialVersionUID = 1L;
9+
10+
private final Version changeToVersion;
11+
private final Component problematicMDep;
12+
private final Component rootComp;
13+
14+
public EMinorUpgradeDowngrade(Component rootComp, Component problematicMDep, Version changeToVersion) {
15+
super(String.format("minor upgrade/downgrade detected for mdep %s of root comp %s: attempt to change to %s", problematicMDep, rootComp, changeToVersion));
16+
this.changeToVersion = changeToVersion;
17+
this.problematicMDep = problematicMDep;
18+
this.rootComp = rootComp;
19+
}
20+
21+
public Version getChangeToVersion() {
22+
return changeToVersion;
23+
}
24+
25+
public Component getProblematicMDep() {
26+
return problematicMDep;
27+
}
28+
29+
public Component getRootComp() {
30+
return rootComp;
31+
}
32+
}

src/test/java/org/scm4j/releaser/WorkflowBuildTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,21 @@ public void testActualizePatches() {
9898
// check UBL actualized unTillDb version
9999
checkUBLMDepsVersions(1);
100100
}
101+
102+
@Test
103+
public void testNoActualizePatchesIfHasNewReleases() {
104+
forkAndBuild(compUnTill);
105+
106+
// release next 2.60 unTillDb minor
107+
env.generateFeatureCommit(env.getUnTillDbVCS(), repoUnTillDb.getDevelopBranch(), "feature added");
108+
forkAndBuild(compUnTillDb, 2);
109+
110+
ReleaseBranchCurrent crb = ReleaseBranchFactory.getCRB(repoUnTill);
111+
IAction action = execAndGetActionBuild(compUnTill.clone(crb.getVersion()));
112+
assertActionDoesNothing(action, compUnTill);
113+
assertActionDoesNothing(action, compUBL);
114+
assertActionDoesNothing(action, compUnTillDb);
115+
}
101116

102117
@Test
103118
public void testLockMDeps() {

0 commit comments

Comments
 (0)