Skip to content

Instantly share code, notes, and snippets.

@WimObiwan
Last active July 18, 2016 12:39
Show Gist options
  • Save WimObiwan/28fd18b0d91601bb20488ba485b94c24 to your computer and use it in GitHub Desktop.
Save WimObiwan/28fd18b0d91601bb20488ba485b94c24 to your computer and use it in GitHub Desktop.
Rename a file (include git describe in filename) and copy to server location
$Version = '10.3.5'
$VersionTarget = '5.3.5'
$Source = @(
"C:\Source$Version\CTArchitect\Release\CTArchitect.exe",
"C:\Source$Version\CTArchitect\Release\CTArchitect.pdb"
)
$Target = "\\greatgazoo\FTPRoot\internal\TEST $VersionTarget\"
$TagMatch = 'CTArchitect*'
$Source | . .\TagAndCopyItem.ps1 -Target $Target -TagMatch $TagMatch
# For HWClient:
$Version = '10.3.5'
$VersionTarget = '5.3.5'
$Source = @(
"C:\Source$Version\HWClient\Release\HWClient.exe",
"C:\Source$Version\HWClient\Release\HWClient.pdb"
)
$Target = "\\greatgazoo\FTPRoot\internal\TEST $VersionTarget\"
$TagMatch = 'HWClient*'
$Source | . .\TagAndCopyItem.ps1 -Target $Target -TagMatch $TagMatch
[cmdletbinding()]
Param(
[string]$Item,
[string]$TagMatch = "*"
)
$ErrorActionPreference = "Stop"
$Item = (Resolve-Path $Item).Path
Write-Verbose "Item: $Item"
$extension = [System.IO.Path]::GetExtension($Item)
$path = Split-Path $Item
Write-Verbose "Path: $Path"
$base = $Item.Substring(0, $Item.Length - $extension.Length)
pushd .
cd $path
$commitdatetime=[DateTime]::Parse($(git log --pretty=format:"%ad" -n 1 --date=iso HEAD))
$gitdescribe=$(git describe --match $tagmatch)
"$base-$gitdescribe-$($commitdatetime.ToString('yyMMdd-HHmm'))$($extension)"
popd
[cmdletbinding()]
Param(
[Parameter(Position = 0, Mandatory = $True, ValueFromPipeline = $True)]
[string]$Source,
[string]$Target,
[string]$TagMatch = "*"
)
BEGIN
{
$ErrorActionPreference = "Stop"
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
$count = 0
}
PROCESS
{
$lastWriteTime = (dir $Source | sort LastWriteTime -Descending | select -First 1).LastWriteTime
if ($lastWriteTime -lt (Get-Date).AddHours(-1)) {
Write-Error "$SourceItem is more than 1 hour old"
}
cd (Split-Path $Source)
$from = (Split-Path -Leaf $Source)
Write-Verbose "From: $from"
$tagged = $(. "$scriptPath\Get-TaggedItem.ps1" $from -TagMatch $TagMatch )
Write-Verbose "Tagged: $tagged"
cp $from $tagged
Write-Verbose "Target: $target"
mv $tagged $Target -Force
$count++
}
END
{
dir $Target | sort -Descending LastWriteTime | Select -First $count
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment