mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
opt: env (#1510)
* 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:
committed by
GitHub
parent
c0bbf8400a
commit
a65edab7d1
8
.github/workflows/android.yml
vendored
8
.github/workflows/android.yml
vendored
@@ -57,10 +57,12 @@ jobs:
|
||||
echo keyPassword='${{ secrets.KEY_PASSWORD }}' >> android/key.properties
|
||||
fi
|
||||
|
||||
- name: Set and Extract version
|
||||
shell: pwsh
|
||||
run: lib/scripts/build.ps1 android
|
||||
|
||||
- name: flutter build apk
|
||||
run: |
|
||||
dart lib/scripts/build.dart "android"
|
||||
flutter build apk --release --split-per-abi --pub
|
||||
run: flutter build apk --release --split-per-abi --dart-define-from-file=pili_release.json --pub
|
||||
|
||||
- name: 上传
|
||||
uses: actions/upload-artifact@v4
|
||||
|
||||
8
.github/workflows/ios.yml
vendored
8
.github/workflows/ios.yml
vendored
@@ -32,11 +32,13 @@ jobs:
|
||||
channel: stable
|
||||
flutter-version-file: pubspec.yaml
|
||||
|
||||
- name: Set and Extract version
|
||||
shell: pwsh
|
||||
run: lib/scripts/build.ps1
|
||||
|
||||
- name: Build iOS
|
||||
run: |
|
||||
chmod +x lib/scripts/build.dart
|
||||
dart lib/scripts/build.dart
|
||||
flutter build ios --release --no-codesign
|
||||
flutter build ios --release --no-codesign --dart-define-from-file=pili_release.json
|
||||
ln -sf ./build/ios/iphoneos Payload
|
||||
zip -r9 ios-release-no-sign.ipa Payload/runner.app
|
||||
|
||||
|
||||
9
.github/workflows/linux.yml
vendored
9
.github/workflows/linux.yml
vendored
@@ -54,15 +54,12 @@ jobs:
|
||||
cache: true
|
||||
|
||||
- name: Set and Extract version
|
||||
run: |
|
||||
dart lib/scripts/build.dart
|
||||
VERSION=$(cat pubspec.yaml | grep 'version:' | sed 's/version: //g' | tr -d '[:space:]')
|
||||
echo "version=$VERSION" >> $GITHUB_ENV
|
||||
shell: bash
|
||||
shell: pwsh
|
||||
run: lib/scripts/build.ps1
|
||||
|
||||
#TODO: deb and rpm packages need to be build
|
||||
- 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
|
||||
run: tar -zcvf PiliPlus_linux_${{ env.version }}_amd64.tar.gz -C build/linux/x64/release/bundle .
|
||||
|
||||
10
.github/workflows/mac.yml
vendored
10
.github/workflows/mac.yml
vendored
@@ -32,12 +32,12 @@ jobs:
|
||||
channel: stable
|
||||
flutter-version-file: pubspec.yaml
|
||||
|
||||
- name: Set and Extract version
|
||||
shell: pwsh
|
||||
run: lib/scripts/build.ps1
|
||||
|
||||
- name: Build Mac
|
||||
run: |
|
||||
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
|
||||
run: flutter build macos --release --dart-define-from-file=pili_release.json
|
||||
|
||||
- name: Prepare Upload
|
||||
run: |
|
||||
|
||||
10
.github/workflows/win.yml
vendored
10
.github/workflows/win.yml
vendored
@@ -40,13 +40,15 @@ jobs:
|
||||
- name: Add Chinese language file for Inno Setup
|
||||
run: |
|
||||
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
|
||||
run: |
|
||||
dart lib/scripts/build.dart
|
||||
flutter build windows --release
|
||||
fastforge package --platform windows --targets exe
|
||||
fastforge package --platform windows --targets exe --flutter-build-args="dart-define-from-file=pili_release.json"
|
||||
|
||||
- name: Prepare Upload
|
||||
run: |
|
||||
|
||||
8
.gitignore
vendored
8
.gitignore
vendored
@@ -137,9 +137,11 @@ app.*.symbols
|
||||
!.vscode/launch.json
|
||||
!.vscode/tasks.json
|
||||
|
||||
/lib/build_config.dart
|
||||
|
||||
devtools_options.yaml
|
||||
|
||||
# FVM Version Cache
|
||||
.fvm/
|
||||
.fvm/
|
||||
|
||||
pili_release.json
|
||||
|
||||
dist
|
||||
37
.vscode/launch.json
vendored
37
.vscode/launch.json
vendored
@@ -1,48 +1,25 @@
|
||||
{
|
||||
// 使用 IntelliSense 了解相关属性。
|
||||
// 使用 IntelliSense 了解相关属性。
|
||||
// 悬停以查看现有属性的描述。
|
||||
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Debug",
|
||||
"name": "PiliPlus",
|
||||
"request": "launch",
|
||||
"type": "dart",
|
||||
"preLaunchTask": "Update build_config"
|
||||
"type": "dart"
|
||||
},
|
||||
{
|
||||
"name": "Profile",
|
||||
"name": "PiliPlus (profile mode)",
|
||||
"request": "launch",
|
||||
"type": "dart",
|
||||
"flutterMode": "profile",
|
||||
"preLaunchTask": "Update build_config"
|
||||
"flutterMode": "profile"
|
||||
},
|
||||
{
|
||||
"name": "Release",
|
||||
"name": "PiliPlus (release mode)",
|
||||
"request": "launch",
|
||||
"type": "dart",
|
||||
"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)"
|
||||
"flutterMode": "release"
|
||||
}
|
||||
]
|
||||
}
|
||||
25
.vscode/tasks.json
vendored
25
.vscode/tasks.json
vendored
@@ -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
16
lib/build_config.dart
Normal 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',
|
||||
);
|
||||
}
|
||||
@@ -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
47
lib/scripts/build.ps1
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user