Skip to content

Commit

Permalink
Fixed git error, converted script to ps1 and added log file
Browse files Browse the repository at this point in the history
  • Loading branch information
KiritoDv committed Jun 4, 2024
1 parent 705c17d commit 52490cd
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
cache: true
cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:' # optional, change this to force refresh cache
cache-path: '${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch:' # optional, change this to specify the cache path
- run: ./build.bat
- run: ./build.ps1
- run: flutter config --enable-windows-desktop
- run: flutter build windows --release
- uses: actions/upload-artifact@v3
Expand Down
12 changes: 0 additions & 12 deletions build.bat

This file was deleted.

10 changes: 10 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Remove-Item -Force lib/auto/build.dart
New-Item -ItemType File -Path lib/auto/build.dart

$BRANCH = git rev-parse --abbrev-ref HEAD
$COMMIT_HASH = git rev-parse --short HEAD
$COMMIT_DATE = git show -s --format=%ci

"const String branch = '$BRANCH';" | Out-File -FilePath lib/auto/build.dart -Encoding utf8
"const String commitHash = '$COMMIT_HASH';" | Out-File -FilePath lib/auto/build.dart -Encoding utf8 -Append
"const String commitDate = '$COMMIT_DATE';" | Out-File -FilePath lib/auto/build.dart -Encoding utf8 -Append
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
rm -f lib/auto/build.dart
touch lib/auto/build.dart
BRANCH=$(git rev-parse --abbrev-ref HEAD)
COMMIT_HASH=$(git rev-parse HEAD)
COMMIT_HASH=$(git rev-parse --short HEAD)
COMMIT_DATE=$(git show -s --format=%ci)

echo "const String branch = '$BRANCH';" > lib/auto/build.dart
Expand Down
6 changes: 3 additions & 3 deletions lib/auto/build.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const String branch = './build.sh to generate this file';
const String commitHash = 'Run';
const String commitDate = '0000000000';
const String branch = 'v0.2.0';
const String commitHash = '705c17d';
const String commitDate = '2024-06-03 23:53:34 -0600';
12 changes: 12 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
Expand Down Expand Up @@ -30,6 +31,8 @@ import 'package:window_size/window_size.dart';

void main() {
WidgetsFlutterBinding.ensureInitialized();
final errorFile = File('latest.log')
..createSync();

if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) {
setWindowTitle('Retro');
Expand All @@ -39,9 +42,18 @@ void main() {

RetroContext.git = GitLoader.getGitInfo();

runZonedGuarded<Future<void>>(bindApp, (error, stack) async {
// Log to file
final errorString = 'Error: $error\nStack: $stack';
await errorFile.writeAsString(errorString, mode: FileMode.append);
});
}

Future<void> bindApp() async {
runApp(const Retro());
}


class Retro extends StatelessWidget {
const Retro({super.key});

Expand Down
6 changes: 1 addition & 5 deletions lib/utils/git.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ class GitInfo {
}

class GitLoader {

static final DateFormat _dateFormat = DateFormat('yyyy-MM-dd HH:mm:ss');

static GitInfo getGitInfo() {
final date = DateTime.fromMillisecondsSinceEpoch(int.parse(commitDate) * 1000);
return GitInfo(branch: branch, commitHash: commitHash, commitDate: _dateFormat.format(date));
return GitInfo(branch: branch, commitHash: commitHash, commitDate: commitDate.split(' -').first);
}
}

0 comments on commit 52490cd

Please sign in to comment.