* opt: env

* fix

* fix: regex

* fix: android

* fix

* fix

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>

* fastforge define

* fix

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>

---------

Co-authored-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
My-Responsitories
2025-10-10 15:52:26 +08:00
committed by GitHub
parent c0bbf8400a
commit a65edab7d1
11 changed files with 99 additions and 130 deletions

View File

@@ -57,10 +57,12 @@ jobs:
echo keyPassword='${{ secrets.KEY_PASSWORD }}' >> android/key.properties echo keyPassword='${{ secrets.KEY_PASSWORD }}' >> android/key.properties
fi fi
- name: Set and Extract version
shell: pwsh
run: lib/scripts/build.ps1 android
- name: flutter build apk - name: flutter build apk
run: | run: flutter build apk --release --split-per-abi --dart-define-from-file=pili_release.json --pub
dart lib/scripts/build.dart "android"
flutter build apk --release --split-per-abi --pub
- name: 上传 - name: 上传
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4

View File

@@ -32,11 +32,13 @@ jobs:
channel: stable channel: stable
flutter-version-file: pubspec.yaml flutter-version-file: pubspec.yaml
- name: Set and Extract version
shell: pwsh
run: lib/scripts/build.ps1
- name: Build iOS - name: Build iOS
run: | run: |
chmod +x lib/scripts/build.dart flutter build ios --release --no-codesign --dart-define-from-file=pili_release.json
dart lib/scripts/build.dart
flutter build ios --release --no-codesign
ln -sf ./build/ios/iphoneos Payload ln -sf ./build/ios/iphoneos Payload
zip -r9 ios-release-no-sign.ipa Payload/runner.app zip -r9 ios-release-no-sign.ipa Payload/runner.app

View File

@@ -54,15 +54,12 @@ jobs:
cache: true cache: true
- name: Set and Extract version - name: Set and Extract version
run: | shell: pwsh
dart lib/scripts/build.dart run: lib/scripts/build.ps1
VERSION=$(cat pubspec.yaml | grep 'version:' | sed 's/version: //g' | tr -d '[:space:]')
echo "version=$VERSION" >> $GITHUB_ENV
shell: bash
#TODO: deb and rpm packages need to be build #TODO: deb and rpm packages need to be build
- name: Build Linux - name: Build Linux
run: flutter build linux --release -v --pub run: flutter build linux --release -v --pub --dart-define-from-file=pili_release.json
- name: Package .tar.gz - name: Package .tar.gz
run: tar -zcvf PiliPlus_linux_${{ env.version }}_amd64.tar.gz -C build/linux/x64/release/bundle . run: tar -zcvf PiliPlus_linux_${{ env.version }}_amd64.tar.gz -C build/linux/x64/release/bundle .

View File

@@ -32,12 +32,12 @@ jobs:
channel: stable channel: stable
flutter-version-file: pubspec.yaml flutter-version-file: pubspec.yaml
- name: Set and Extract version
shell: pwsh
run: lib/scripts/build.ps1
- name: Build Mac - name: Build Mac
run: | run: flutter build macos --release --dart-define-from-file=pili_release.json
dart lib/scripts/build.dart
VERSION=$(cat pubspec.yaml | grep 'version:' | sed 's/version: //g' | tr -d '[:space:]')
echo "version=$VERSION" >> $GITHUB_ENV
flutter build macos --release
- name: Prepare Upload - name: Prepare Upload
run: | run: |

View File

@@ -40,13 +40,15 @@ jobs:
- name: Add Chinese language file for Inno Setup - name: Add Chinese language file for Inno Setup
run: | run: |
Copy-Item "windows/packaging/exe/ChineseSimplified.isl" "C:\Program Files (x86)\Inno Setup 6\Languages\ChineseSimplified.isl" Copy-Item "windows/packaging/exe/ChineseSimplified.isl" "C:\Program Files (x86)\Inno Setup 6\Languages\ChineseSimplified.isl"
shell: powershell shell: pwsh
- name: Set and Extract version
shell: pwsh
run: lib/scripts/build.ps1
- name: Build Windows - name: Build Windows
run: | run: |
dart lib/scripts/build.dart fastforge package --platform windows --targets exe --flutter-build-args="dart-define-from-file=pili_release.json"
flutter build windows --release
fastforge package --platform windows --targets exe
- name: Prepare Upload - name: Prepare Upload
run: | run: |

8
.gitignore vendored
View File

@@ -137,9 +137,11 @@ app.*.symbols
!.vscode/launch.json !.vscode/launch.json
!.vscode/tasks.json !.vscode/tasks.json
/lib/build_config.dart
devtools_options.yaml devtools_options.yaml
# FVM Version Cache # FVM Version Cache
.fvm/ .fvm/
pili_release.json
dist

