From f572a2a33ea84df2af24e650a611da5608d3871b Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Fri, 9 Jun 2017 18:47:50 +0200 Subject: [PATCH] Improved install script and made a release script --- NadekoBot.iss | 8 ++++- release.ps1 | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 release.ps1 diff --git a/NadekoBot.iss b/NadekoBot.iss index c470d8b0..b0c226f6 100644 --- a/NadekoBot.iss +++ b/NadekoBot.iss @@ -1,5 +1,5 @@ #define sysfolder "system" -#define version "1.41" +#define version GetEnv('NADEKOBOT_INSTALL_VERSION') #define target "win7-x64" [Setup] @@ -56,6 +56,12 @@ Root: "HKLM"; Subkey: "SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFla Root: "HKCU"; Subkey: "SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"; \ ValueType: String; ValueName: "{app}\{#sysfolder}\NadekoBot.exe"; ValueData: "RUNASADMIN"; \ Flags: uninsdeletekeyifempty uninsdeletevalue; +Root: "HKLM"; Subkey: "SOFTWARE\NadekoBot"; \ + ValueType: String; ValueName: "InstallPath"; ValueData: "{app}\{#sysfolder}"; \ + Flags: deletevalue uninsdeletekeyifempty uninsdeletevalue; +Root: "HKLM"; Subkey: "SOFTWARE\NadekoBot"; \ + ValueType: String; ValueName: "Version"; ValueData: "{#version}"; \ + Flags: deletevalue uninsdeletekeyifempty uninsdeletevalue; [Messages] WelcomeLabel2=IMPORTANT! READ BELOW!%n%nIt is recommended that you CLOSE any ANTI VIRUS before continuing.%n%nYou can only update v1.4 or newer.%n%nDo not select your old NadekoBot folder as an install path if it's not 1.4 or newer. diff --git a/release.ps1 b/release.ps1 new file mode 100644 index 00000000..725dc1ce --- /dev/null +++ b/release.ps1 @@ -0,0 +1,82 @@ +function GitHub-Release($versionNumber) +{ + $ErrorActionPreference = "Stop" + $env:NADEKOBOT_INSTALL_VERSION=$versionNumber + + $draft = $TRUE + + $lastTag = git describe --tags --abbrev=0 + $tag = "$lastTag..HEAD" + $changelog = & 'git' 'log', $tag, '--oneline' + + $gitHubApiKey = $env:GITHUB_API_KEY + + $commitId = git rev-parse HEAD + + # 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 + + & "C:\Program Files (x86)\Inno Setup 5\iscc.exe" "/O+" ".\NadekoBot.iss" + + $artifact = "NadekoBot-setup-$versionNumber.exe"; + + $auth = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes($gitHubApiKey + ":x-oauth-basic")); + + $result = GitHubMake-Release $versionNumber $commitId $TRUE $gitHubApiKey $auth "" + $releaseId = $result | Select -ExpandProperty id + $uploadUri = $result | Select -ExpandProperty upload_url + $uploadUri = $uploadUri -creplace '\{\?name,label\}', "?name=$artifact" + Write-Host $releaseId $uploadUri + $uploadFile = [Environment]::GetFolderPath('MyDocuments') + "\projekti\NadekoInstallerOutput\$artifact" + + $uploadParams = @{ + 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" + Write-Host 'Done 🎉' +} + +function GitHubMake-Release($versionNumber, $commitId, $draft, $gitHubApiKey, $auth, $releaseId = "") +{ + $releaseId = If ($releaseId -eq "") {""} Else {"/" + $releaseId}; + + Write-Host $versionNumber + Write-Host $commitId + Write-Host $draft + Write-Host $gitHubApiKey + Write-Host $releaseId + Write-Host $auth + + $releaseData = @{ + tag_name = $versionNumber; + target_commitish = $commitId; + name = [string]::Format("NadekoBot v{0}", $versionNumber); + body = "test"; + draft = $draft; + prerelease = $releaseId -ne ""; + } + + $releaseParams = @{ + 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 +} \ No newline at end of file