Skip to content

Commit

Permalink
Merge pull request #1314 from nextcloud/feat/nextcloud_test/prefer-un…
Browse files Browse the repository at this point in the history
…stable-releases-over-incompatible
  • Loading branch information
provokateurin authored Dec 18, 2023
2 parents 8974a97 + 0cd3322 commit d135010
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 36 deletions.
2 changes: 1 addition & 1 deletion packages/nextcloud/test/dashboard_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void main() {
final items = response.body.ocs.data['recommendations']!.items;
expect(items, hasLength(7));
},
skip: preset.version.toVersion() < Version(27, 1, 0),
skip: preset.version.getRaw() < Version(27, 1, 0),
);
});
},
Expand Down
48 changes: 24 additions & 24 deletions packages/nextcloud_test/bin/generate_presets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import 'package:nextcloud_test/src/app.dart';
import 'package:nextcloud_test/src/extended_version.dart';
import 'package:universal_io/io.dart';

final versionPattern = RegExp(r'^[0-9]+\.[0-9]+\.[0-9]+$');

Future<void> main() async {
const appIDs = [
'news',
Expand Down Expand Up @@ -38,7 +36,9 @@ Future<void> main() async {
if (a == app) {
buffer.writeln(release.url);
} else {
final release = a.findLatestCompatibleRelease(serverVersion) ?? a.findLatestRelease();
final release = a.findLatestCompatibleRelease(serverVersion) ??
a.findLatestCompatibleRelease(serverVersion, allowUnstable: true) ??
a.findLatestRelease();
buffer.writeln(release.url);
}
}
Expand All @@ -57,7 +57,9 @@ Future<void> main() async {
final buffer = StringBuffer()..writeln('SERVER_VERSION=$serverVersion');

for (final app in apps) {
final release = app.findLatestCompatibleRelease(serverVersion) ?? app.findLatestRelease();
final release = app.findLatestCompatibleRelease(serverVersion) ??
app.findLatestCompatibleRelease(serverVersion, allowUnstable: true) ??
app.findLatestRelease();
buffer.writeln('${app.id.toUpperCase()}_URL=${release.url}');
}

Expand Down Expand Up @@ -91,24 +93,26 @@ Future<List<ExtendedVersion>> _getServerVersions(final HttpClient httpClient) as

final results = data['results'] as List;
for (final result in results) {
final tag = result as Map<String, dynamic>;
try {
final tag = result as Map<String, dynamic>;

final name = tag['name'] as String;
if (!versionPattern.hasMatch(name)) {
continue;
}
final version = ExtendedVersion.parse(name);
final normalizedVersion = version.withoutPatch();
final version = ExtendedVersion.parse(tag['name'] as String);
if (version.minor == null || version.patch == null) {
continue;
}

if (version < coreMinVersion || version.major > core.maxMajor) {
continue;
}
final normalizedVersion = version.withoutPatch();

if (!versions.containsKey(normalizedVersion)) {
versions[normalizedVersion] = version;
} else if (version > versions[normalizedVersion]) {
versions[normalizedVersion] = version;
}
if (version < coreMinVersion || version.major > core.maxMajor) {
continue;
}

if (!versions.containsKey(normalizedVersion)) {
versions[normalizedVersion] = version;
} else if (version > versions[normalizedVersion]) {
versions[normalizedVersion] = version;
}
} catch (_) {}
}
}

Expand Down Expand Up @@ -140,11 +144,7 @@ Future<List<App>> _getApps(final List<String> appIDs, final HttpClient httpClien
for (final releaseItem in releasesItems) {
final release = releaseItem as Map<String, dynamic>;

final versionString = release['version'] as String;
if (!versionPattern.hasMatch(versionString)) {
continue;
}
final version = ExtendedVersion.parse(versionString);
final version = ExtendedVersion.parse(release['version'] as String);
final normalizedVersion = version.withoutPatch();

final rawPlatformVersionSpec = release['rawPlatformVersionSpec'] as String;
Expand Down
2 changes: 1 addition & 1 deletion packages/nextcloud_test/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ RUN curl -L "$SPREED_URL" | tar -xz -C /
FROM nextcloud

COPY --from=news /news /usr/src/nextcloud/apps/news
RUN ./occ app:enable news --force # TODO remove once news supports server 28
RUN ./occ app:enable news

COPY --from=notes /notes /usr/src/nextcloud/apps/notes
RUN ./occ app:enable notes
Expand Down
5 changes: 5 additions & 0 deletions packages/nextcloud_test/docker/presets/news/25.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SERVER_VERSION=28.0.0
NEWS_URL=https://github.com/nextcloud/news/releases/download/25.0.0-alpha2/news.tar.gz
NOTES_URL=https://github.com/nextcloud-releases/notes/releases/download/v4.9.1/notes-v4.9.1.tar.gz
SPREED_URL=https://github.com/nextcloud-releases/spreed/releases/download/v18.0.1/spreed-v18.0.1.tar.gz
UPPUSH_URL=https://codeberg.org/NextPush/uppush/archive/1.4.1.tar.gz
2 changes: 1 addition & 1 deletion packages/nextcloud_test/docker/presets/notes/4.8
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SERVER_VERSION=28.0.0
NEWS_URL=https://github.com/nextcloud/news/releases/download/24.0.0/news.tar.gz
NEWS_URL=https://github.com/nextcloud/news/releases/download/25.0.0-alpha2/news.tar.gz
NOTES_URL=https://github.com/nextcloud-releases/notes/releases/download/v4.8.1/notes.tar.gz
SPREED_URL=https://github.com/nextcloud-releases/spreed/releases/download/v18.0.1/spreed-v18.0.1.tar.gz
UPPUSH_URL=https://codeberg.org/NextPush/uppush/archive/1.4.1.tar.gz
2 changes: 1 addition & 1 deletion packages/nextcloud_test/docker/presets/notes/4.9
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SERVER_VERSION=28.0.0
NEWS_URL=https://github.com/nextcloud/news/releases/download/24.0.0/news.tar.gz
NEWS_URL=https://github.com/nextcloud/news/releases/download/25.0.0-alpha2/news.tar.gz
NOTES_URL=https://github.com/nextcloud-releases/notes/releases/download/v4.9.1/notes-v4.9.1.tar.gz
SPREED_URL=https://github.com/nextcloud-releases/spreed/releases/download/v18.0.1/spreed-v18.0.1.tar.gz
UPPUSH_URL=https://codeberg.org/NextPush/uppush/archive/1.4.1.tar.gz
2 changes: 1 addition & 1 deletion packages/nextcloud_test/docker/presets/server/28.0
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SERVER_VERSION=28.0.0
NEWS_URL=https://github.com/nextcloud/news/releases/download/24.0.0/news.tar.gz
NEWS_URL=https://github.com/nextcloud/news/releases/download/25.0.0-alpha2/news.tar.gz
NOTES_URL=https://github.com/nextcloud-releases/notes/releases/download/v4.9.1/notes-v4.9.1.tar.gz
SPREED_URL=https://github.com/nextcloud-releases/spreed/releases/download/v18.0.1/spreed-v18.0.1.tar.gz
UPPUSH_URL=https://codeberg.org/NextPush/uppush/archive/1.4.1.tar.gz
2 changes: 1 addition & 1 deletion packages/nextcloud_test/docker/presets/spreed/18.0
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SERVER_VERSION=28.0.0
NEWS_URL=https://github.com/nextcloud/news/releases/download/24.0.0/news.tar.gz
NEWS_URL=https://github.com/nextcloud/news/releases/download/25.0.0-alpha2/news.tar.gz
NOTES_URL=https://github.com/nextcloud-releases/notes/releases/download/v4.9.1/notes-v4.9.1.tar.gz
SPREED_URL=https://github.com/nextcloud-releases/spreed/releases/download/v18.0.1/spreed-v18.0.1.tar.gz
UPPUSH_URL=https://codeberg.org/NextPush/uppush/archive/1.4.1.tar.gz
2 changes: 1 addition & 1 deletion packages/nextcloud_test/docker/presets/uppush/1.4
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SERVER_VERSION=28.0.0
NEWS_URL=https://github.com/nextcloud/news/releases/download/24.0.0/news.tar.gz
NEWS_URL=https://github.com/nextcloud/news/releases/download/25.0.0-alpha2/news.tar.gz
NOTES_URL=https://github.com/nextcloud-releases/notes/releases/download/v4.9.1/notes-v4.9.1.tar.gz
SPREED_URL=https://github.com/nextcloud-releases/spreed/releases/download/v18.0.1/spreed-v18.0.1.tar.gz
UPPUSH_URL=https://codeberg.org/NextPush/uppush/archive/1.4.1.tar.gz
6 changes: 4 additions & 2 deletions packages/nextcloud_test/lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ typedef App = ({

@internal
extension AppFindLatestRelease on App {
AppRelease? findLatestCompatibleRelease(final ExtendedVersion serverVersion) {
AppRelease? findLatestCompatibleRelease(final ExtendedVersion serverVersion, {final bool allowUnstable = false}) {
final compatibleReleases = releases
.where(
(final release) =>
serverVersion >= release.minimumServerVersion && serverVersion <= release.maximumServerVersion,
serverVersion >= release.minimumServerVersion &&
serverVersion <= release.maximumServerVersion &&
(allowUnstable || !release.version.getRaw().isPreRelease),
)
.toList()
..sort((final a, final b) => b.version.compareTo(a.version));
Expand Down
16 changes: 13 additions & 3 deletions packages/nextcloud_test/lib/src/extended_version.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,47 @@ final coreMinVersion = ExtendedVersion.fromVersion(core.minVersion);
@internal
class ExtendedVersion implements Comparable<ExtendedVersion> {
const ExtendedVersion(
final Version raw,
this.major,
this.minor,
this.patch,
);
) : _raw = raw;

factory ExtendedVersion.parse(final String versionString) {
final version = Version.parse(versionString);
final dotCount = versionString.split('').where((final char) => char == '.').length;

return ExtendedVersion(
version,
version.major,
dotCount >= 1 ? version.minor : null,
dotCount >= 2 ? version.patch : null,
);
}

factory ExtendedVersion.fromVersion(final Version version) => ExtendedVersion(
version,
version.major,
version.minor,
version.patch,
);

final Version _raw;

final int major;

final int? minor;

final int? patch;

ExtendedVersion withoutPatch() => ExtendedVersion(major, minor, null);
ExtendedVersion withoutPatch() => ExtendedVersion(
_raw,
major,
minor,
null,
);

Version toVersion() => Version(major, minor ?? 0, patch ?? 0);
Version getRaw() => _raw;

@override
String toString() {
Expand Down

0 comments on commit d135010

Please sign in to comment.