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

Add feature to use version from annotated tag #76

Merged
merged 2 commits into from
May 8, 2021

Conversation

shestee
Copy link
Contributor

@shestee shestee commented May 6, 2021

Previous plugin behaviour didn't allow missing version.properties file nor empty version property in the file. This commit adds a behaviour that allows such configuration and deducts version from tag that code is checked out on.
This functionality is useful for teams that prefer releasing "on demand" and also allows increasing version number as needed, not based on number of commits pushed as in default behaviour with version property set. To use this new simplified behaviour no other configuration option than missing version is needed.

As said implemented feature deducts version based on tag on which a code is checked out. If the tag is valid (has same prefix as configured or default 'v' and version number is valid) deducted version is same as version in tag. If other tags that are valid are found, previousVersion which is exposed by the plugin, is a version with highest number less than deducted version (eg. for tag v1.1.5 plugin deducts version number 1.1.5 and assuming that tag v1.1.4 exists, exposed previousVersion is 1.1.4). If code is not checked out on a valid tag and version is not set as property the plugin deducts version 0.0.1.

To implement this behaviour getter for requestedVersion() in 'VersionConfig class was added, and it returns Optional, which is tested in NextVersionPicker and PreviousVersionFinder classes for containing a value, and further logic in these classes is based upon this check for requestedVersion. Also deductVersion() method in AutoVersion checks if requestedVersion is found in configuration, and if not previousVersion is being found using newly deducted version which is passed as argument to findPreviousVersion().
New behaviour is tested by two new unit tests in NextVersionPickerTest, two tests ("no file" and "missing version property") refactored in VersionConfigTest and was also tested manually by building test project with various configuration options.

This PR resolves #1

Previous plugin behaviour didn't allow missing 'version.properties' file
nor empty 'version' property in the file. This commit adds a behaviour that
allows such configuration and deducts version from tag that code is checked out
on.
This functionality is useful for teams that prefer releasing 'on demand'
and also allows increasing version number as needed, not based on number of
commits pushed as in default behaviour with 'version' property set. To use this
new simplified behaviour no other configuration option than missing 'version'
is needed.
@shestee shestee requested a review from mockitoguy May 6, 2021 11:51
String nextVersion = new NextVersionPicker(runner, log).pickNextVersion(previousVersion,
config, projectVersion);

if (!config.getRequestedVersion().isPresent()) {
previousVersion = previousVersionFinder.findPreviousVersion(versions, new VersionConfig(nextVersion, config.getTagPrefix()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we cover this condition in the unit test?

result = matcher.group().substring(config.getTagPrefix().length());
explainVersion(log, result, "deducted version based on tag: '" + config.getTagPrefix() + result + "'");
} else {
result = "0.0.1";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get this code branch covered in the unit test?

throw new ShipkitAutoVersionException(
"Please create file 'version.properties' with a valid 'version' property, " +
"for example 'version=1.0.*'", e);
System.out.println("[shipkit-auto-version] Ignoring file '" + versionFile.getName()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's follow up with a little clean up for this, but let's not block this PR for this edge case.

" Correct examples: 'version=1.0.*', 'version=2.10.100'");
String v;
if (p.containsKey("version") && p.get("version").toString().trim().equals("")) {
v = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this code branch is not covered by unit test

Copy link
Contributor

@mockitoguy mockitoguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! Looks great, please consider my feedback! Can you link the issue ticket to the PR description?

Increased code coverage of new feature that allows using version from annotated tag.
@shestee
Copy link
Contributor Author

shestee commented May 8, 2021

Thank you @mockitoguy for your review! I added some unit tests to increase code coverage as you requested.

@mockitoguy mockitoguy marked this pull request as ready for review May 8, 2021 21:31
@mockitoguy
Copy link
Contributor

Looks great, thank you!!!

@mockitoguy mockitoguy merged commit 04d9944 into shipkit:master May 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use version from annotated tag
2 participants