Skip to content

Commit

Permalink
feat(changelog): prepare and show changelog on pre-release builds
Browse files Browse the repository at this point in the history
  • Loading branch information
JagandeepBrar committed Jul 9, 2022
1 parent d91cb05 commit df65f53
Show file tree
Hide file tree
Showing 18 changed files with 202 additions and 115 deletions.
20 changes: 5 additions & 15 deletions .github/workflows/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ name: Prepare
on:
workflow_call:
inputs:
changelog:
type: string
required: true
flavor:
type: string
required: true
Expand Down Expand Up @@ -53,12 +50,6 @@ jobs:
COUNT=`git rev-list HEAD --count`
echo "::set-output name=commit-count::$COUNT"
- name: Latest Commit Message
id: commit-message
run: |
MESSAGE=`git show -s --format=%s`
echo "::set-output name=commit-message::$MESSAGE"
- name: Build Flavor
id: build-flavor
uses: actions/github-script@v6
Expand All @@ -81,15 +72,10 @@ jobs:
id: build-changelog
uses: actions/github-script@v6
env:
CHANGELOG: ${{ inputs.changelog }}
FLAVOR: ${{ steps.build-flavor.outputs.result }}
COMMIT: ${{ steps.commit-message.outputs.commit-message }}
with:
result-encoding: string
script: |
if (process.env.CHANGELOG) return process.env.CHANGELOG;
if (process.env.FLAVOR === 'edge') return process.env.COMMIT || 'No Documented Changes';
throw new Error('This flavor requires a changelog.');
script: return `Thank you for testing ${process.env.FLAVOR} release builds!\n\nAll changes can be found within the application.`;

- name: Build Number
id: build-number
Expand Down Expand Up @@ -150,6 +136,9 @@ jobs:
- name: Generate Localization
run: dart ${{github.workspace }}/scripts/generate_localization.dart

- name: Generate Changelog
run: dart ${{github.workspace }}/scripts/generate_changelog.dart ${{ needs.build-details.outputs.build-flavor }}

- name: Generate Build Runner Files
run: flutter packages pub run build_runner build

Expand All @@ -158,6 +147,7 @@ jobs:
with:
name: core-files
path: |
${{ github.workspace }}/assets/changelog.json
${{ github.workspace }}/assets/localization
${{ github.workspace }}/lib/**/*.g.dart
${{ github.workspace }}/lib/system/environment.dart
6 changes: 0 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,13 @@ on:
- beta
- candidate
- stable
changelog:
description: Custom Release Changelog
required: false
default: ''
type: string

jobs:
prepare:
name: Prepare
uses: JagandeepBrar/LunaSea/.github/workflows/prepare.yml@master
with:
flavor: ${{ inputs.flavor }}
changelog: ${{ inputs.changelog }}
secrets:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}

Expand Down
27 changes: 0 additions & 27 deletions assets/changelog_example.json

This file was deleted.

