Skip to content

Commit

Permalink
Merge pull request #116 from logantracyo/master
Browse files Browse the repository at this point in the history
Fix consistent typo throughout; fixes pull request #115
  • Loading branch information
mockitoguy authored Jul 20, 2022
2 parents 0432d9a + 6a21637 commit a7fbe40
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Encourage and help software developers set up their releases to be fully automat

# shipkit-auto-version Gradle Plugin

Our Gradle plugin ```shipkit-auto-version``` deducts the version for the Gradle project to streamline automation and continuous delivery of your code.
Our Gradle plugin ```shipkit-auto-version``` deduces the version for the Gradle project to streamline automation and continuous delivery of your code.
The idea is to infer the version from tags or from an optional `version.properties` file with a version spec like `1.0.*`.
This way, you don't need to do any "version bump" commits in every release!
This project is inspired on [Axion plugin](https://github.com/allegro/axion-release-plugin), and few others, listed later in this document.
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/shipkit/auto/version/AutoVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ class AutoVersion {
}

/**
* Deduct version based on existing tags (will run 'git tag'), and the version spec from versionFile field.
* Deduce version based on existing tags (will run 'git tag'), and the version spec from versionFile field.
*
* @param projectVersion the version of the gradle project before running the plugin
*/
DeductedVersion deductVersion(String projectVersion) {
return deductVersion(LOG, projectVersion);
DeducedVersion deduceVersion(String projectVersion) {
return deduceVersion(LOG, projectVersion);
}

//Exposed for testing so that 'log' can be mocked
DeductedVersion deductVersion(Logger log, String projectVersion) {
DeducedVersion deduceVersion(Logger log, String projectVersion) {
Optional<VersionNumber> previousVersion = Optional.empty();
VersionConfig config = VersionConfig.parseVersionFile(versionFile);

Expand All @@ -59,13 +59,13 @@ DeductedVersion deductVersion(Logger log, String projectVersion) {

logPreviousVersion(log, previousVersion);

return new DeductedVersion(nextVersion, previousVersion, config.getTagPrefix());
return new DeducedVersion(nextVersion, previousVersion, config.getTagPrefix());
} catch (Exception e) {
String message = "caught an exception, falling back to reasonable default";
log.debug("shipkit-auto-version " + message, e);
String v = config.getVersionSpec().orElse("0.0.1-SNAPSHOT").replace("*", "unspecified");
explainVersion(log, v, message + "\n - run with --debug for more info");
return new DeductedVersion(v, previousVersion, config.getTagPrefix());
return new DeducedVersion(v, previousVersion, config.getTagPrefix());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class AutoVersionPlugin implements Plugin<Project> {

public void apply(Project project) {
DeductedVersion version = new AutoVersion(project.getProjectDir()).deductVersion(project.getVersion().toString());
DeducedVersion version = new AutoVersion(project.getProjectDir()).deduceVersion(project.getVersion().toString());
project.allprojects(p -> p.setVersion(version.getVersion()));
project.getExtensions().getExtraProperties().set("shipkit-auto-version.previous-version", version.getPreviousVersion());
project.getExtensions().getExtraProperties().set("shipkit-auto-version.previous-tag", version.getPreviousTag());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
import java.util.Optional;

/**
* Value object representing the deducted version
* Value object representing the deduced version
*/
class DeductedVersion {
class DeducedVersion {

private final String version;
private final String previousVersion;
private final String previousTag;

DeductedVersion(String version, Optional<VersionNumber> previousVersion, String tagPrefix) {
DeducedVersion(String version, Optional<VersionNumber> previousVersion, String tagPrefix) {
Objects.requireNonNull(version, "version cannot be null");
this.version = version;
this.previousVersion = previousVersion.map(VersionNumber::toString).orElse(null);
this.previousTag = previousVersion.map(v -> TagConvention.tagFor(v.toString(), tagPrefix)).orElse(null);
}

/**
* Deducted version, never null.
* Deduced version, never null.
*/
String getVersion() {
return version;
Expand Down Expand Up @@ -50,4 +50,4 @@ String getPreviousVersion() {
String getPreviousTag() {
return previousTag;
}
}
}
6 changes: 3 additions & 3 deletions src/main/java/org/shipkit/auto/version/NextVersionPicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ String pickNextVersion(Optional<VersionNumber> previousVersion, VersionConfig co

if (isSupportedVersion(tag, config.getTagPrefix())) {
result = tag.substring(config.getTagPrefix().length());
explainVersion(log, result, "deducted version based on tag: '" + tag + "'");
explainVersion(log, result, "deduced version based on tag: '" + tag + "'");
} else if (isSnapshot(tag, config.getTagPrefix())) {
Pattern pattern = Pattern.compile("\\d+\\.\\d+\\.\\d+(\\.\\d+)?");
Matcher matcher = pattern.matcher(tag);
matcher.find();
result = new VersionNumber(matcher.group()).incrementBy(1).toString() + "-SNAPSHOT";
explainVersion(log, result,
"deducted snapshot based on tag: '" + config.getTagPrefix() + matcher.group() + "'");
"deduced snapshot based on tag: '" + config.getTagPrefix() + matcher.group() + "'");
} else {
result = "0.0.1-SNAPSHOT";
explainVersion(log, result, "found no version property and the code is not checked out on a valid tag");
Expand All @@ -76,7 +76,7 @@ String pickNextVersion(Optional<VersionNumber> previousVersion, VersionConfig co
"git", "log", "--pretty=oneline", TagConvention.tagFor(prev.toString(), config.getTagPrefix()) + "..HEAD");
int commitCount = new CommitCounter().countCommitDelta(gitOutput);
String result = prev.incrementBy(commitCount).toString();
explainVersion(log, result, "deducted version based on previous tag: '" + prev + "'");
explainVersion(log, result, "deduced version based on previous tag: '" + prev + "'");
return result;
} else {
String result = config.newPatchVersion();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/shipkit/auto/version/VersionConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ static boolean isSupportedVersion(String version) {
}

/**
* Informs if given tag is supported and if snapshot can be deducted
* Informs if given tag is supported and if snapshot can be deduced
* as the tag is not an annotated tag
*
* @return true for tags like 'v1.0.0-1-sha1234', '2.33.444-15-dgo4d29u'
Expand Down
12 changes: 6 additions & 6 deletions src/test/groovy/org/shipkit/auto/version/AutoVersionTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class AutoVersionTest extends TmpFolderSpecification {
runner.run("git", "tag") >> "v1.0.1"

when:
def v = autoVersion.deductVersion(log, Project.DEFAULT_VERSION)
def v = autoVersion.deduceVersion(log, Project.DEFAULT_VERSION)

then:
v.version == "1.1.0"
Expand All @@ -36,19 +36,19 @@ class AutoVersionTest extends TmpFolderSpecification {
runner.run("git", "describe", "--tags") >> "v1.0.5"

when:
def v = autoVersion.deductVersion(log, Project.DEFAULT_VERSION)
def v = autoVersion.deduceVersion(log, Project.DEFAULT_VERSION)

then:
v.version == "1.0.5"
v.previousVersion == "1.0.4"
}

def "no build failure when deducting versions fails"() {
def "no build failure when deducing versions fails"() {
versionFile << "version=1.0.*"
runner.run("git", "tag") >> "v1.0.1"

when:
def v = autoVersion.deductVersion(log, Project.DEFAULT_VERSION)
def v = autoVersion.deduceVersion(log, Project.DEFAULT_VERSION)

then:
v.version == "1.0.unspecified"
Expand All @@ -59,13 +59,13 @@ class AutoVersionTest extends TmpFolderSpecification {
" - run with --debug for more info")
}

def "no build failure when no version config present and deducting versions fails"() {
def "no build failure when no version config present and deducing versions fails"() {
runner.run("git", "tag") >> {
throw new Exception()
}

when:
def v = autoVersion.deductVersion(log, Project.DEFAULT_VERSION)
def v = autoVersion.deduceVersion(log, Project.DEFAULT_VERSION)

then:
v.version == "0.0.1-SNAPSHOT"
Expand Down
19 changes: 19 additions & 0 deletions src/test/groovy/org/shipkit/auto/version/DeducedVersionTest.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.shipkit.auto.version

import spock.lang.Specification

class DeducedVersionTest extends Specification {

def "previous version"() {
expect:
"0.0.9" == new DeducedVersion("1.0.0", Optional.of(new VersionNumber("0.0.9")), "v").previousVersion
null == new DeducedVersion("1.0.0", Optional.empty(), "v").previousVersion
}

def "previous tag"() {
expect:
"v0.0.9" == new DeducedVersion("1.0.0", Optional.of(new VersionNumber("0.0.9")), "v").previousTag
"0.0.9" == new DeducedVersion("1.0.0", Optional.of(new VersionNumber("0.0.9")), "").previousTag
null == new DeducedVersion("1.0.0", Optional.empty(), "v").previousTag
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ some commit #2
then:
v == "1.0.2"
1 * log.lifecycle("Building version '1.0.2'\n" +
" - reason: shipkit-auto-version deducted version based on previous tag: '1.0.0'")
" - reason: shipkit-auto-version deduced version based on previous tag: '1.0.0'")
}

def "picks version when no tag prefix"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class VersionConfigTest extends TmpFolderSpecification {
'v1.0.0-rc' | 'v' | false
}

def "tags are not annotated and snapshots can be deducted"() {
def "tags are not annotated and snapshots can be deduced"() {
expect:
isSnapshot(tag, tagPrefix) == result

Expand Down

0 comments on commit a7fbe40

Please sign in to comment.