1+ #
12# Script should be executed manually by developer
3+ #
4+
25$ModuleName = ' InstallModuleFromGit'
36
7+ if ($Env: TF_BUILD -eq ' True' ) {
8+ throw ' This script should not be executed from VSTS. Please use dedicated script for that.'
9+ }
10+
11+
412# check running folder
5- if (! ( Test-Path " ..\$ModuleName \$ModuleName .psd1" ) ) {
6- throw " We are not in correct folder, please run this tool as .\tools\PublishModule.ps1 "
13+ if (Test-Path " ..\$ModuleName \$ModuleName .psd1" ) {
14+ " Checking module $ ( Resolve-Path " .\ $ModuleName .psd1 " ) "
715} else {
8- " Checking module $ ( Resolve-Path " ..\ $ModuleName \ $ModuleName .psd1 " ) "
16+ throw " We are not in correct folder, please run this tool as .\tools\PublishModule.ps1 "
917}
1018
19+
1120# test manifest
1221try {
1322 $Module = Test-ModuleManifest " $ModuleName .psd1" - ea Stop
@@ -16,42 +25,46 @@ try {
1625 throw ' Module manifest not in proper format'
1726}
1827
28+
1929# test version, must be x.y.z
2030if (($Module.Version.ToString () -split ' \.' ).Count -lt 3 ) {
2131 throw " Module version must have three segments at least, currently it is $ ( $Module.Version.ToString ()) "
2232} else {
23- " Module version $ ( $Module.Version.ToString ()) is OK"
33+ " Module version tag ' $ ( $Module.Version.ToString ()) ' is OK"
2434}
2535
26- # test if remote is not the same
36+
37+ # test if the module is not already published with same version number
2738" Checking for module with version $ ( $Module.Version ) online..."
2839if (Find-Module - Name $ModuleName - RequiredVersion ($Module.Version ) - Repository PSGallery - ea 0 ) {
2940 throw ' Module with same version already exists'
3041} else {
3142 " No module with version $ ( $Module.Version ) found online"
3243}
3344
34- # get nuget key from somewhere?
45+
46+ # get publishing key
3547if ($NugetKey ) {
3648 " NugetKey found"
3749} else {
3850 throw ' Please define $NugetKey variable (run $NugetKey = Read-Host)'
3951}
4052
41- # copy entire folder to temp location
42- if ($IsLinux -or $IsMacOS ) {$Destination = ' /tmp' }
43- else {$Destination = $Env: TEMP }
4453
54+ # copy entire folder to temp location
55+ if ($IsLinux -or $IsMacOS ) {$Destination = ' /tmp' } else {$Destination = $Env: TEMP }
4556$Destination2 = Join-Path $Destination $ModuleName
46- " Copying to $Destination2 "
4757if (Test-Path $Destination2 ) {Remove-Item $Destination2 - Recurse - Force}
58+
59+ " Copying to $Destination2 "
4860Copy-Item - Path . - Destination $Destination - Recurse # it creates folder $ModuleName
4961
62+
5063# remove not needed files (as per .publishignore)
5164" Removing not needed files"
52- $pwdLength = $Destination2. Length + 1
65+ $pwdLength = ( Get-Item $Destination2 ).FullName. Length + 1 # expands 'C:\Users\VSSADM~1\AppData\Local\Temp'
5366foreach ($line in (Get-Content ' .publishignore' | where {$_ -notlike ' #*' })) {
54- # "Checking files like $line"
67+ " Checking files like $line "
5568 foreach ($file in (Get-ChildItem - Path $Destination2 - Recurse - Force - File)) {
5669 $relativeName = $file.FullName.Substring ($pwdLength ) -replace ' \\' , ' /'
5770 # "$relativeName"
@@ -63,6 +76,7 @@ foreach ($line in (Get-Content '.publishignore'| where {$_ -notlike '#*'})) {
6376}
6477
6578# publish
79+ " Publishing total of $ ( (Get-ChildItem $Destination2 - Recurse - File).Count) files"
6680Read-Host " All prerequisites check. Press Enter to Publish module or Ctrl+C to abort"
6781Publish-Module - Path $Destination2 - Repository PSGallery - NuGetApiKey $NugetKey - Verbose
68- " Module $ModuleName published to PowerShell Gallery"
82+ " Module $ModuleName published to PowerShell Gallery"
0 commit comments