37
.vscode/launch.json vendored
View File

@@ -1,48 +1,25 @@
{ {
// 使用 IntelliSense 了解相关属性。 // 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。 // 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"name": "Debug", "name": "PiliPlus",
"request": "launch", "request": "launch",
"type": "dart", "type": "dart"
"preLaunchTask": "Update build_config"
}, },
{ {
"name": "Profile", "name": "PiliPlus (profile mode)",
"request": "launch", "request": "launch",
"type": "dart", "type": "dart",
"flutterMode": "profile", "flutterMode": "profile"
"preLaunchTask": "Update build_config"
}, },
{ {
"name": "Release", "name": "PiliPlus (release mode)",
"request": "launch", "request": "launch",
"type": "dart", "type": "dart",
"flutterMode": "release", "flutterMode": "release"
"preLaunchTask": "Update build_config"
},
{
"name": "Debug (FVM)",
"request": "launch",
"type": "dart",
"preLaunchTask": "Update build_config (FVM)"
},
{
"name": "Profile (FVM)",
"request": "launch",
"type": "dart",
"flutterMode": "profile",
"preLaunchTask": "Update build_config (FVM)"
},
{
"name": "Release (FVM)",
"request": "launch",
"type": "dart",
"flutterMode": "release",
"preLaunchTask": "Update build_config (FVM)"
} }
] ]
} }

25
.vscode/tasks.json vendored
View File

@@ -1,25 +0,0 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Update build_config",
"command": "dart lib/scripts/build.dart dev",
"type": "shell",
"problemMatcher": [],
"presentation": {
"reveal": "always"
},
"group": "build"
},
{
"label": "Update build_config (FVM)",
"command": "fvm dart lib/scripts/build.dart dev",
"type": "shell",
"problemMatcher": [],
"presentation": {
"reveal": "always"
},
"group": "build"
}
]
}

16
lib/build_config.dart Normal file
View File

@@ -0,0 +1,16 @@
class BuildConfig {
static const int versionCode = int.fromEnvironment(
'pili.code',
defaultValue: 1,
);
static const String versionName = String.fromEnvironment(
'pili.name',
defaultValue: 'SNAPSHOT',
);
static const int buildTime = int.fromEnvironment('pili.time');
static const String commitHash = String.fromEnvironment(
'pili.hash',
defaultValue: 'N/A',
);
}

View File

@@ -1,51 +0,0 @@
import 'dart:io';
void main(Iterable<String> args) async {
final arg = args.firstOrNull;
final pubspecFile = File('pubspec.yaml');
final lines = await pubspecFile.readAsLines();
final versionLineIndex = lines.indexWhere(
(line) => line.trim().startsWith('version:'),
);
String versionName = lines[versionLineIndex]
.split('+')[0]
.replaceAll('version:', '')
.trim();
final commitHash = (await Process.run('git', [
'rev-parse',
'HEAD',
])).stdout.toString().trim();
if (arg == 'android') {
versionName += '-${commitHash.substring(0, 9)}';
}
final versionCode = (await Process.run('git', [
'rev-list',
'--count',
'HEAD',
])).stdout.toString().trim();
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';
}
''';
if (arg != 'dev') {
pubspecFile.writeAsString(lines.join('\n'));
}
File('lib/build_config.dart').writeAsString(content);
}

47
lib/scripts/build.ps1 Normal file
View File

@@ -0,0 +1,47 @@
param(
[string]$Arg = ''
)
try {
$versionName = $null
$versionCode = [int](git rev-list --count HEAD).Trim()
$commitHash = (git rev-parse HEAD).Trim()
$updatedContent = foreach ($line in (Get-Content -Path 'pubspec.yaml' -Encoding UTF8)) {
if ($line -match '^\s*version:\s*([\d\.]+)') {
$versionName = $matches[1]
if ($Arg -eq 'android') {
$versionName += '-' + $commitHash.Substring(0, 9)
}
"version: $versionName+$versionCode"
}
else {
$line
}
}
if ($null -eq $versionName) {
throw 'version not found'
}
$updatedContent | Set-Content -Path 'pubspec.yaml' -Encoding UTF8
$buildTime = [int]([DateTimeOffset]::Now.ToUnixTimeSeconds())
$data = @{
'pili.name' = $versionName
'pili.code' = $versionCode
'pili.hash' = $commitHash
'pili.time' = $buildTime
}
$data | ConvertTo-Json -Compress | Out-File 'pili_release.json' -Encoding UTF8
Add-Content -Path $env:GITHUB_ENV -Value "version=$versionName+$versionCode"
}
catch {
Write-Error "Prebuild Error: $($_.Exception.Message)"
exit 1
}