diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6a66dc2..5f0374c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,6 +18,8 @@ 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: chmod +x ./build.sh + - run: ./build.sh - run: flutter config --enable-macos-desktop - run: flutter build -v macos --release - run: ditto -c -k --sequesterRsrc --keepParent retro.app $GITHUB_WORKSPACE/retro.zip @@ -36,6 +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: flutter config --enable-windows-desktop - run: flutter build windows --release - uses: actions/upload-artifact@v3 @@ -54,13 +57,15 @@ 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: chmod +x ./build.sh + - run: ./build.sh - run: flutter config --enable-linux-desktop - run: flutter build linux --release - name: Create AppImage run: | wget "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage" chmod a+x appimagetool-x86_64.AppImage - + # Create AppDir cp -r build/linux/x64/release/bundle/ retro.AppDir cp assets/icon-macos.png retro.AppDir/retro.png diff --git a/.gitignore b/.gitignore index 8cac985..396537d 100644 --- a/.gitignore +++ b/.gitignore @@ -39,6 +39,9 @@ app.*.symbols # Obfuscation related app.*.map.json +# Autogenerated file +# lib/auto/build.dart + # Android Studio will place build artifacts here /android/app/debug /android/app/profile diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..c6cc2da --- /dev/null +++ b/build.bat @@ -0,0 +1,12 @@ +@echo off + +if exist lib\auto\build.dart del /f lib\auto\build.dart +type nul > lib\auto\build.dart + +for /f "delims=" %%i in ('git rev-parse --abbrev-ref HEAD') do set BRANCH=%%i +for /f "delims=" %%i in ('git rev-parse HEAD') do set COMMIT_HASH=%%i +for /f "delims=" %%i in ('git show -s --format=%%ci') do set COMMIT_DATE=%%i + +echo const String branch = '%BRANCH%'; > lib\auto\build.dart +echo const String commitHash = '%COMMIT_HASH%'; >> lib\auto\build.dart +echo const String commitDate = '%COMMIT_DATE%'; >> lib\auto\build.dart \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..884adf5 --- /dev/null +++ b/build.sh @@ -0,0 +1,9 @@ +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_DATE=$(git show -s --format=%ci) + +echo "const String branch = '$BRANCH';" > lib/auto/build.dart +echo "const String commitHash = '$COMMIT_HASH';" >> lib/auto/build.dart +echo "const String commitDate = '$COMMIT_DATE';" >> lib/auto/build.dart \ No newline at end of file diff --git a/lib/auto/build.dart b/lib/auto/build.dart new file mode 100644 index 0000000..f94d1d2 --- /dev/null +++ b/lib/auto/build.dart @@ -0,0 +1,3 @@ +const String branch = './build.sh to generate this file'; +const String commitHash = 'Run'; +const String commitDate = '0000000000'; diff --git a/lib/utils/git.dart b/lib/utils/git.dart index 53ab005..179d1b3 100644 --- a/lib/utils/git.dart +++ b/lib/utils/git.dart @@ -1,5 +1,6 @@ -import 'package:flutter/services.dart'; import 'package:intl/intl.dart'; +import 'package:retro/auto/build.dart'; + class GitInfo { @@ -15,12 +16,7 @@ class GitLoader { static final DateFormat _dateFormat = DateFormat('yyyy-MM-dd HH:mm:ss'); static Future getGitInfo() async { - final head = (await rootBundle.loadString('.git/HEAD')).trim(); - final commitId = (await rootBundle.loadString('.git/ORIG_HEAD')).substring(0, 7); - final commitDate = (await rootBundle.loadString('.git/logs/HEAD')).split('\n').first.split(' ')[4]; final date = DateTime.fromMillisecondsSinceEpoch(int.parse(commitDate) * 1000); - final branch = head.split('/').last; - - return GitInfo(branch: branch, commitHash: commitId, commitDate: _dateFormat.format(date)); + return GitInfo(branch: branch, commitHash: commitHash, commitDate: _dateFormat.format(date)); } } \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index 5d65d71..981c091 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -101,10 +101,6 @@ flutter: # To add assets to your application, add an assets section, like this: assets: - assets/ - - .git/HEAD # This file points out the current branch of the project. - - .git/ORIG_HEAD # This file points to the commit id at origin (last commit id of the remote repository). - - .git/logs/HEAD # This directory includes files that contain the history of the commits. - - .git/refs/heads/ # This directory includes files for each branch that points to the last commit id (local repo). # An image asset can refer to one or more resolution-specific "variants", see # https://flutter.dev/assets-and-images/#resolution-aware