|
| 1 | +$PSake.use_exit_on_error = $true |
| 2 | + |
| 3 | +$Here = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" |
| 4 | + |
| 5 | +$SolutionRoot = (Split-Path -parent $Here) |
| 6 | + |
| 7 | +$ProjectName = "Advanced.Algorithms" |
| 8 | +$GitHubProjectName = "Advanced-Algorithms" |
| 9 | +$GitHubUserName = "justcoding121" |
| 10 | + |
| 11 | +$SolutionFile = "$SolutionRoot\$ProjectName.sln" |
| 12 | + |
| 13 | +## This comes from the build server iteration |
| 14 | +if(!$BuildNumber) { $BuildNumber = $env:APPVEYOR_BUILD_NUMBER } |
| 15 | +if(!$BuildNumber) { $BuildNumber = "0"} |
| 16 | + |
| 17 | +## The build configuration, i.e. Debug/Release |
| 18 | +if(!$Configuration) { $Configuration = $env:Configuration } |
| 19 | +if(!$Configuration) { $Configuration = "Release" } |
| 20 | + |
| 21 | +if(!$Version) { $Version = $env:APPVEYOR_BUILD_VERSION } |
| 22 | +if(!$Version) { $Version = "0.0.$BuildNumber" } |
| 23 | + |
| 24 | +if(!$Branch) { $Branch = $env:APPVEYOR_REPO_BRANCH } |
| 25 | +if(!$Branch) { $Branch = "local" } |
| 26 | + |
| 27 | +if($Branch -eq "beta" ) { $Version = "$Version-beta" } |
| 28 | + |
| 29 | +$NuGet = Join-Path $SolutionRoot ".nuget\nuget.exe" |
| 30 | + |
| 31 | +$MSBuild = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\msbuild.exe" |
| 32 | +$MSBuild -replace ' ', '` ' |
| 33 | + |
| 34 | +FormatTaskName (("-"*25) + "[{0}]" + ("-"*25)) |
| 35 | + |
| 36 | +#default task |
| 37 | +Task default -depends Clean, Build, Document, Package |
| 38 | + |
| 39 | +#cleans obj, b |
| 40 | +Task Clean { |
| 41 | + Get-ChildItem .\ -include bin,obj -Recurse | foreach ($_) { Remove-Item $_.fullname -Force -Recurse } |
| 42 | + exec { . $MSBuild $SolutionFile /t:Clean /v:quiet } |
| 43 | +} |
| 44 | + |
| 45 | +#install build tools |
| 46 | +Task Install-BuildTools -depends Clean { |
| 47 | + if(!(Test-Path $MSBuild)) |
| 48 | + { |
| 49 | + cinst microsoft-build-tools -y |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +#restore nuget packages |
| 54 | +Task Restore-Packages -depends Install-BuildTools { |
| 55 | + exec { . dotnet restore "$SolutionRoot\$ProjectName.sln" } |
| 56 | +} |
| 57 | + |
| 58 | +#build |
| 59 | +Task Build -depends Restore-Packages{ |
| 60 | + exec { . $MSBuild $SolutionFile /t:Build /v:normal /p:Configuration=$Configuration /t:restore } |
| 61 | +} |
| 62 | + |
| 63 | +#publish API documentation changes for GitHub pages under master\docs directory |
| 64 | +Task Document -depends Build { |
| 65 | + |
| 66 | + if($Branch -eq "master") |
| 67 | + { |
| 68 | + #use docfx to generate API documentation from source metadata |
| 69 | + docfx docfx.json |
| 70 | + |
| 71 | + #patch index.json so that it is always sorted |
| 72 | + #otherwise git will think file was changed |
| 73 | + $IndexJsonFile = "$SolutionRoot\docs\index.json" |
| 74 | + $unsorted = Get-Content $IndexJsonFile | Out-String |
| 75 | + [Reflection.Assembly]::LoadFile("$Here\lib\Newtonsoft.Json.dll") |
| 76 | + [System.Reflection.Assembly]::LoadWithPartialName("System") |
| 77 | + $hashTable = [Newtonsoft.Json.JsonConvert]::DeserializeObject($unsorted, [System.Collections.Generic.SortedDictionary[[string],[object]]]) |
| 78 | + $obj = [Newtonsoft.Json.JsonConvert]::SerializeObject($hashTable, [Newtonsoft.Json.Formatting]::Indented) |
| 79 | + Set-Content -Path $IndexJsonFile -Value $obj |
| 80 | + |
| 81 | + #setup clone directory |
| 82 | + $TEMP_REPO_DIR =(Split-Path -parent $SolutionRoot) + "\temp-repo-clone" |
| 83 | + |
| 84 | + If(test-path $TEMP_REPO_DIR) |
| 85 | + { |
| 86 | + Remove-Item $TEMP_REPO_DIR -Force -Recurse |
| 87 | + } |
| 88 | + |
| 89 | + New-Item -ItemType Directory -Force -Path $TEMP_REPO_DIR |
| 90 | + |
| 91 | + #clone |
| 92 | + git clone https://github.com/$GitHubUserName/$GitHubProjectName.git --branch master $TEMP_REPO_DIR |
| 93 | + |
| 94 | + If(test-path "$TEMP_REPO_DIR\docs") |
| 95 | + { |
| 96 | + Remove-Item "$TEMP_REPO_DIR\docs" -Force -Recurse |
| 97 | + } |
| 98 | + New-Item -ItemType Directory -Force -Path "$TEMP_REPO_DIR\docs" |
| 99 | + |
| 100 | + #cd to docs folder |
| 101 | + cd "$TEMP_REPO_DIR\docs" |
| 102 | + |
| 103 | + #copy docs to clone directory\docs |
| 104 | + Copy-Item -Path "$SolutionRoot\docs\*" -Destination "$TEMP_REPO_DIR\docs" -Recurse -Force |
| 105 | + |
| 106 | + #push changes to master |
| 107 | + git config --global credential.helper store |
| 108 | + Add-Content "$HOME\.git-credentials" "https://$($env:github_access_token):[email protected]`n" |
| 109 | + git config --global user.email $env:github_email |
| 110 | + git config --global user.name "buildbot121" |
| 111 | + git add . -A |
| 112 | + git commit -m "Maintanance commit by build server" |
| 113 | + git push origin master |
| 114 | + |
| 115 | + #move cd back to current location |
| 116 | + cd $Here |
| 117 | + } |
| 118 | +} |
| 119 | + |
| 120 | +#package nuget files |
| 121 | +Task Package -depends Document { |
| 122 | + exec { . $NuGet pack "$SolutionRoot\$ProjectName\$ProjectName.nuspec" -Properties Configuration=$Configuration -OutputDirectory "$SolutionRoot" -Version "$Version" } |
| 123 | +} |
0 commit comments