Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-09-27 13:24:17 +08:00
parent 0ebb2afe39
commit c7e3d9dbc1
4 changed files with 57 additions and 78 deletions

View File

@@ -2,13 +2,13 @@ name: Android Release
on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
paths-ignore:
- '**.md'
types:
- opened
- synchronize
- reopened
- ready_for_review
paths-ignore:
- "**.md"
workflow_dispatch:
jobs:
@@ -53,11 +53,6 @@ jobs:
- name: 下载项目依赖
run: flutter pub get
- name: 更新版本号
run: |
version_name=$(yq e .version pubspec.yaml | cut -d "+" -f 1)
sed -i "s/version: .*/version: $version_name-$(git rev-parse --short HEAD)+$(git rev-list --count HEAD)/g" pubspec.yaml
- name: Write key
if: github.event_name != 'pull_request'
run: |

View File

@@ -2,18 +2,18 @@ name: Build for iOS
on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
paths-ignore:
- '**.md'
types:
- opened
- synchronize
- reopened
- ready_for_review
paths-ignore:
- "**.md"
workflow_dispatch:
inputs:
branch:
required: false
default: 'main'
default: "main"
jobs:
build-macos-app:
@@ -32,11 +32,6 @@ jobs:
channel: stable
flutter-version-file: pubspec.yaml
- name: 更新版本号
run: |
version_name=$(yq e '.version' pubspec.yaml | cut -d "+" -f 1)
sed -i '' "s/version: .*/version: $version_name+$(git rev-list --count HEAD)/" pubspec.yaml
- name: Build iOS
run: |
chmod +x lib/scripts/build.dart

View File

@@ -25,7 +25,6 @@ import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart' hide ContextExtensionss;
import 'package:intl/intl.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:re_highlight/languages/json.dart';
import 'package:re_highlight/re_highlight.dart';
import 'package:re_highlight/styles/github-dark.dart';
@@ -41,7 +40,8 @@ class AboutPage extends StatefulWidget {
}
class _AboutPageState extends State<AboutPage> {
RxString currentVersion = ''.obs;
final currentVersion =
'${BuildConfig.versionName}+${BuildConfig.versionCode}';
RxString cacheSize = ''.obs;
late int _pressCount = 0;
@@ -50,12 +50,10 @@ class _AboutPageState extends State<AboutPage> {
void initState() {
super.initState();
getCacheSize();
getCurrentApp();
}
@override
void dispose() {
currentVersion.close();
cacheSize.close();
super.dispose();
}
@@ -66,12 +64,6 @@ class _AboutPageState extends State<AboutPage> {
);
}
Future<void> getCurrentApp() async {
var currentInfo = await PackageInfo.fromPlatform();
String buildNumber = currentInfo.buildNumber;
currentVersion.value = "${currentInfo.version}+$buildNumber";
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
@@ -143,16 +135,14 @@ class _AboutPageState extends State<AboutPage> {
],
),
),
Obx(
() => ListTile(
onTap: () => Update.checkUpdate(false),
onLongPress: () => Utils.copyText(currentVersion.value),
title: const Text('当前版本'),
leading: const Icon(Icons.commit_outlined),
trailing: Text(
currentVersion.value,
style: subTitleStyle,
),
ListTile(
onTap: () => Update.checkUpdate(false),
onLongPress: () => Utils.copyText(currentVersion),
title: const Text('当前版本'),
leading: const Icon(Icons.commit_outlined),
trailing: Text(
currentVersion,
style: subTitleStyle,
),
),
ListTile(

View File

@@ -1,49 +1,48 @@
import 'dart:io';
void main() async {
if (Platform.isWindows || Platform.isLinux) {
updateVersion();
}
final buildTime = DateTime.now().millisecondsSinceEpoch ~/ 1000;
String commitHash = '';
try {
final result = await Process.run('git', ['rev-parse', 'HEAD']);
commitHash = result.stdout.toString().trim();
} catch (_) {}
final content =
'''
class BuildConfig {
static const int buildTime = $buildTime;
static const String commitHash = '$commitHash';
}
''';
final file = File('lib/build_config.dart');
await file.writeAsString(content);
}
Future<void> updateVersion() async {
final file = File('pubspec.yaml');
final lines = await file.readAsLines();
final pubspecFile = File('pubspec.yaml');
final lines = await pubspecFile.readAsLines();
final versionLineIndex = lines.indexWhere(
(line) => line.trim().startsWith('version:'),
);
if (versionLineIndex == -1) {
exit(1);
}
final versionName = lines[versionLineIndex]
String versionName = lines[versionLineIndex]
.split('+')[0]
.replaceAll('version:', '')
.trim();
final commitCount = await Process.run('git', [
final commitHash = (await Process.run('git', [
'rev-parse',
'HEAD',
])).stdout.toString().trim();
if (Platform.isAndroid) {
versionName += '-${commitHash.substring(0, 9)}';
}
final versionCode = (await Process.run('git', [
'rev-list',
'--count',
'HEAD',
]);
final buildNumber = commitCount.stdout.toString().trim();
])).stdout.toString().trim();
lines[versionLineIndex] = 'version: $versionName+$buildNumber';
await file.writeAsString(lines.join('\n'));
lines[versionLineIndex] = 'version: $versionName+$versionCode';
final buildTime = DateTime.now().millisecondsSinceEpoch ~/ 1000;
final content =
'''
class BuildConfig {
static const int versionCode = $versionCode;
static const String versionName = '$versionName';
static const int buildTime = $buildTime;
static const String commitHash = '$commitHash';
}
''';
pubspecFile.writeAsString(lines.join('\n'));
File('lib/build_config.dart').writeAsString(content);
}