halkyon/test/release/version_test.dart
Tizian 「ティツィアーン」 e65f61bdd1
build(release): a Dart release tool for every app
tool/release.dart releases one app: `dart run tool/release.dart learn
[major | minor | patch] [--dry-run]`, each app configured in Dart beside
it (apps/learn/release.dart). Every step and check of tool/release.sh
is kept: the repository as pushed, resuming after a release commit and
tag, Flutter as CI pins it, the tools, the key and its certificate pin,
secrets asked for without echo and never written down, CI green on the
newest commit, the signed release commit and tag by a key deploys
accept, the APK built from a checkout of the tag and checked, the snap,
the signed checksums, pushing only after both builds passed, the
release on Forgejo, the F-Droid repository, the Snap Store once a
channel is set.

New: tags per app (learn-v0.19.0, Learn's v… counting as its
history); only commits touching the app decide its version (its folder,
the shared packages it uses by path, the root pubspec and lock, its
release files, where its packages were before the move); --dry-run
reads all of it, lists every step and the notes, and what a release
would refuse, changing nothing. The pure parts are tested in
test/release/. Learn releases build 21 with tool/release.sh, then
switches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-10-22 18:11:05 +02:00

88 lines
2.8 KiB
Dart

import 'package:test/test.dart';
import '../../tool/src/release/version.dart';
void main() {
Commit commit(String subject, [String body = '']) =>
Commit(hash: 'c0ffee', subject: subject, body: body);
group('a version', () {
test('reads as semantic versioning writes it, and nothing else', () {
expect(Version.tryParse('0.17.0'), const Version(0, 17, 0));
expect(Version.tryParse('1.2.3')?.toString(), '1.2.3');
for (final text in [
'1.2',
'1.2.3.4',
'v1.2.3',
'1.2.3-beta',
'',
'x.y.z',
]) {
expect(Version.tryParse(text), isNull, reason: text);
}
});
test('is raised by one part, the parts after it starting again', () {
const version = Version(1, 4, 2);
expect(version.bumped(Bump.major), const Version(2, 0, 0));
expect(version.bumped(Bump.minor), const Version(1, 5, 0));
expect(version.bumped(Bump.patch), const Version(1, 4, 3));
});
test("is read with its build from a pubspec's version line", () {
expect(declaredVersion('name: x\nversion: 0.17.0+20\n'), (
const Version(0, 17, 0),
20,
));
expect(declaredVersion('name: x\nversion: 0.17.0\n'), isNull);
expect(declaredVersion('name: x\n'), isNull);
});
});
group('the commits since the last release', () {
const beforeOne = Version(0, 17, 0);
const afterOne = Version(1, 2, 0);
test('a feature raises the minor number, a fix or speed-up the patch', () {
expect(bumpFor(beforeOne, [commit('feat(study): x')]), Bump.minor);
expect(bumpFor(beforeOne, [commit('feat: x')]), Bump.minor);
expect(bumpFor(beforeOne, [commit('fix(sync): x')]), Bump.patch);
expect(bumpFor(beforeOne, [commit('perf: x')]), Bump.patch);
expect(
bumpFor(beforeOne, [commit('fix: x'), commit('feat(app): y')]),
Bump.minor,
);
});
test('a breaking change raises the major number from 1.0 on, the minor '
'one before', () {
expect(bumpFor(afterOne, [commit('refactor(auth)!: x')]), Bump.major);
expect(bumpFor(beforeOne, [commit('refactor(auth)!: x')]), Bump.minor);
expect(
bumpFor(afterOne, [
commit('docs: x', 'Why.\n\nBREAKING CHANGE: older apps stop.'),
]),
Bump.major,
);
// Only at a line's start does it count.
expect(
bumpFor(afterOne, [commit('docs: x', 'No BREAKING CHANGE: here.')]),
isNull,
);
});
test('other types release nothing by themselves', () {
expect(
bumpFor(beforeOne, [
commit('docs: x'),
commit('chore(release): learn-v0.18.0'),
commit('build: y'),
commit('Merge branch z'),
commit('halkyon_app: an untyped subject'),
]),
isNull,
);
expect(bumpFor(beforeOne, const []), isNull);
});
});
}