1
+ #
1
2
# Script should be executed manually by developer
3
+ #
4
+
2
5
$ModuleName = ' InstallModuleFromGit'
3
6
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
+
4
12
# 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 " ) "
7
15
} 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 "
9
17
}
10
18
19
+
11
20
# test manifest
12
21
try {
13
22
$Module = Test-ModuleManifest " $ModuleName .psd1" - ea Stop
@@ -16,42 +25,46 @@ try {
16
25
throw ' Module manifest not in proper format'
17
26
}
18
27
28
+
19
29
# test version, must be x.y.z
20
30
if (($Module.Version.ToString () -split ' \.' ).Count -lt 3 ) {
21
31
throw " Module version must have three segments at least, currently it is $ ( $Module.Version.ToString ()) "
22
32
} else {
23
- " Module version $ ( $Module.Version.ToString ()) is OK"
33
+ " Module version tag ' $ ( $Module.Version.ToString ()) ' is OK"
24
34
}
25
35
26
- # test if remote is not the same
36
+
37
+ # test if the module is not already published with same version number
27
38
" Checking for module with version $ ( $Module.Version ) online..."
28
39
if (Find-Module - Name $ModuleName - RequiredVersion ($Module.Version ) - Repository PSGallery - ea 0 ) {
29
40
throw ' Module with same version already exists'
30
41
} else {
31
42
" No module with version $ ( $Module.Version ) found online"
32
43
}
33
44
34
- # get nuget key from somewhere?
45
+
46
+ # get publishing key
35
47
if ($NugetKey ) {
36
48
" NugetKey found"
37
49
} else {
38
50
throw ' Please define $NugetKey variable (run $NugetKey = Read-Host)'
39
51
}
40
52
41
- # copy entire folder to temp location
42
- if ($IsLinux -or $IsMacOS ) {$Destination = ' /tmp' }
43
- else {$Destination = $Env: TEMP }
44
53
54
+ # copy entire folder to temp location
55
+ if ($IsLinux -or $IsMacOS ) {$Destination = ' /tmp' } else {$Destination = $Env: TEMP }
45
56
$Destination2 = Join-Path $Destination $ModuleName
46
- " Copying to $Destination2 "
47
57
if (Test-Path $Destination2 ) {Remove-Item $Destination2 - Recurse - Force}
58
+
59
+ " Copying to $Destination2 "
48
60
Copy-Item - Path . - Destination $Destination - Recurse # it creates folder $ModuleName
49
61
62
+
50
63
# remove not needed files (as per .publishignore)
51
64
" 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'
53
66
foreach ($line in (Get-Content ' .publishignore' | where {$_ -notlike ' #*' })) {
54
- # "Checking files like $line"
67
+ " Checking files like $line "
55
68
foreach ($file in (Get-ChildItem - Path $Destination2 - Recurse - Force - File)) {
56
69
$relativeName = $file.FullName.Substring ($pwdLength ) -replace ' \\' , ' /'
57
70
# "$relativeName"
@@ -63,6 +76,7 @@ foreach ($line in (Get-Content '.publishignore'| where {$_ -notlike '#*'})) {
63
76
}
64
77
65
78
# publish
79
+ " Publishing total of $ ( (Get-ChildItem $Destination2 - Recurse - File).Count) files"
66
80
Read-Host " All prerequisites check. Press Enter to Publish module or Ctrl+C to abort"
67
81
Publish-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