Skip to content

Commit ab7371a

Browse files
committed
minor upgrade/downgrade detection: refactor, documentation update
1 parent d5f6171 commit ab7371a

File tree

3 files changed

+37
-30
lines changed

3 files changed

+37
-30
lines changed

docs/minor-release-status.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Status denotes next action which should be undertaken to finish patch build: {AC
4545
- mdeps are not locked => ERROR
4646
- `subComponents` are calculated using mdeps from particular RB
4747
- Any component is not in DONE status => BUILD_MDEPS
48+
- Any component `nextVersion`.truncatePatch is not equal to one mentioned in `mdeps` -> error (disallow minor upgrade/downgrade)
49+
- Any component `nextVersion`.patch is less than one mentioned in `mdeps` -> error (patch upgrade only is allowed)
4850
- Any component has patch which is greater than one mentioned in `mdeps` => ACTUALIZE_PATCHES
4951
- No valuable commits after last tag => DONE
5052
- Using #scm-ver is not safe, it is possible to lost commit which is done between build and increasing version

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

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
package org.scm4j.releaser;
22

3+
import static org.scm4j.releaser.Utils.reportDuration;
4+
5+
import java.util.ArrayList;
6+
import java.util.LinkedHashMap;
7+
import java.util.List;
8+
import java.util.concurrent.ConcurrentHashMap;
9+
import java.util.function.Function;
10+
311
import org.scm4j.commons.Version;
412
import org.scm4j.commons.progress.IProgress;
513
import org.scm4j.commons.progress.ProgressConsole;
614
import org.scm4j.releaser.branch.DevelopBranch;
715
import org.scm4j.releaser.branch.ReleaseBranchCurrent;
816
import org.scm4j.releaser.branch.ReleaseBranchFactory;
917
import org.scm4j.releaser.branch.ReleaseBranchPatch;
10-
import org.scm4j.releaser.conf.*;
18+
import org.scm4j.releaser.conf.Component;
19+
import org.scm4j.releaser.conf.DelayedTag;
20+
import org.scm4j.releaser.conf.DelayedTagsFile;
21+
import org.scm4j.releaser.conf.VCSRepository;
22+
import org.scm4j.releaser.conf.VCSRepositoryFactory;
1123
import org.scm4j.releaser.exceptions.EMinorUpgradeDowngrade;
1224
import org.scm4j.releaser.exceptions.ENoReleaseBranchForPatch;
1325
import org.scm4j.releaser.exceptions.ENoReleases;
@@ -17,15 +29,6 @@
1729
import org.scm4j.vcs.api.VCSTag;
1830
import org.scm4j.vcs.api.WalkDirection;
1931

20-
import java.util.ArrayList;
21-
import java.util.LinkedHashMap;
22-
import java.util.List;
23-
import java.util.concurrent.ConcurrentHashMap;
24-
import java.util.function.Function;
25-
26-
import static org.scm4j.releaser.Constants.ZERO_PATCH;
27-
import static org.scm4j.releaser.Utils.reportDuration;
28-
2932
public class ExtendedStatusBuilder {
3033

3134
private static final int PARALLEL_CALCULATION_AWAIT_TIME = 500;
@@ -217,34 +220,37 @@ private <T> T walkOnCommits(VCSRepository repo, ReleaseBranchPatch rb, Function<
217220
} while (commits.size() >= COMMITS_RANGE_LIMIT);
218221
return null;
219222
}
220-
223+
221224
private boolean areMDepsPatchesActual(Component rootComp, VCSRepository repo, List<Component> mDeps, CachedStatuses cache) {
222225
for (Component mDep : mDeps) {
223226
String url = repoFactory.getUrl(mDep);
224-
Version nextMDepVersion = cache.get(url).getNextVersion();
225-
if (!nextMDepVersion.toReleaseNoPatch().equals(mDep.getVersion().toReleaseNoPatch())) {
227+
Version nextVersion = cache.get(url).getNextVersion();
228+
229+
// Any component `nextVersion`.truncatePatch is not equal to one mentioned in `mdeps` -> error (disallow minor upgrade/downgrade)
230+
if (!nextVersion.toReleaseNoPatch().equals(mDep.getVersion().toReleaseNoPatch())) {
226231
cache.remove(repo.getUrl());
227-
throw new EMinorUpgradeDowngrade(rootComp, mDep, nextMDepVersion.toPreviousPatch());
232+
throw new EMinorUpgradeDowngrade(rootComp, mDep, nextVersion.toPreviousPatch());
228233
}
234+
235+
229236
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());
237+
Version verToActualizeOn ;
238+
if (mdf.getDelayedTagByUrl(url) != null) { // if delayed tag
239+
verToActualizeOn = nextVersion;
233240
} else {
234-
cachedMDepPatch = Integer.parseInt(nextMDepVersion.getPatch());
241+
verToActualizeOn = nextVersion.toPreviousPatch();
235242
}
236-
243+
237244
Integer mDepPatch = Integer.parseInt(mDep.getVersion().getPatch());
238-
if (cachedMDepPatch == mDepPatch) {
239-
continue;
240-
}
245+
Integer nextVersionPatch = Integer.parseInt(verToActualizeOn.getPatch());
241246

242-
if (cachedMDepPatch < mDepPatch) {
247+
// Any component `nextVersion`.patch is less than one mentioned in `mdeps` -> error (patch upgrade only is allowed)
248+
if (nextVersionPatch < mDepPatch) {
243249
cache.remove(repo.getUrl());
244-
throw new EMinorUpgradeDowngrade(rootComp, mDep, nextMDepVersion.toPreviousPatch());
250+
throw new EMinorUpgradeDowngrade(rootComp, mDep, verToActualizeOn);
245251
}
246-
247-
if (!(nextMDepVersion.getPatch().equals(ZERO_PATCH) && mdf.getDelayedTagByUrl(url) != null)) {
252+
253+
if (nextVersionPatch > mDepPatch) {
248254
return false;
249255
}
250256
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,10 @@ public void testMinorUpgradeDowngradeException() {
200200
} catch (EMinorUpgradeDowngrade e) {
201201
if (e.getRootComp().equals(compUBL.clone(crbUBL.getVersion().toPreviousPatch()))) {
202202
assertEquals(compUnTillDb.clone("2.59.0"), e.getProblematicMDep());
203-
} else if (e.getRootComp().equals(compUnTill.clone(crbUnTill.getVersion().toPreviousPatch()))) {
203+
} else if (e.getRootComp().equals(compUnTill.clone(env.getUnTillVer().toRelease()))) {
204204
assertEquals(compUnTillDb.clone("2.60.0"), e.getProblematicMDep());
205205
} else {
206-
assertEquals(e.getRootComp(), compUBL.clone(crbUBL.getVersion().toPreviousPatch()));
206+
fail();
207207
}
208208
}
209209
}
@@ -214,7 +214,6 @@ public void testPatchDowngradeException() {
214214

215215
// unTill uses 2.59.0 version of UnTillDb
216216
// make UBL use 2.59.1 version of unTillDb
217-
ReleaseBranchCurrent crbUnTill = ReleaseBranchFactory.getCRB(repoUnTill);
218217
ReleaseBranchCurrent crbUBL = ReleaseBranchFactory.getCRB(repoUBL);
219218
ReleaseBranchCurrent crbUnTillDb = ReleaseBranchFactory.getCRB(repoUnTillDb);
220219
MDepsFile mdf = new MDepsFile(env.getUblVCS().getFileContent(crbUBL.getName(), Constants.MDEPS_FILE_NAME, null));
@@ -230,7 +229,7 @@ public void testPatchDowngradeException() {
230229
} catch (EMinorUpgradeDowngrade e) {
231230
if (e.getRootComp().equals(compUBL.clone(crbUBL.getVersion().toPreviousPatch()))) {
232231
assertEquals(compUnTillDb.clone("2.59.1"), e.getProblematicMDep());
233-
} else if (e.getRootComp().equals(compUnTill.clone(crbUnTill.getVersion().toPreviousPatch()))) {
232+
} else if (e.getRootComp().equals(compUnTill.clone(env.getUnTillVer().toRelease()))) {
234233
assertEquals(compUnTillDb.clone("2.59.0"), e.getProblematicMDep());
235234
} else {
236235
fail();

0 commit comments

Comments
 (0)