Skip to content

Commit

Permalink
fix: version ordering by semver instead of date
Browse files Browse the repository at this point in the history
We also remove SemverException since we fixed the v1.9.2b issue.
(By renaming to v1.9.2-beta.2)
  • Loading branch information
raoulvdberge committed Dec 24, 2023
1 parent 72b82e8 commit a413f4e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 35 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- Fixed release version ordering.

## [0.2.1] - 2023-12-24

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Builder
@Getter
@ToString(exclude = "pagesPath")
public class Component {
private final String name;
private final boolean root;
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/refinedmods/refinedsites/model/Site.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

import com.vdurmont.semver4j.Semver;
import lombok.Getter;
import lombok.ToString;

@ToString(exclude = "componentsByName")
public class Site {
@Getter
private final String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.stream.Stream;

import com.vdurmont.semver4j.Semver;
import com.vdurmont.semver4j.SemverException;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
Expand All @@ -38,28 +37,22 @@ class GithubComponentFactory implements ComponentFactory {
log.warn("Ignoring tag {}", tagName);
continue;
}
final Semver version;
try {
version = new Semver(tagName.substring(1));
} catch (SemverException e) {
log.warn("Invalid semver version detected {}", tagName.substring(1), e);
continue;
}
final Semver version = new Semver(tagName.substring(1));
if (version.isGreaterThanOrEqualTo(minVersion)) {
log.info("Found valid version {}", version);
validTags.add(new Tag(
tagName,
version.getValue(),
"v" + version.getValue(),
false
tagName,
version.getValue(),
"v" + version.getValue(),
false
));
}
}
validTags.add(new Tag(
config.getSnapshotBranch(),
"snapshot",
"snapshot",
true
config.getSnapshotBranch(),
"snapshot",
"snapshot",
true
));
} catch (IOException e) {
throw new RuntimeException(e);
Expand All @@ -74,23 +67,23 @@ public Stream<Component> getComponents() {
log.info("Cloning version {} into {}", validTag, path);
try {
Git.cloneRepository()
.setURI(repo.getHtmlUrl().toString())
.setDirectory(rootPath.resolve(path).toFile())
.setBranch(validTag.tagName())
.setDepth(1)
.call();
.setURI(repo.getHtmlUrl().toString())
.setDirectory(rootPath.resolve(path).toFile())
.setBranch(validTag.tagName())
.setDepth(1)
.call();
} catch (GitAPIException e) {
throw new RuntimeException(e);
}
final LocalComponentFactory factory = new LocalComponentFactory(
rootPath.resolve(path),
name,
false,
new Version(
validTag.version,
validTag.friendlyVersion,
validTag.snapshot
)
rootPath.resolve(path),
name,
false,
new Version(
validTag.version,
validTag.friendlyVersion,
validTag.snapshot
)
);
components.addAll(factory.getComponents().toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
Expand All @@ -27,6 +26,7 @@

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.vdurmont.semver4j.Semver;
import lombok.AllArgsConstructor;

@AllArgsConstructor
Expand Down Expand Up @@ -85,7 +85,11 @@ private Releases getReleases(final String componentName, final ReleaseConfig rel
final List<Release> releases = sourceDataByName.entrySet()
.stream()
.map(entry -> new Release(entry.getKey(), entry.getValue()))
.sorted(Comparator.comparing(Release::getCreatedAt))
.sorted((a, b) -> {
final Semver sa = new Semver(a.getName().substring(1));
final Semver sb = new Semver(b.getName().substring(1));
return sa.compareTo(sb);
})
.toList();
return new Releases(indexedAt, releases, componentName, Stats.of(sourceData));
}
Expand Down

0 comments on commit a413f4e

Please sign in to comment.