1
Fork 0
mirror of https://gitlab.com/Kwoth/nadekobot.git synced 2024-10-02 20:13:13 +00:00
nadekobot/release.ps1

114 lines
4.2 KiB
PowerShell
Raw Normal View History

2018-12-28 23:11:21 +00:00
function Get-Changelog()
{
$lastTag = git describe --tags --abbrev=0
$tag = "$lastTag..HEAD"
2017-06-10 13:14:00 +00:00
$clArr = (& 'git' 'log', $tag, '--oneline')
2017-06-10 21:52:44 +00:00
[array]::Reverse($clArr)
2017-06-09 23:12:54 +00:00
$changelog = $clArr | where { "$_" -notlike "*(POEditor.com)*" -and "$_" -notlike "*Merge branch*" -and "$_" -notlike "*Merge pull request*" -and "$_" -notlike "^-*" -and "$_" -notlike "*Merge remote tracking*" }
$changelog = [string]::join([Environment]::NewLine, $changelog)
2017-06-09 23:12:54 +00:00
$cl2 = $clArr | where { "$_" -like "*Merge pull request*" }
$changelog = "## Changes$nl$changelog"
2018-12-28 23:11:21 +00:00
if ($null -ne $cl2) {
2018-03-04 08:04:39 +00:00
$cl2 = [string]::join([Environment]::NewLine, $cl2)
$changelog = $changelog + "$nl ## Pull Requests Merged$nl$cl2"
}
2018-12-28 23:11:21 +00:00
}
2019-04-03 01:11:14 +00:00
function Build-Installer($versionNumber)
{
$env:NADEKOBOT_INSTALL_VERSION = $versionNumber
dotnet publish -c Release --runtime win7-x64
.\rcedit-x64.exe "src\NadekoBot\bin\Release\netcoreapp2.1\win7-x64\nadekobot.exe" --set-icon "src\NadekoBot\bin\Release\netcoreapp2.1\win7-x64\nadeko_icon.ico"
& "C:\Program Files (x86)\Inno Setup 5\iscc.exe" "/O+" ".\NadekoBot.iss"
$path = [Environment]::GetFolderPath('MyDocuments') + "\projekti\NadekoInstallerOutput\NadekoBot-setup-$versionNumber.exe";
$dest = [Environment]::GetFolderPath('MyDocuments') + "\projekti\NadekoInstallerOutput\nadekobot-setup.exe";
Move-Item -Path $path -Destination $dest -Force
}
2018-12-28 23:11:21 +00:00
function GitHub-Release($versionNumber) {
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
$ErrorActionPreference = "Stop"
git pull
git push #making sure commit id exists on remote
$nl = [Environment]::NewLine
$env:NADEKOBOT_INSTALL_VERSION = $versionNumber
$gitHubApiKey = $env:GITHUB_API_KEY
$commitId = git rev-parse HEAD
$changelog = Get-Changelog
2017-06-09 23:12:54 +00:00
Write-Host $changelog
# set-alias sz "$env:ProgramFiles\7-Zip\7z.exe"
# $source = "src\NadekoBot\bin\Release\PublishOutput\win7-x64"
# $target = "src\NadekoBot\bin\Release\PublishOutput\NadekoBot.7z"
# sz 'a' '-mx3' $target $source
2019-04-03 01:11:14 +00:00
Build-Installer
$artifact = "nadekobot-setup.exe";
$auth = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes($gitHubApiKey + ":x-oauth-basic"));
2017-06-09 23:12:54 +00:00
Write-Host $changelog
$result = GitHubMake-Release $versionNumber $commitId $TRUE $gitHubApiKey $auth "" "$changelog"
2018-12-28 23:11:21 +00:00
$releaseId = $result | Select-Object -ExpandProperty id
$uploadUri = $result | Select-Object -ExpandProperty upload_url
$uploadUri = $uploadUri -creplace '\{\?name,label\}', "?name=$artifact"
Write-Host $releaseId $uploadUri
$uploadFile = [Environment]::GetFolderPath('MyDocuments') + "\projekti\NadekoInstallerOutput\$artifact"
$uploadParams = @{
2018-03-04 08:04:39 +00:00
Uri = $uploadUri;
Method = 'POST';
Headers = @{
Authorization = $auth;
}
ContentType = 'application/x-msdownload';
InFile = $uploadFile
}
Write-Host 'Uploading artifact'
$result = Invoke-RestMethod @uploadParams
Write-Host 'Artifact upload finished.'
$result = GitHubMake-Release $versionNumber $commitId $FALSE $gitHubApiKey $auth "$releaseId"
git pull
Write-Host 'Done 🎉'
}
2018-03-04 08:04:39 +00:00
function GitHubMake-Release($versionNumber, $commitId, $draft, $gitHubApiKey, $auth, $releaseId, $body) {
$releaseId = If ($releaseId -eq "") {""} Else {"/" + $releaseId};
Write-Host $versionNumber
Write-Host $commitId
Write-Host $draft
Write-Host $releaseId
2017-06-09 23:12:54 +00:00
Write-Host $body
$releaseData = @{
2018-03-04 08:04:39 +00:00
tag_name = $versionNumber;
target_commitish = $commitId;
name = [string]::Format("NadekoBot v{0}", $versionNumber);
body = $body;
draft = $draft;
prerelease = $releaseId -ne "";
}
$releaseParams = @{
2018-03-04 08:04:39 +00:00
Uri = "https://api.github.com/repos/Kwoth/NadekoBot/releases" + $releaseId;
Method = 'POST';
Headers = @{
Authorization = $auth;
}
ContentType = 'application/json';
Body = (ConvertTo-Json $releaseData -Compress)
}
return Invoke-RestMethod @releaseParams
}