1 change: 1 addition & 0 deletions assets/changelog_stable.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
2 changes: 2 additions & 0 deletions assets/localization/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"lunasea.Changelog": "Changelog",
"lunasea.ChangeProfiles": "Change Profiles",
"lunasea.CheckLogsMessage": "Check the logs for more details",
"lunasea.Chores": "Chores",
"lunasea.Clear": "Clear",
"lunasea.Close": "Close",
"lunasea.ComingSoon": "Coming Soon",
Expand All @@ -52,6 +53,7 @@
"lunasea.Disable": "Disable",
"lunasea.Disabled": "Disabled",
"lunasea.Dismiss": "Dismiss",
"lunasea.Docs": "Docs",
"lunasea.Edge": "Edge",
"lunasea.Error": "Error",
"lunasea.ExternalModules": "External Modules",
Expand Down
2 changes: 1 addition & 1 deletion lib/database/tables/lunasea.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ enum LunaSeaDatabase<T> with LunaTableMixin<T> {
USE_24_HOUR_TIME<bool>(false),
DEFAULT_LAUNCH_MODULE<LunaModule>(LunaModule.DASHBOARD),
ENABLE_IN_APP_NOTIFICATIONS<bool>(true),
CHANGELOG_LAST_BUILD<String>('0.0.0');
CHANGELOG_LAST_BUILD_VERSION<int>(0);

@override
LunaTable get table => LunaTable.lunasea;
Expand Down
9 changes: 3 additions & 6 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import 'package:lunasea/modules/dashboard/routes/dashboard/route.dart'
show HomeRouter;
import 'package:lunasea/system/build.dart';
import 'package:lunasea/system/cache/image/image_cache.dart';
import 'package:lunasea/system/flavor.dart';
import 'package:lunasea/system/in_app_purchase/in_app_purchase.dart';
import 'package:lunasea/system/localization.dart';
import 'package:lunasea/system/network/network.dart';
Expand Down Expand Up @@ -129,11 +128,9 @@ class _State extends State<LunaOS> {
}

Future<void> _healthCheck() async {
if (LunaFlavor.isStable) {
LunaBuild().isLatestBuildVersion().then((isLatest) {
if (!isLatest.item1) ChangelogSheet().show();
});
}
LunaBuild().isLatestBuildVersion().then((isLatest) {
if (!isLatest.item1) ChangelogSheet().show();
});
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,7 @@ class _State extends ConsumerState<BuildDetails> {
return LunaButton.text(
icon: LunaIcons.CHANGELOG,
text: 'lunasea.Changelog'.tr(),
onTap: () async {
if (LunaFlavor.isStable) {
return ChangelogSheet().show();
}
return LunaBuild().openCommitHistory();
},
onTap: ChangelogSheet().show,
);
}

Expand Down
50 changes: 17 additions & 33 deletions lib/system/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ class LunaBuild {
return commit.substring(0, min(7, commit.length));
}

Future<void> openCommitHistory() async {
const commit = LunaEnvironment.commit;
String _base = 'https://github.com/JagandeepBrar/LunaSea/commits';
return '$_base/$commit'.openLink();
String getCommitUrl(
String commit, {
bool fullHistory = false,
}) {
final location = fullHistory ? 'commits' : 'commit';
return 'https://github.com/JagandeepBrar/LunaSea/$location/$commit';
}

Future<void> openCommitHistory({String? commit}) async {
return getCommitUrl(LunaEnvironment.commit, fullHistory: true).openLink();
}

Future<Tuple2<bool, int?>> isLatestBuildNumber() async {
Expand All @@ -34,36 +40,14 @@ class LunaBuild {
return const Tuple2(false, null);
}

Future<Tuple2<bool, String?>> isLatestBuildVersion() async {
List<int> _parse(String v) =>
v.split('.').map((s) => int.parse(s)).toList();

try {
const database = LunaSeaDatabase.CHANGELOG_LAST_BUILD;
final package = (await PackageInfo.fromPlatform()).version;

final currentVersion = _parse(database.read());
final runningVersion = _parse(package);

bool isLatest = true;
if (runningVersion[0] != currentVersion[0]) {
isLatest = false;
} else if (runningVersion[1] != currentVersion[1]) {
isLatest = false;
} else if (runningVersion[2] != currentVersion[2]) {
isLatest = false;
}
Future<Tuple2<bool, int>> isLatestBuildVersion() async {
const database = LunaSeaDatabase.CHANGELOG_LAST_BUILD_VERSION;
const build = LunaEnvironment.build;

database.update(package);
return Tuple2(isLatest, package);
} catch (error, stack) {
LunaLogger().error(
'Failed to check if running latest build version',
error,
stack,
);
}
bool isLatest = true;
if (build > database.read()) isLatest = false;

return const Tuple2(false, null);
database.update(build);
return Tuple2(isLatest, build);
}
}
4 changes: 4 additions & 0 deletions lib/system/flavor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ enum LunaFlavor {
}

static LunaFlavor get current => LunaFlavor.fromKey(LunaEnvironment.flavor);

static bool get isEdge => current == LunaFlavor.EDGE;
static bool get isBeta => current == LunaFlavor.BETA;
static bool get isCandidate => current == LunaFlavor.CANDIDATE;
static bool get isStable => current == LunaFlavor.STABLE;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/utils/changelog/change.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ part 'change.g.dart';
@JsonSerializable()
class Change {
@JsonKey()
String module;
String commit;

@JsonKey()
List<String> changes;
String message;

Change({
required this.module,
required this.changes,
required this.commit,
required this.message,
});

@override
Expand Down
14 changes: 11 additions & 3 deletions lib/utils/changelog/changelog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,28 @@ class Changelog {
@JsonKey()
String? motd;

@JsonKey(name: 'new')
@JsonKey(name: 'feat')
List<Change>? feat;

@JsonKey(name: 'tweaks')
@JsonKey(name: 'refactor')
List<Change>? tweaks;

@JsonKey(name: 'fixes')
@JsonKey(name: 'fix')
List<Change>? fixes;

@JsonKey(name: 'docs')
List<Change>? docs;

@JsonKey(name: 'chore')
List<Change>? chores;

Changelog({
this.motd,
this.feat,
this.tweaks,
this.fixes,
this.docs,
this.chores,
});

@override
Expand Down
45 changes: 36 additions & 9 deletions lib/utils/changelog/sheet.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'package:flutter/material.dart';
import 'package:lunasea/deprecated/state/state.dart';
import 'package:lunasea/extensions/string/string.dart';
import 'package:lunasea/system/build.dart';
import 'package:lunasea/system/environment.dart';
import 'package:lunasea/system/flavor.dart';
import 'package:lunasea/system/logger.dart';
import 'package:lunasea/utils/links.dart';
import 'package:lunasea/vendor.dart';
Expand All @@ -9,6 +12,8 @@ import 'package:lunasea/utils/changelog/changelog.dart';
import 'package:lunasea/widgets/ui.dart';

class ChangelogSheet extends LunaBottomModalSheet {
static final _defaultMOTD =
'Welcome to LunaSea!\n\nThank you for testing ${LunaFlavor.current.key} release builds! Please see below for all documented changes found in this release.';
late Changelog _changelog;
late String _version;

Expand All @@ -17,11 +22,9 @@ class ChangelogSheet extends LunaBottomModalSheet {
Widget Function(BuildContext context)? builder,
}) async {
try {
final context = LunaState.navigatorKey.currentContext!;
_version = await PackageInfo.fromPlatform().then((v) => v.version);
_changelog = await DefaultAssetBundle.of(context)
.loadString('assets/changelog.json')
.then((c) => Changelog.fromJson(json.decode(c)));
await _loadChangelog();

return this.showModal(builder: builder);
} catch (error, stack) {
LunaLogger().error(
Expand All @@ -32,13 +35,25 @@ class ChangelogSheet extends LunaBottomModalSheet {
}
}

Future<void> _loadChangelog() async {
final context = LunaState.navigatorKey.currentContext!;
final asset = LunaFlavor.isStable
? 'assets/changelog_stable.json'
: 'assets/changelog.json';

_changelog = await DefaultAssetBundle.of(context)
.loadString(asset)
.then((c) => Changelog.fromJson(json.decode(c)));
}

@override
Widget builder(BuildContext context) {
final showDefaultMOTD = _changelog.motd?.isEmpty ?? true;
return LunaListViewModal(
children: [
LunaHeader(
text: _version,
subtitle: _changelog.motd ?? 'Welcome to LunaSea!',
text: '$_version (${LunaEnvironment.build})',
subtitle: showDefaultMOTD ? _defaultMOTD : _changelog.motd,
),
..._buildChangeBlock(
'lunasea.New'.tr(),
Expand All @@ -52,14 +67,26 @@ class ChangelogSheet extends LunaBottomModalSheet {
'lunasea.Fixes'.tr(),
_changelog.fixes,
),
if (LunaFlavor.isEdge)
..._buildChangeBlock(
'lunasea.Chores'.tr(),
_changelog.chores,
),
if (LunaFlavor.isEdge)
..._buildChangeBlock(
'lunasea.Docs'.tr(),
_changelog.docs,
),
const SizedBox(height: LunaUI.DEFAULT_MARGIN_SIZE / 2),
],
actionBar: LunaBottomActionBar(
actions: [
LunaButton.text(
text: 'lunasea.FullChangelog'.tr(),
icon: Icons.track_changes_rounded,
onTap: LunaLinkedContent.CHANGELOG.launch,
onTap: LunaFlavor.isStable
? LunaLinkedContent.CHANGELOG.launch
: LunaBuild().openCommitHistory,
),
],
),
Expand All @@ -74,8 +101,8 @@ class ChangelogSheet extends LunaBottomModalSheet {
content: List<LunaTableContent>.generate(
changes.length,
(i) => LunaTableContent(
title: changes[i].module,
body: changes[i].changes.map((s) => s.bulleted()).join('\n'),
body: changes[i].message.bulleted(),
url: LunaBuild().getCommitUrl(changes[i].commit),
),
),
),
Expand Down

0 comments on commit df65f53

Please sign in to comment.