1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-22 21:20:09 +00:00

fix(windows): stabilize install and prerelease versioning

This commit is contained in:
Tw93
2026-03-22 14:39:25 +08:00
parent 05fbc007d5
commit 16c3ea9867
13 changed files with 211 additions and 54 deletions

View File

@@ -259,6 +259,64 @@ function Clear-GoCaches {
}
}
function Get-MiseCachePath {
<#
.SYNOPSIS
Resolve the mise cache directory without touching installs/plugins
#>
if (-not [string]::IsNullOrWhiteSpace($env:MISE_CACHE_DIR)) {
return $env:MISE_CACHE_DIR
}
if (-not (Get-Command mise -ErrorAction SilentlyContinue)) {
return $null
}
try {
$cachePath = (& mise cache path 2>$null | Select-Object -First 1)
if ($LASTEXITCODE -eq 0 -and -not [string]::IsNullOrWhiteSpace($cachePath)) {
return $cachePath.Trim()
}
}
catch {
Write-Debug "mise cache path failed: $_"
}
return $null
}
function Clear-MiseCache {
<#
.SYNOPSIS
Clean mise internal cache only
.DESCRIPTION
Respects MISE_CACHE_DIR and never removes the installs/plugins data tree.
#>
$hasMise = [bool](Get-Command mise -ErrorAction SilentlyContinue)
$cachePath = Get-MiseCachePath
$clearedByCommand = $false
if ($hasMise -and -not (Test-DryRunMode)) {
try {
$null = & mise cache clear 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Success "mise cache"
Set-SectionActivity
$clearedByCommand = $true
}
}
catch {
Write-Debug "mise cache clear failed: $_"
}
}
if (-not $clearedByCommand -and $cachePath -and (Test-Path $cachePath)) {
Clear-DirectoryContents -Path $cachePath -Description "mise cache"
}
}
# ============================================================================
# Rust Ecosystem
# ============================================================================
@@ -701,6 +759,9 @@ function Invoke-DevToolsCleanup {
# Go ecosystem
Clear-GoCaches
# mise cache
Clear-MiseCache
# Rust ecosystem
Clear-RustCaches

View File

@@ -16,6 +16,9 @@ $script:MOLE_CORE_DIR = Split-Path -Parent $MyInvocation.MyCommand.Path
$script:MOLE_LIB_DIR = Split-Path -Parent $script:MOLE_CORE_DIR
$script:MOLE_ROOT_DIR = Split-Path -Parent $script:MOLE_LIB_DIR
# Version helpers are standalone and safe to load before the other core modules.
. "$script:MOLE_CORE_DIR\version.ps1"
# ============================================================================
# Load Core Modules
# ============================================================================
@@ -36,7 +39,7 @@ $script:MOLE_ROOT_DIR = Split-Path -Parent $script:MOLE_LIB_DIR
# Version Information
# ============================================================================
$script:MOLE_VERSION = "1.0.0"
$script:MOLE_VERSION = Get-MoleVersionString -RootDir $script:MOLE_ROOT_DIR
$script:MOLE_BUILD_DATE = "2026-01-07"
function Get-MoleVersion {

View File

@@ -9,6 +9,9 @@ if ((Get-Variable -Name 'MOLE_TUI_BINARIES_LOADED' -Scope Script -ErrorAction Si
}
$script:MOLE_TUI_BINARIES_LOADED = $true
$script:MOLE_TUI_CORE_DIR = Split-Path -Parent $MyInvocation.MyCommand.Path
. "$script:MOLE_TUI_CORE_DIR\version.ps1"
$script:MoleGitHubRepo = "tw93/Mole"
$script:MoleGitHubApiRoot = "https://api.github.com/repos/$($script:MoleGitHubRepo)"
$script:MoleGitHubHeaders = @{
@@ -19,17 +22,7 @@ $script:MoleGitHubHeaders = @{
function Get-MoleVersionFromScriptFile {
param([string]$WindowsDir)
$moleScript = Join-Path $WindowsDir "mole.ps1"
if (-not (Test-Path $moleScript)) {
return $null
}
$content = Get-Content $moleScript -Raw
if ($content -match '\$script:MOLE_VER\s*=\s*"([^"]+)"') {
return $Matches[1]
}
return $null
return Get-MoleVersionString -RootDir $WindowsDir
}
function Get-TuiBinaryAssetName {
@@ -136,18 +129,50 @@ function Build-TuiBinary {
Write-Host "Building $Name tool..." -ForegroundColor Cyan
$stdoutPath = Join-Path $env:TEMP "mole-$Name-build.stdout.log"
$stderrPath = Join-Path $env:TEMP "mole-$Name-build.stderr.log"
foreach ($path in @($stdoutPath, $stderrPath)) {
if (Test-Path $path) {
Remove-Item $path -Force -ErrorAction SilentlyContinue
}
}
Push-Location $WindowsDir
try {
$result = & go build -o "$DestinationPath" $SourcePath 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Host "Failed to build $Name tool: $result" -ForegroundColor Red
return $false
}
$process = Start-Process -FilePath "go" `
-ArgumentList @("build", "-o", $DestinationPath, $SourcePath) `
-NoNewWindow `
-Wait `
-PassThru `
-RedirectStandardOutput $stdoutPath `
-RedirectStandardError $stderrPath
}
catch {
Write-Host "Failed to start go build for $Name tool: $_" -ForegroundColor Red
return $false
}
finally {
Pop-Location
}
$buildOutput = @()
foreach ($path in @($stdoutPath, $stderrPath)) {
if (Test-Path $path) {
$content = (Get-Content $path -Raw).Trim()
if ($content) {
$buildOutput += $content
}
Remove-Item $path -Force -ErrorAction SilentlyContinue
}
}
if ($process.ExitCode -ne 0) {
$message = if ($buildOutput.Count -gt 0) { $buildOutput -join [Environment]::NewLine } else { "go build exited with code $($process.ExitCode)" }
Write-Host "Failed to build $Name tool: $message" -ForegroundColor Red
return $false
}
return $true
}
@@ -169,15 +194,24 @@ function Ensure-TuiBinary {
$Version = Get-MoleVersionFromScriptFile -WindowsDir $WindowsDir
}
if (Restore-PrebuiltTuiBinary -Name $Name -WindowsDir $WindowsDir -DestinationPath $DestinationPath -Version $Version) {
return $DestinationPath
try {
if (Restore-PrebuiltTuiBinary -Name $Name -WindowsDir $WindowsDir -DestinationPath $DestinationPath -Version $Version) {
return $DestinationPath
}
}
catch {
Write-Host "Failed to restore prebuilt $Name tool: $_" -ForegroundColor Yellow
}
if (Get-Command go -ErrorAction SilentlyContinue) {
if (Build-TuiBinary -Name $Name -WindowsDir $WindowsDir -DestinationPath $DestinationPath -SourcePath $SourcePath) {
return $DestinationPath
try {
if (Build-TuiBinary -Name $Name -WindowsDir $WindowsDir -DestinationPath $DestinationPath -SourcePath $SourcePath) {
return $DestinationPath
}
}
catch {
Write-Host "Failed to prepare $Name tool: $_" -ForegroundColor Yellow
}
return $null
}
return $null

41
lib/core/version.ps1 Normal file
View File

@@ -0,0 +1,41 @@
# Mole - Version helpers
# Provides a single source of truth for the Windows version string.
#Requires -Version 5.1
Set-StrictMode -Version Latest
if ((Get-Variable -Name 'MOLE_VERSION_HELPERS_LOADED' -Scope Script -ErrorAction SilentlyContinue) -and $script:MOLE_VERSION_HELPERS_LOADED) {
return
}
$script:MOLE_VERSION_HELPERS_LOADED = $true
$script:MoleDefaultVersion = "1.29.0"
function Get-MoleVersionFilePath {
param([string]$RootDir)
if ([string]::IsNullOrWhiteSpace($RootDir)) {
return $null
}
return Join-Path $RootDir "VERSION"
}
function Get-MoleVersionString {
param(
[string]$RootDir,
[string]$DefaultVersion = $script:MoleDefaultVersion
)
$versionFile = Get-MoleVersionFilePath -RootDir $RootDir
if (-not $versionFile -or -not (Test-Path $versionFile)) {
return $DefaultVersion
}
$version = (Get-Content $versionFile -Raw).Trim()
if ([string]::IsNullOrWhiteSpace($version)) {
return $DefaultVersion
}
return $version
}