1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-22 18:30:08 +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

3
.gitattributes vendored Normal file
View File

@@ -0,0 +1,3 @@
* text=auto eol=lf
*.ps1 text eol=lf
*.cmd text eol=crlf

View File

@@ -47,14 +47,12 @@ jobs:
$version = "${{ github.ref }}" -replace '^refs/tags/[Vv]', ''
$version = $version -replace '-windows$', ''
} else {
$content = Get-Content mole.ps1 -Raw
if ($content -match '\$script:MOLE_VER\s*=\s*"([^"]+)"') {
$version = $Matches[1]
} else {
$version = (Get-Content VERSION -Raw).Trim()
}
if (-not $version) {
Write-Error "Could not detect version"
exit 1
}
}
Write-Host "Version: $version"
"VERSION=$version" >> $env:GITHUB_OUTPUT

2
.gitignore vendored
View File

@@ -89,3 +89,5 @@ mole_guidelines.md
run_tests.ps1
session.json
journal/2026-03-11-safe-remove-design.md
mole.cmd
mo.cmd

1
VERSION Normal file
View File

@@ -0,0 +1 @@
1.29.0

View File

@@ -19,14 +19,17 @@ Set-StrictMode -Version Latest
# Configuration
# ============================================================================
$script:VERSION = "1.0.0"
$script:SourceDir = if ($MyInvocation.MyCommand.Path) {
Split-Path -Parent $MyInvocation.MyCommand.Path
} else {
$PSScriptRoot
}
$script:CoreDir = Join-Path $script:SourceDir "lib\core"
$script:ShortcutName = "Mole"
. (Join-Path $script:CoreDir "version.ps1")
$script:VERSION = Get-MoleVersionString -RootDir $script:SourceDir
# Colors (using [char]27 for PowerShell 5.1 compatibility)
$script:ESC = [char]27
$script:Colors = @{
@@ -39,7 +42,7 @@ $script:Colors = @{
NC = "$($script:ESC)[0m"
}
. (Join-Path $script:SourceDir "lib\core\tui_binaries.ps1")
. (Join-Path $script:CoreDir "tui_binaries.ps1")
# ============================================================================
# Helpers
@@ -258,7 +261,13 @@ function Ensure-OptionalTuiTools {
foreach ($tool in $tools) {
$destination = Join-Path $RootDir $tool.Output
try {
$binPath = Ensure-TuiBinary -Name $tool.Name -WindowsDir $RootDir -DestinationPath $destination -SourcePath $tool.Source -Version $version
}
catch {
Write-MoleWarning "Skipping $($tool.Name).exe after a non-fatal setup error: $_"
$binPath = $null
}
if ($binPath) {
Write-Success "Ready: $($tool.Name).exe"
}

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
# ============================================================================
@@ -702,6 +760,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
}
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) {
try {
if (Build-TuiBinary -Name $Name -WindowsDir $WindowsDir -DestinationPath $DestinationPath -SourcePath $SourcePath) {
return $DestinationPath
}
return $null
}
catch {
Write-Host "Failed to prepare $Name tool: $_" -ForegroundColor Yellow
}
}
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
}

View File

@@ -24,6 +24,12 @@ Set-StrictMode -Version Latest
$script:MOLE_ROOT = Split-Path -Parent $MyInvocation.MyCommand.Path
$script:MOLE_BIN = Join-Path $script:MOLE_ROOT "bin"
$script:MOLE_LIB = Join-Path $script:MOLE_ROOT "lib"
$script:MOLE_CORE = Join-Path $script:MOLE_LIB "core"
# Read the version before loading the rest of the runtime so every entrypoint
# resolves the same release tag.
. "$script:MOLE_CORE\version.ps1"
$script:MOLE_VER = Get-MoleVersionString -RootDir $script:MOLE_ROOT
# Import core
. "$script:MOLE_LIB\core\common.ps1"
@@ -32,7 +38,6 @@ $script:MOLE_LIB = Join-Path $script:MOLE_ROOT "lib"
# Version Info
# ============================================================================
$script:MOLE_VER = "1.0.0"
$script:MOLE_BUILD = "2026-01-07"
function Show-Version {

View File

@@ -20,15 +20,15 @@ Set-StrictMode -Version Latest
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$projectRoot = Split-Path -Parent $scriptDir
$releaseDir = Join-Path $projectRoot "release"
$versionFile = Join-Path $projectRoot "VERSION"
# Read version from mole.ps1 if not provided
# Read version from VERSION if not provided
if (-not $Version) {
$moleScript = Join-Path $projectRoot "mole.ps1"
$content = Get-Content $moleScript -Raw
if ($content -match '\$script:MOLE_VER\s*=\s*"([^"]+)"') {
$Version = $Matches[1]
} else {
Write-Host "Error: Could not detect version from mole.ps1" -ForegroundColor Red
if (Test-Path $versionFile) {
$Version = (Get-Content $versionFile -Raw).Trim()
}
if (-not $Version) {
Write-Host "Error: Could not detect version from VERSION" -ForegroundColor Red
exit 1
}
}

View File

@@ -21,15 +21,15 @@ $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$projectRoot = Split-Path -Parent $scriptDir
$releaseDir = Join-Path $projectRoot "release"
$wixSource = Join-Path $scriptDir "mole-installer.wxs"
$versionFile = Join-Path $projectRoot "VERSION"
# Read version from mole.ps1 if not provided
# Read version from VERSION if not provided
if (-not $Version) {
$moleScript = Join-Path $projectRoot "mole.ps1"
$content = Get-Content $moleScript -Raw
if ($content -match '\$script:MOLE_VER\s*=\s*"([^"]+)"') {
$Version = $Matches[1]
} else {
Write-Host "Error: Could not detect version from mole.ps1" -ForegroundColor Red
if (Test-Path $versionFile) {
$Version = (Get-Content $versionFile -Raw).Trim()
}
if (-not $Version) {
Write-Host "Error: Could not detect version from VERSION" -ForegroundColor Red
exit 1
}
}

View File

@@ -23,15 +23,15 @@ $projectRoot = Split-Path -Parent $scriptDir
$releaseDir = Join-Path $projectRoot "release"
$binDir = Join-Path $projectRoot "bin"
$cmdDir = Join-Path $projectRoot "cmd"
$versionFile = Join-Path $projectRoot "VERSION"
# Read version from mole.ps1 if not provided
# Read version from VERSION if not provided
if (-not $Version) {
$moleScript = Join-Path $projectRoot "mole.ps1"
$content = Get-Content $moleScript -Raw
if ($content -match '\$script:MOLE_VER\s*=\s*"([^"]+)"') {
$Version = $Matches[1]
} else {
Write-Host "Error: Could not detect version from mole.ps1" -ForegroundColor Red
if (Test-Path $versionFile) {
$Version = (Get-Content $versionFile -Raw).Trim()
}
if (-not $Version) {
Write-Host "Error: Could not detect version from VERSION" -ForegroundColor Red
exit 1
}
}