Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

distinguish between prerelease strategies again #85

Closed
esz opened this issue Jun 6, 2018 · 1 comment
Closed

distinguish between prerelease strategies again #85

esz opened this issue Jun 6, 2018 · 1 comment
Labels
Milestone

Comments

@esz
Copy link

esz commented Jun 6, 2018

When building from a dirty repo on a commit tagged with a final release, the behavior of the reckoner is inconsistent when using snapshotFromProp().

The following tests (https://github.com/esz/reckon/commit/08ab81d6f092f08e094f203cf149f46c1e067926) reproduce this behavior:

  def 'if building from a dirty repo on a commit tagged with a final version without supplying a stage, the next snapshot is built'() {
    given:
    VcsInventory inventory = new VcsInventory(
      'abcdef',
      false,
      Version.valueOf('2.0.0'),
      Version.valueOf('2.0.0'),
      Version.valueOf('2.0.0'),
      0,
      [] as Set,
      [Version.valueOf('1.0.0'), Version.valueOf('2.0.0')] as Set
    )
    expect:
    reckonSnapshot(inventory, null, null) == '2.1.0-SNAPSHOT'
  }

  def 'if building from a dirty repo on a commit tagged with a final version supplying a "snapshot" stage, the next snapshot is built'() {
    given:
    VcsInventory inventory = new VcsInventory(
      'abcdef',
      false,
      Version.valueOf('2.0.0'),
      Version.valueOf('2.0.0'),
      Version.valueOf('2.0.0'),
      0,
      [] as Set,
      [Version.valueOf('1.0.0'), Version.valueOf('2.0.0')] as Set
    )
    expect:
    reckonSnapshot(inventory, null, 'snapshot') == '2.1.0-SNAPSHOT'
  }

Both tests expect the same result, once supplying the -Preckon.stage=snapshot property and once not. IMHO both tests should yield 2.1.0-SNAPSHOT however the second test fails with "Cannot release a final or significant stage without a clean repo."

This behavior is due to

    if (stage != null && !inventory.isClean()) {
      throw new IllegalStateException("Cannot release a final or significant stage without a clean repo.");
    }

in org.ajoberstar.reckon.core.Reckoner.reckonTargetVersion(VcsInventory, Version)

This makes perfectly sense when using stageFromProp(), since when the user is setting a stage on the CLI this should yield a significant (rc, milestone, beta, whatever..) Version. However, it also causes the inconsistent behavior from above, when using snapshotFromProp()

Fixing this by simply excluding "snapshot" in the condition above is not sufficient, since one never knows if we have stageFromProp('snapshot', ...). Please have a look at the changes in https://github.com/esz/reckon/tree/distinguish_between_prerelease_strategies where I attempted to solve this issue.

I introduced org.ajoberstar.reckon.core.Stages and two implementation which are (or will be) responsible for:

  • keeping track of, which stage is final, significant, insignificant depending on the scheme
  • replacing the Reckoner#stageCalc function
  • performing stage-related sanitychecks and defaults currently implemented by the reckoner (not implemented yet)
    • e.g. checking if the stage supplied by the user is in the range of valid stages
    • determining a default stage if none is provided
    • ...
  • computing the suffix (e.g. ..-rc1.fa7cf732) of the version string (not implemented yet)
@ajoberstar
Copy link
Owner

Thanks for all of the detail and implementation ideas!

I agree with changing the behavior you see in the tests. As for how to do it, I think there are smaller changes that would get us there:

  • In Reckoner$Builder#stages() fail if SNAPSHOT_STAGE is included in the list. Snapshots aren't really valid with other stages given the sorting implications.
  • Move the existing stage != null && !inventory.isClean() validation from reckonTargetVersion() to reckon() where most of the other validation is. In that location, you could leverage methods on Version to more cleanly test for this: reckoned.isSignificant() && !inventory.isClean().

@ajoberstar ajoberstar added the bug label Jun 6, 2018
@ajoberstar ajoberstar added this to the 0.8.0 milestone Jun 16, 2018
ajoberstar added a commit that referenced this issue Jul 4, 2018
This is an unintended usage, so we want it to fail.

This is related to #85.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants