-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #268 from reupen/add-version-to-release-components
Include version in component archives for releases
- Loading branch information
Showing
3 changed files
with
65 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,25 @@ | ||
Param( | ||
[Parameter(Mandatory=$true)][String]$ComponentPath, | ||
[Parameter(Mandatory=$true)][String]$OutputDir | ||
[Parameter(Mandatory=$true)][string]$ComponentPath, | ||
[Parameter(Mandatory=$true)][string]$OutputDir | ||
) | ||
|
||
$input_base_name = [io.path]::GetFileNameWithoutExtension($ComponentPath) | ||
$output_path = "$OutputDir$input_base_name.fb2k-component" | ||
$intermediate_file_path = "$output_path.zip" | ||
Import-Module "$PSScriptRoot\versioning" | ||
|
||
$version = Get-Version | ||
|
||
$inputBaseName = [io.path]::GetFileNameWithoutExtension($ComponentPath) | ||
|
||
$verionPart = '' | ||
|
||
if ($version -and $version.IsRelease()) { | ||
$verionPart = "-$version" | ||
} | ||
|
||
$outputPath = "$OutputDir$inputBaseName$verionPart.fb2k-component" | ||
$intermediateFilePath = "$outputPath.zip" | ||
|
||
# Note that Compress-Archive won't accept a file extension other than .zip. Hence, we add .zip to the file name | ||
# and then remove it using Move-Item. | ||
# (Also note that both Compress-Archive and Move-Item should overwite the destination file if it exists.) | ||
Compress-Archive -Path $ComponentPath -CompressionLevel Optimal -DestinationPath $intermediate_file_path -Force | ||
Move-Item $intermediate_file_path $output_path -Force | ||
Compress-Archive -Path $ComponentPath -CompressionLevel Optimal -DestinationPath $intermediateFilePath -Force | ||
Move-Item $intermediateFilePath $outputPath -Force |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,57 @@ | ||
function Get-GitDescription { | ||
$description_regex = '^v(?<version>.+)-(?<distance>\d+)-g(?<commit>[0-9a-f]{7})(-(?<dirty>dirty))?$' | ||
|
||
Try { | ||
$description = git describe --tags --dirty --match 'v[0-9]*' --long | ||
} Catch { | ||
return $null | ||
class Version { | ||
[string]$BaseVersion; | ||
[int]$Distance; | ||
[string]$CommitHash; | ||
[bool]$Dirty; | ||
|
||
Version([string]$BaseVersion, [int]$Distance, [string]$CommitHash, [bool]$Dirty) { | ||
$this.BaseVersion = $BaseVersion | ||
$this.Distance = $Distance | ||
$this.CommitHash = $CommitHash | ||
$this.Dirty = $Dirty | ||
} | ||
|
||
[string]ToString() { | ||
$annotations = @() | ||
|
||
if ($this.Distance) { | ||
$annotations += @($this.Distance, "g$($this.CommitHash)") | ||
} | ||
|
||
If (-not ($description -match $description_regex)) { | ||
return $null | ||
if ($this.Dirty) { | ||
$annotations += 'dirty' | ||
} | ||
|
||
if ($annotations) { | ||
$joinedAnnotations = $annotations -Join '.' | ||
return "$($this.BaseVersion)+$joinedAnnotations" | ||
} | ||
|
||
return $this.BaseVersion | ||
} | ||
|
||
return $Matches | ||
} | ||
|
||
function Get-Version { | ||
$description = Get-GitDescription | ||
|
||
if (-not $description) { | ||
return '0.0.0+unknown' | ||
[bool]IsRelease() { | ||
return $this.Distance -eq 0 -and -not $this.Dirty | ||
} | ||
|
||
$base_version = $description.version | ||
$annotations = @() | ||
static [Version]FromGit() { | ||
$descriptionRegex = '^v(?<version>.+)-(?<distance>\d+)-g(?<commit>[0-9a-f]{7})(-(?<dirty>dirty))?$' | ||
|
||
if ([int]$description.distance) { | ||
$annotations += @($description.distance, "g$($description.commit)") | ||
$description = git describe --tags --dirty --match 'v[0-9]*' --long | ||
|
||
If (-not ($description -match $descriptionRegex)) { | ||
throw | ||
} | ||
|
||
return [Version]::new($Matches.version, [int]$Matches.distance, $Matches.commit, [bool]$Matches.dirty) | ||
} | ||
} | ||
|
||
if ($description.dirty) { | ||
$annotations += @($description.dirty) | ||
function Get-Version { | ||
try { | ||
return [Version]::FromGit() | ||
} | ||
|
||
if ($annotations) { | ||
$joined_annotations = $annotations -Join '.' | ||
return "$base_version+$joined_annotations" | ||
catch { | ||
return [Version]::new(0, 0, 'unknown', $false) | ||
} | ||
|
||
return $base_version | ||
} |