Created
July 9, 2018 21:47
-
-
Save IlyaFinkelshteyn/cdf6e8185ce00baa74b57699a665bb14 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#WARNING: this may work unpredictable with parallel build of the same project (parallel jobs in matrix are fine) | |
#Note $separator variable. If "-" can be used earlier in build version, replace it to something unique | |
version: 0.1.{build} | |
environment: | |
API_TOKEN: | |
secure: SlDEDtAKuvsy+VErEuc/4DxdhPeKu2WRqvYzEh/fiH4= | |
for: | |
- | |
branches: | |
only: | |
- master | |
init: | |
- ps: | | |
echo "common init" | |
init: | |
- ps: | | |
echo "common init" | |
$token = $env:API_TOKEN #should be defined as a secure variable | |
$separator = "-" | |
$headers = @{ | |
"Authorization" = "Bearer $token" | |
"Content-type" = "application/json" | |
} | |
$apiURL = "https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG" | |
$history = Invoke-RestMethod -Uri "$apiURL/history?recordsNumber=2" -Headers $headers -Method Get | |
if ($history.builds.Count -eq 2) { | |
$s = Invoke-RestMethod -Uri "https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/settings" -Headers $headers -Method Get | |
$s.settings.nextBuildNumber = ($s.settings.nextBuildNumber - 1) | |
Invoke-RestMethod -Uri 'https://ci.appveyor.com/api/projects' -Headers $headers -Body ($s.settings | ConvertTo-Json -Depth 10) -Method Put | |
$previousVersion = $history.builds[1].version | |
if ($previousVersion.IndexOf("$separator") -ne "-1") {$previousVersion = $previousVersion.SubString(0, $previousVersion.IndexOf("$separator"))} | |
Update-AppveyorBuild -Version $previousVersion$separator$((New-Guid).ToString().SubString(0,8)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment