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
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