Skip to content

Commit

Permalink
Publish .NET Symbol Service at compile-time
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Salas committed Apr 3, 2018
1 parent d18cec1 commit edd6b10
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .gitignore
Expand Up @@ -14,4 +14,6 @@ outputs/
/distrib/dependencies/
/fetch-cache

*.log
*.log

dotnet-symbol-service-last-commit
20 changes: 20 additions & 0 deletions build.sbt
Expand Up @@ -153,6 +153,26 @@ lazy val HQ = Project("HQ", file("hq"))
lazy val CodePulse = Project("CodePulse", file("codepulse"))
.dependsOn(Shared, HQ)
.settings(
compile in Compile := (Def.taskDyn {
val c = (compile in Compile).value
Def.task {
import sys.process._

var powershellCmd = "powershell"
if (System.getProperty("os.name") == "Linux") {
powershellCmd = "pwsh"
}

val publishCmd = powershellCmd + " -file publish-symbol-service.ps1"
println("Running: " + publishCmd)

val exitCode = publishCmd.!

val msg = if (exitCode == 0) "The .NET Symbol Service is up-to-date" else "ERROR: UNABLE TO PUBLISH .NET SYMBOL SERVICE!!!"
println(msg)
c
}
}).value,
baseSettings,
scalaSettings,
withTesting,
Expand Down
62 changes: 62 additions & 0 deletions publish-symbol-service.ps1
@@ -0,0 +1,62 @@
Set-PSDebug -Strict
$ErrorActionPreference = 'Stop'
$VerbosePreference = 'Continue'

Set-Location $PSScriptRoot

function Get-OSRID() {
if ([environment]::Is64BitOperatingSystem -and [Runtime.InteropServices.RuntimeInformation]::IsOSPlatform([Runtime.InteropServices.OSPlatform]::Windows)) {
return 'win-x64'
}
if ([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform([Runtime.InteropServices.OSPlatform]::OSX)) {
return 'osx-x64'
}
if ([environment]::Is64BitOperatingSystem -and [Runtime.InteropServices.RuntimeInformation]::IsOSPlatform([Runtime.InteropServices.OSPlatform]::Linux)) {
return 'linux-x64'
}
}

function Get-SavedCommitHash() {
if (-not (test-path dotnet-symbol-service-last-commit -pathtype leaf)) {
return [string]::Empty
}
Get-Content -Path dotnet-symbol-service-last-commit | select-object -first 1
}

function Set-SavedCommitHash([string] $commitHash) {
Set-Content -Path dotnet-symbol-service-last-commit -Value $commitHash
}

function Get-LastCommit([string] $sinceCommitHash) {
if ($sinceCommitHash -eq [string]::Empty) {
$log = git log --oneline dotnet-symbol-service | select-object -first 1
} else {
$log = git log "$sinceCommitHash..HEAD" --oneline dotnet-symbol-service | select-object -first 1
}

if ($log -eq $null) {
return $null
}
$log.substring(0, $log.indexof(' '))
}

function Invoke-Publish() {
push-location 'dotnet-symbol-service'
dotnet publish -c Release -r (Get-OSRID) -o ..\..\dotnet-symbol-service\publish
if ($LASTEXITCODE -ne 0) {
write-error "Failed to publish with exit code $LASTEXITCODE"
exit $LASTEXITCODE
}
pop-location
}

$savedCommitHash = Get-SavedCommitHash
$lastCommitHash = Get-LastCommit $savedCommitHash
if ($lastCommitHash -eq $null) {
exit 0
}

Invoke-Publish
Set-SavedCommitHash $lastCommitHash

exit 0

0 comments on commit edd6b10

Please sign in to comment.