Skip to content

Commit

Permalink
Insert CopyRight information in top of PowerShell scripts fixed #195
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickGrub committed Oct 8, 2021
1 parent d8bc844 commit a26998f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
34 changes: 34 additions & 0 deletions AzureDevops_AddCopyRight.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
param ($Major, $Minor, $Build, $Revision, $Timestamp, $HashCodeFile)

$Major = "22"
$Minor = "1"
$Build = "0"
$Revision = "1"
$timestamp = (Get-Date).ToUniversalTime()
$HashCodeFile = Split-Path $MyInvocation.MyCommand.Path

function Add-CopyRight($fileConent, $version, $buildTime) {
$copyRight = @"
#=============================================================================#
# Copyright (c) coolOrange s.r.l. - All rights reserved. #
# Verson: {0} Buildtime: {1} #
#=============================================================================#
"@ -f @($version, $buildTime)

$fileConentWithCopyRight = "$($copyRight)`n`n" + $($fileConent)
return $fileConentWithCopyRight
}

$currentPath = Split-Path $MyInvocation.MyCommand.Path
Get-ChildItem "$currentPath\Files" -Recurse -Include *.psm1, *.ps1 |
ForEach-Object {
$fileContent = (Get-Content $_ -Raw)

$version = "$($Major).$($Minor).$($Build).$($Revision)"
$newContent = Add-CopyRight -fileConent $fileContent -version $version -buildTime $Timestamp
Set-Content $_ -Value $newContent -Encoding UTF8
Write-Host "Add copyright to file $($_.Name)"

$hash = Get-FileHash $_
(Split-Path -Path $hash.Path -Leaf) + "($($hash.Algorithm)): $($hash.Hash)" | Out-File "$HashCodeFile\PSCodeHash.txt" -Append
}
6 changes: 6 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ variables:
buildMinor: '$(Minor)'
buildRevision: '$(Revision)'
increment: $[counter(1,0)]
buildTimestamp: $((Get-Date).ToUniversalTime())

steps:
- task: NuGetToolInstaller@0
Expand All @@ -26,6 +27,11 @@ steps:
vstsFeed: 'AzureFeed_Projects'
restoreSolution: '$(solution)'

- task: PowerShell@2
inputs:
filePath: 'AzureDevops_AddCopyRight.ps1'
arguments: '-Major $(buildMajor) -Minor $(buildMinor) -Build $(Build.BuildNumber) -Revision $(buildRevision) -Timestamp $(buildTimestamp) -HashCodeFile $(Build.ArtifactStagingDirectory)'

- task: VSBuild@1
inputs:
solution: '$(solution)'
Expand Down

0 comments on commit a26998f

Please sign in to comment.