-
Notifications
You must be signed in to change notification settings - Fork 60
/
publish.ps1
89 lines (75 loc) · 3.41 KB
/
publish.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
param(
[string]$buildVersion,
[string]$psGalleryApiKey,
[string]$gitHubApiKey
)
$ErrorActionPreference = 'Stop'
function Publish-ToGitHub($versionNumber, $commitId, $preRelease, $artifact, $gitHubApiKey)
{
$data = @{
tag_name = [string]::Format("v{0}", $versionNumber);
target_commitish = $commitId;
name = [string]::Format("v{0}", $versionNumber);
body = '';
prerelease = $preRelease;
}
$auth = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes($gitHubApiKey + ":x-oauth-basic"));
$releaseParams = @{
Uri = "https://api.github.com/repos/OctopusDeploy/OctopusDSC/releases";
Method = 'POST';
Headers = @{ Authorization = $auth; }
ContentType = 'application/json';
Body = ($data | ConvertTo-Json -Compress)
}
$result = Invoke-RestMethod @releaseParams
$uploadUri = $result | Select-Object -ExpandProperty upload_url
$uploadUri = $uploadUri -creplace '\{\?name,label\}'
$uploadUri = $uploadUri + ("?name=$artifact".Replace('.\', ''))
$params = @{
Uri = $uploadUri;
Method = 'POST';
Headers = @{ Authorization = $auth; }
ContentType = 'application/zip';
InFile = $artifact
}
Invoke-RestMethod @params
}
try
{
Write-output "### Enabling TLS 1.2 support"
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12, [System.Net.SecurityProtocolType]::Tls11, [System.Net.SecurityProtocolType]::Tls
Write-output "### Updating version number to $buildVersion"
$content = (Get-Content OctopusDSC/OctopusDSC.psd1)
$content = $content -replace "ModuleVersion = '[0-9\.]+'", "ModuleVersion = '$buildVersion'"
Set-Content OctopusDSC/OctopusDSC.psd1 $content
Write-output "### Ensuring nuget.exe is available"
If (-not (Test-Path "C:\ProgramData\Microsoft\Windows\PowerShell\PowerShellGet\NuGet.exe")) {
Write-output "Downloading latest nuget to C:\ProgramData\Microsoft\Windows\PowerShell\PowerShellGet\NuGet.exe"
if (-not (Test-Path "C:\ProgramData\Microsoft\Windows\PowerShell\PowerShellGet")) {
New-Item -type Directory "C:\ProgramData\Microsoft\Windows\PowerShell\PowerShellGet" | Out-Null
}
Invoke-WebRequest -Uri "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -OutFile "C:\ProgramData\Microsoft\Windows\PowerShell\PowerShellGet\NuGet.exe"
Write-Output "### Checking nuget.exe version"
& C:\ProgramData\Microsoft\Windows\PowerShell\PowerShellGet\NuGet.exe help | select -first 1
}
Write-Output "### Install-PackageProvider nuget -force"
Install-PackageProvider nuget -force
Write-output "### Import Modules"
Import-Module "C:\Program Files\WindowsPowerShell\Modules\PackageManagement"
Import-Module "C:\Program Files\WindowsPowerShell\Modules\PowerShellGet"
Write-output "### Publish-Module -Path 'OctopusDSC'"
Publish-Module -Path "OctopusDSC" -NuGetApiKey $psGalleryApiKey
Write-Output "### Publishing to GitHub"
Compress-Archive -Path .\OctopusDSC -DestinationPath ".\OctopusDSC.$buildVersion.zip"
$commitId = git rev-parse HEAD
Publish-ToGitHub -versionNumber $buildVersion `
-commitId $commitId `
-preRelease $false `
-artifact ".\OctopusDSC.$buildVersion.zip" `
-gitHubApiKey $gitHubApiKey
}
catch
{
Write-Output $_
exit 1
}