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: on:
pull_request: pull_request:
types: types:
- opened - opened
- synchronize - synchronize
- reopened - reopened
- ready_for_review - ready_for_review
paths-ignore: paths-ignore:
- '**.md' - "**.md"
workflow_dispatch: workflow_dispatch:
jobs: jobs:
@@ -53,11 +53,6 @@ jobs:
- name: 下载项目依赖 - name: 下载项目依赖
run: flutter pub get 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 - name: Write key
if: github.event_name != 'pull_request' if: github.event_name != 'pull_request'
run: | run: |

View File

@@ -2,18 +2,18 @@ name: Build for iOS
on: on:
pull_request: pull_request:
types: types:
- opened - opened
- synchronize - synchronize
- reopened - reopened
- ready_for_review - ready_for_review
paths-ignore: paths-ignore:
- '**.md' - "**.md"
workflow_dispatch: workflow_dispatch:
inputs: inputs:
branch: branch:
required: false required: false
default: 'main' default: "main"
jobs: jobs:
build-macos-app: build-macos-app:
@@ -32,11 +32,6 @@ jobs:
channel: stable channel: stable
flutter-version-file: pubspec.yaml 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 - name: Build iOS
run: | run: |
chmod +x lib/scripts/build.dart 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:get/get.dart' hide ContextExtensionss;
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.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/languages/json.dart';
import 'package:re_highlight/re_highlight.dart'; import 'package:re_highlight/re_highlight.dart';
import 'package:re_highlight/styles/github-dark.dart'; import 'package:re_highlight/styles/github-dark.dart';
@@ -41,7 +40,8 @@ class AboutPage extends StatefulWidget {
} }
class _AboutPageState extends State<AboutPage> { class _AboutPageState extends State<AboutPage> {
RxString currentVersion = ''.obs; final currentVersion =
'${BuildConfig.versionName}+${BuildConfig.versionCode}';
RxString cacheSize = ''.obs; RxString cacheSize = ''.obs;
late int _pressCount = 0; late int _pressCount = 0;
@@ -50,12 +50,10 @@ class _AboutPageState extends State<AboutPage> {
void initState() { void initState() {
super.initState(); super.initState();
getCacheSize(); getCacheSize();
getCurrentApp();
} }
@override @override
void dispose() { void dispose() {
currentVersion.close();
cacheSize.close(); cacheSize.close();
super.dispose(); 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final theme = Theme.of(context); final theme = Theme.of(context);
@@ -143,16 +135,14 @@ class _AboutPageState extends State<AboutPage> {
], ],
), ),
), ),
Obx( ListTile(
() => ListTile( onTap: () => Update.checkUpdate(false),
onTap: () => Update.checkUpdate(false), onLongPress: () => Utils.copyText(currentVersion),
onLongPress: () => Utils.copyText(currentVersion.value), title: const Text('当前版本'),
title: const Text('当前版本'), leading: const Icon(Icons.commit_outlined),
leading: const Icon(Icons.commit_outlined), trailing: Text(
trailing: Text( currentVersion,
currentVersion.value, style: subTitleStyle,
style: subTitleStyle,
),
), ),
), ),
ListTile( ListTile(

View File

@@ -1,49 +1,48 @@
import 'dart:io'; import 'dart:io';
void main() async { void main() async {
if (Platform.isWindows || Platform.isLinux) { final pubspecFile = File('pubspec.yaml');
updateVersion(); final lines = await pubspecFile.readAsLines();
}
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 versionLineIndex = lines.indexWhere( final versionLineIndex = lines.indexWhere(
(line) => line.trim().startsWith('version:'), (line) => line.trim().startsWith('version:'),
); );
if (versionLineIndex == -1) {
exit(1);
}
final versionName = lines[versionLineIndex] String versionName = lines[versionLineIndex]
.split('+')[0] .split('+')[0]
.replaceAll('version:', '') .replaceAll('version:', '')
.trim(); .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', 'rev-list',
'--count', '--count',
'HEAD', 'HEAD',
]); ])).stdout.toString().trim();
final buildNumber = commitCount.stdout.toString().trim();
lines[versionLineIndex] = 'version: $versionName+$buildNumber'; lines[versionLineIndex] = 'version: $versionName+$versionCode';
await file.writeAsString(lines.join('\n'));
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);
} }