diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-11-18 14:37:23 +0100 |
---|---|---|
committer | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-11-18 16:46:45 +0100 |
commit | 87926505665cb43492f487fd96354bb7ea48aa90 (patch) | |
tree | fee75ae63883a414d01395c5ad909e2c5507892a /appveyor.ps1 | |
parent | 1544db3e40a7de95d411dc2e7c96be3eb07f896f (diff) | |
download | sonar-scanner-cli-87926505665cb43492f487fd96354bb7ea48aa90.tar.gz sonar-scanner-cli-87926505665cb43492f487fd96354bb7ea48aa90.zip |
SQSCANNER-8 Execute ITs on Windows using AppVeyor
Diffstat (limited to 'appveyor.ps1')
-rw-r--r-- | appveyor.ps1 | 133 |
1 files changed, 130 insertions, 3 deletions
diff --git a/appveyor.ps1 b/appveyor.ps1 index d7ce18e..a7c29ba 100644 --- a/appveyor.ps1 +++ b/appveyor.ps1 @@ -1,5 +1,106 @@ $ErrorActionPreference = "Stop" +function FetchAndUnzip +{ + param ([string]$Url, [string]$Out) + + $tmp = [System.IO.Path]::GetTempFileName() + [System.Reflection.Assembly]::LoadWithPartialName('System.Net.Http') | Out-Null + $client = (New-Object System.Net.Http.HttpClient) + try + { + if (-not([string]::IsNullOrEmpty($env:GITHUB_TOKEN))) + { + $credentials = [string]::Format([System.Globalization.CultureInfo]::InvariantCulture, "{0}:", $env:GITHUB_TOKEN); + $credentials = [Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($credentials)); + $client.DefaultRequestHeaders.Authorization = (New-Object System.Net.Http.Headers.AuthenticationHeaderValue("Basic", $credentials)); + } + $contents = $client.GetByteArrayAsync($url).Result; + [System.IO.File]::WriteAllBytes($tmp, $contents); + } + finally + { + $client.Dispose() + } + + if (-not(Test-Path $Out)) + { + mkdir $Out | Out-Null + } + [System.Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem') | Out-Null + [System.IO.Compression.ZipFile]::ExtractToDirectory($tmp, $Out) +} + +function InstallAppveyorTools +{ + $travisUtilsVersion = "16" + $localPath = "$env:USERPROFILE\.local" + $travisUtilsPath = "$localPath\travis-utils-$travisUtilsVersion" + if (Test-Path $travisUtilsPath) + { + echo "Reusing the Travis Utils version $travisUtilsVersion already downloaded under $travisUtilsPath" + } + else + { + $url = "https://github.com/SonarSource/travis-utils/archive/v$travisUtilsVersion.zip" + echo "Downloading Travis Utils version $travisUtilsVersion from $url into $localPath" + FetchAndUnzip $url $localPath + } + + $mavenLocalRepository = "$env:USERPROFILE\.m2\repository" + if (-not(Test-Path $mavenLocalRepository)) + { + mkdir $mavenLocalRepository | Out-Null + } + echo "Installating Travis Utils closed source Maven projects into $mavenLocalRepository" + Copy-Item "$travisUtilsPath\m2repo\*" $mavenLocalRepository -Force -Recurse + + $env:ORCHESTRATOR_CONFIG_URL = "" + $env:TRAVIS = "ORCH-332" +} + +function Build +{ + param ([string]$Project, [string]$Sha1) + + $msg = "Fetch [" + $Project + ":" + $Sha1 + "]" + echo $msg + + $url = "https://github.com/$Project/archive/$Sha1.zip" + $tmp = "c:\snapshot" + if (Test-Path $tmp) + { + Cmd /C "rmdir /S /Q $tmp" + } + + FetchAndUnzip $url $tmp + + $msg = "Build [" + $Project + ":" + $Sha1 + "]" + echo $msg + + pushd $tmp\* + try + { + mvn install "--batch-mode" "-DskipTests" "-Pdev" + CheckLastExitCode + } + finally + { + popd + } +} + +function BuildSnapshot +{ + param ([string]$Project) + + echo "Fetch and build latest green snapshot of [$Project]" + + $lastGreenSha1 = (new-object Net.WebClient).DownloadString("http://sonarsource-979.appspot.com/$Project/latestGreen") + + Build $Project $lastGreenSha1 +} + function CheckLastExitCode { param ([int[]]$SuccessCodes = @(0)) @@ -14,16 +115,42 @@ CALLSTACK:$(Get-PSCallStack | Out-String) } } -switch ($env:RUN) +BuildSnapshot "SonarSource/orchestrator" + +switch ($env:TEST) { "ci" { - mvn package "--batch-mode" "-B" "-e" "-V" + mvn verify "--batch-mode" "-B" "-e" "-V" + CheckLastExitCode + } + + "it" + { + InstallAppveyorTools + + mvn install "--batch-mode" "-Dsource.skip=true" "-Dmaven.test.skip=true" CheckLastExitCode + + if ($env:SQ_VERSION -eq "DEV") + { + BuildSnapshot "SonarSource/sonarqube" + } + + pushd it + try + { + mvn install "--batch-mode" "-DsonarRunner.version=""2.5-SNAPSHOT""" "-Dsonar.runtimeVersion=""$env:SQ_VERSION""" "-Dmaven.test.redirectTestOutputToFile=false" + CheckLastExitCode + } + finally + { + popd + } } default { - throw "Unexpected test mode: ""$env:RUN""" + throw "Unexpected TEST mode: $env:TEST" } } |