Skip to content

Commit c33f435

Browse files
added release-build.ps1
1 parent fcc907c commit c33f435

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

build/release-build.ps1

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
if (! $env:HUDSON_URL) {
3+
Write-Error "Please set environment variable 'HUDSON_URL'"
4+
exit
5+
}
6+
7+
# download
8+
$artifactsUri = "$env:HUDSON_URL/job/typescript-generator/lastSuccessfulBuild/artifact/*zip*/archive.zip"
9+
$zipFilePath = "target\archive.zip"
10+
Write-Host -ForegroundColor DarkCyan "Downloading '$artifactsUri'..."
11+
Invoke-WebRequest $artifactsUri -OutFile $zipFilePath
12+
$zipFile = Get-Item $zipFilePath
13+
14+
# unzip
15+
Write-Host -ForegroundColor DarkCyan "Unzipping..."
16+
$unzipDirectoryPath = "target\gpg-sign"
17+
rm -Recurse -Force $unzipDirectoryPath -ErrorAction SilentlyContinue
18+
rm -Recurse -Force $unzipDirectoryPath -ErrorAction SilentlyContinue
19+
$unzipDirectory = mkdir $unzipDirectoryPath
20+
[System.Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem") | Out-Null
21+
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipFile.FullName, $unzipDirectory.FullName)
22+
$basePath = (Resolve-Path $unzipDirectory\*).Path
23+
24+
# passphrase
25+
$securePassphrase = Read-Host -Prompt "Enter signing key passphrase" -AsSecureString
26+
$passphraseCredential = New-Object System.Management.Automation.PSCredential -ArgumentList "Domain\User", $securePassphrase
27+
$passphrase = $passphraseCredential.GetNetworkCredential().Password
28+
"test" | gpg --detach-sign --armor --passphrase $passphrase | Out-Null
29+
if (! $?) {
30+
exit
31+
}
32+
33+
# sign
34+
foreach ($file in dir -Recurse -File $basePath) {
35+
$path = $file.FullName.Substring($basePath.Length + 1)
36+
Write-Host -ForegroundColor DarkCyan "Signing $path..."
37+
gpg --detach-sign --armor --passphrase $passphrase $file.FullName
38+
Get-FileHash -Algorithm MD5 $file.FullName | % { [IO.File]::WriteAllText($file.FullName + ".md5", $_.Hash) }
39+
Get-FileHash -Algorithm SHA1 $file.FullName | % { [IO.File]::WriteAllText($file.FullName + ".sha1", $_.Hash) }
40+
}
41+
42+
# upload
43+
$repoUri = "https://oss.sonatype.org/service/local/staging/deploy/maven2"
44+
$credential = $host.UI.PromptForCredential("OSS Repository Hosting", "Enter your credentials for Sonatype maven repository https://oss.sonatype.org", "", "")
45+
if (! $credential) {
46+
exit
47+
}
48+
$headers = @{"Authorization" = "Basic " + [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($credential.UserName + ":" + $credential.GetNetworkCredential().Password))}
49+
foreach ($file in dir -Recurse -File $basePath) {
50+
$path = $file.FullName.Substring($basePath.Length + 1)
51+
Write-Host -ForegroundColor DarkCyan "Uploading $path..."
52+
$groupId = $path | Split-Path | Split-Path | Split-Path
53+
$uri = $groupId.Replace(".", "/") + $path.Substring($groupId.Length).Replace("\", "/")
54+
$response = Invoke-WebRequest -InFile $file.FullName -Method Put "$repoUri/$uri" -Headers $headers
55+
}
56+
57+
Write-Host -ForegroundColor Cyan "Build successfully uploaded. Go to https://oss.sonatype.org and promote the release."

0 commit comments

Comments
 (0)