Skip to content

Commit

Permalink
Merge pull request #2546 from nextcloud/feat/nextcloud/generate-suppo…
Browse files Browse the repository at this point in the history
…rt-table
  • Loading branch information
provokateurin authored Oct 9, 2024
2 parents fc7b4ed + eba5c60 commit d240d25
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/update_presets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ jobs:
branch: chore/nextcloud_test/update-presets
delete-branch: true
title: "chore(nextcloud_test): Update presets"
body: "Make sure to update the supported apps table if a new preset is added!"
body: |
Make sure to update the supported apps table if a new preset is added!
`git checkout chore/nextcloud_test/update-presets && git commit --amend -s --no-edit && git push -f` locally to trigger the CI.
12 changes: 8 additions & 4 deletions packages/nextcloud/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,21 @@ For an example checkout the [example](https://github.com/nextcloud/neon/blob/mai

## Compatibility/Support policy

[Do not edit manually below]: #

| Component | Supported versions (1) |
|------------------------------------------------------------------------------------|------------------------|
| [Server](https://github.com/nextcloud/server) (2) | 28 - 30 |
| [Cookbook app](https://github.com/nextcloud/cookbook) | 0.11.1 - 0.11.2 |
| [Cookbook app](https://github.com/nextcloud/cookbook) | 0.11 |
| [User account deletion app](https://framagit.org/framasoft/nextcloud/drop_account) | 2.4 - 2.6 |
| [News app](https://github.com/nextcloud/news) | 25 |
| [NextPush app](https://codeberg.org/NextPush/uppush) | 1.4 - 1.5 |
| [Notes app](https://github.com/nextcloud/notes) | 4.8 - 4.11 |
| [Notifications app](https://github.com/nextcloud/notifications) | 28 - 30 |
| [Tables app](https://github.com/nextcloud/tables) | 0.6 - 0.8 |
| [Talk app](https://github.com/nextcloud/spreed) | 18 - 20 |
| [User account deletion app](https://framagit.org/framasoft/nextcloud/drop_account) | 2.4 - 2.6 |
| [Tables app](https://github.com/nextcloud/tables) | 0.6 - 0.8 |
| [NextPush app](https://codeberg.org/NextPush/uppush) | 1.4 - 1.5 |

[Do not edit manually above]: #

1: Other versions might be supported too or at least mostly working, but we do not test against those.
2: Server includes the following apps: comments, core, dashboard, dav, files, files_external, files_reminders, files_sharing, files_trashbin, files_versions, provisioning_api, settings, sharebymail, systemtags, theming, updatenotification, user_ldap, user_status, weather_status, webhook_listeners and WebDAV.
Expand Down
104 changes: 104 additions & 0 deletions packages/nextcloud/generate_support_table.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import 'dart:io';

import 'package:collection/collection.dart';
import 'package:version/version.dart';

final labels = <String, String>{
'server': '[Server](https://github.com/nextcloud/server) (2)',
'cookbook': '[Cookbook app](https://github.com/nextcloud/cookbook)',
'drop_account': '[User account deletion app](https://framagit.org/framasoft/nextcloud/drop_account)',
'news': '[News app](https://github.com/nextcloud/news)',
'notes': '[Notes app](https://github.com/nextcloud/notes)',
'notifications': '[Notifications app](https://github.com/nextcloud/notifications)',
'spreed': '[Talk app](https://github.com/nextcloud/spreed)',
'tables': '[Tables app](https://github.com/nextcloud/tables)',
'uppush': '[NextPush app](https://codeberg.org/NextPush/uppush)',
};

void main() {
var support = <String, ({Version min, Version max})>{};

final dir = Directory('packages/nextcloud_test_presets/docker/presets');
for (final appDir in dir.listSync()) {
if (appDir is! Directory) {
continue;
}

final versions = <Version>[];
for (final presetFile in appDir.listSync()) {
final version = Version.parse(presetFile.uri.pathSegments.last);
versions.add(version);
}
versions.sort();

final app = appDir.uri.pathSegments[appDir.uri.pathSegments.length - 2];
support[app] = (min: versions.first, max: versions.last);
}

support['notifications'] = support['server']!;

support = Map.fromEntries(
support.entries.sorted((a, b) {
if (a.key == 'server') {
return -1;
}
if (b.key == 'server') {
return 1;
}
return a.key.compareTo(b.key);
}),
);

final columns = <String, String>{
'Component': 'Supported versions (1)',
};
for (final entry in support.entries) {
final app = entry.key;
final min = entry.value.min;
final max = entry.value.max;

late String range;
if (min == max) {
range = _formatVersionRemoveTrailingZeros(min);
} else {
range = '${_formatVersionRemoveTrailingZeros(min)} - ${_formatVersionRemoveTrailingZeros(max)}';
}

columns[labels[app]!] = range;
}

final firstColumnWidth = columns.keys.sorted((a, b) => a.length.compareTo(b.length)).last.length;
final secondColumnWidth = columns.values.sorted((a, b) => a.length.compareTo(b.length)).last.length;

final out = StringBuffer();
for (final (index, row) in columns.entries.indexed) {
out.writeln('| ${row.key.padRight(firstColumnWidth)} | ${row.value.padRight(secondColumnWidth)} |');
if (index == 0) {
out.writeln('|${''.padRight(firstColumnWidth + 2, '-')}|${''.padRight(secondColumnWidth + 2, '-')}|');
}
}

final file = File('README.md');
var content = file.readAsStringSync();
content = content.replaceAllMapped(
RegExp(
r'(\[Do not edit manually below]: #\n\n)(.*)(\n\[Do not edit manually above]: #)',
multiLine: true,
dotAll: true,
),
(match) => '${match.group(1)}$out${match.group(3)}',
);
file.writeAsStringSync(content);
}

String _formatVersionRemoveTrailingZeros(Version version) {
if (version.patch == 0 && version.minor == 0) {
return '${version.major}';
}

if (version.patch == 0) {
return '${version.major}.${version.minor}';
}

return '${version.major}.${version.minor}.${version.patch}';
}
1 change: 1 addition & 0 deletions tool/generate-nextcloud.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ cd "$(dirname "$0")/.."
(
cd packages/nextcloud
rm -rf .dart_tool/build/generated/dynamite
fvm dart run generate_support_table.dart
fvm dart run generate_props.dart
fvm dart run build_runner build --delete-conflicting-outputs
fvm dart run generate_exports.dart
Expand Down

0 comments on commit d240d25

Please sign in to comment.