-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppVeyorPublish.ps1
46 lines (37 loc) · 1.81 KB
/
AppVeyorPublish.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# only publish if commit message starts with !publish
if ($Env:APPVEYOR_REPO_COMMIT_MESSAGE -notmatch ', publish!$') {
Write-Output "No publishing from AppVeyor, to automatically publish, finish commit message with ', publish!'"
exit
}
if ($env:OS -notmatch 'Windows') {
Write-Output 'Publishing possible only from Windows hosts'
exit
}
# check if this version already exists
$ModuleName = 'EasyAzureFunction'
$Manifest = Test-ModuleManifest -Path (Join-Path . "$ModuleName.psd1")
$LocalVersion = $Manifest.Version.ToString()
$RemoteModule = Find-Module $ModuleName -Repository PSGallery
$RemoteVersion = $RemoteModule.Version.ToString()
if ($LocalVersion -eq $RemoteVersion) {
Write-Warning "Module $ModuleName with version $LocalVersion already exists. Consider bumping version."
exit
}
# bootstrap NuGet to 2.8.6
$PSGetProgramDataPath = Join-Path -Path $env:ProgramData -ChildPath 'Microsoft\Windows\PowerShell\PowerShellGet\'
# command above would fail on Linux, but there is test "if Windows" on top of the script; we do not publish from non-Windows machines
$NuGetExeName = 'NuGet.exe'
$NuGetExeFilePath = Join-Path $PSGetProgramDataPath $NuGetExeName
if ((-not (Test-Path -Path $NuGetExeFilePath -PathType Leaf)) -and (-not (Test-Path -Path $PSGetProgramDataPath))) {
New-Item -Path $PSGetProgramDataPath -ItemType Directory -Force
}
# Download the NuGet.exe from https://nuget.org/NuGet.exe
Invoke-WebRequest -Uri https://nuget.org/NuGet.exe -OutFile $NuGetExeFilePath
# we proceed with publish
Write-Output "Publishing version $LocalVersion to PSGallery, currently published version is $RemoteVersion"
try {
Publish-Module -Path . -Repository PSGallery -NuGetApiKey $env:MyPSGalleryAPIKey -ea Stop
Write-Output "Module successfully published!"
} catch {
Write-Output "Publishing failed: $_"
}