Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making arcade self buildable #1407

Merged
merged 23 commits into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,25 @@ jobs:
variables:
# Only enable publishing in non-public, non PR scenarios.
- ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}:
# DotNet-Blob-Feed provides: dotnetfeed-storage-access-key-1
# DotNet-Symbol-Server-Pats provides: microsoft-symbol-server-pat, symweb-symbol-server-pat
# Publish-Build-Assets provides: MaestroAccessToken, BotAccount-dotnet-maestro-bot-PAT
- group: DotNet-Blob-Feed
jcagme marked this conversation as resolved.
Show resolved Hide resolved
- group: DotNet-Symbol-Server-Pats
- group: Publish-Build-Assets
- name: _PublishBlobFeedUrl
value: https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json
- name: _SignArgs
- name: _InternalBuildArgs
value: /p:DotNetSignType=$(_SignType) /p:TeamName=$(_TeamName)
- name: _PublishArgs
value: /p:DotNetPublishBlobFeedKey=$(dotnetfeed-storage-access-key-1)
/p:DotNetPublishBlobFeedKey=$(dotnetfeed-storage-access-key-1)
/p:DotNetPublishBlobFeedUrl=$(_PublishBlobFeedUrl)
/p:DotNetPublishToBlobFeed=$(_DotNetPublishToBlobFeed)
/p:DotNetSymbolServerTokenMsdl=$(microsoft-symbol-server-pat)
/p:DotNetSymbolServerTokenSymWeb=$(symweb-symbol-server-pat)
- name: _OfficialBuildIdArgs
value: /p:OfficialBuildId=$(BUILD.BUILDNUMBER)
/p:OfficialBuildId=$(BUILD.BUILDNUMBER)
# else
- ${{ if or(eq(variables['System.TeamProject'], 'public'), in(variables['Build.Reason'], 'PullRequest')) }}:
- name: _PublishArgs
value: ''
- name: _OfficialBuildIdArgs
value: ''
- name: _SignArgs
- name: _InternalBuildArgs
value: ''
strategy:
matrix:
Expand All @@ -57,27 +55,31 @@ jobs:
_PublishType: none
_SignType: test
_DotNetPublishToBlobFeed : false
_Script: eng\common\cibuild.cmd
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might just do something like this for "_Script"

variables:
- name: _Script:
  value: eng\common\cibuild.cmd
- name: _ValidateSdkArgs
  value: ''
strategy:
  matrix:
    Build_Debug:
      _BuildConfig: Debug
      _PublishType: none
      _SignType: test
      _DotNetPublishToBlobFeed: false
    Build_Release:
      _BuildConfig: Release
      ${{ if or(eq(variables['System.TeamProject'], 'public'), in(variables['Build.Reason'], 'PullRequest')) }}:
        _PublishType: none
        _SignType: test
        _DotNetPublishToBlobFeed : false
      ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}:
        _PublishType: blob
        _SignType: real
        _DotNetPublishToBlobFeed : true
        _Script: eng\validate-sdk.cmd
        _ValidateSdkArgs: -gitHubPat $(BotAccount-dotnet-maestro-bot-PAT) -barToken $(MaestroAccessToken)

I think that will resolve correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, way better!

_ValidateSdkArgs: ''
Build_Release:
_BuildConfig: Release
# PRs or external builds are not signed.
${{ if or(eq(variables['System.TeamProject'], 'public'), in(variables['Build.Reason'], 'PullRequest')) }}:
_PublishType: none
_SignType: test
_DotNetPublishToBlobFeed : false
_Script: eng\common\cibuild.cmd
${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}:
_PublishType: blob
_SignType: real
_DotNetPublishToBlobFeed : true
_Script: eng\validate-sdk.cmd
_ValidateSdkArgs: -gitHubPat $(BotAccount-dotnet-maestro-bot-PAT) -barToken $(MaestroAccessToken)
steps:
- checkout: self
clean: true
# Use utility script to run script command dependent on agent OS.
- script: eng\common\cibuild.cmd
- script: $(_Script)
-configuration $(_BuildConfig)
-prepareMachine
$(_PublishArgs)
$(_SignArgs)
$(_OfficialBuildIdArgs)
$(_InternalBuildArgs)
$(_ValidateSdkArgs)
displayName: Windows Build / Publish

- job: Linux
Expand Down
17 changes: 17 additions & 0 deletions eng/Tools.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- All Rights Reserved. Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
<Project>

<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>

<PropertyGroup>
<!--When we are doing SDK validation we place the locally built packages in a custom path. This has to be propagated so the next
build can restore the local packages.-->
<RestoreSources Condition="'$(ArcadeSelfTest)' == 'true'">
jcagme marked this conversation as resolved.
Show resolved Hide resolved
$(RestoreSources);
$(ArtifactsDir)validatesdk\packages\$(Configuration)\NonShipping
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like a strange and fragile coupling. Couldn't this just be something like...

<PropertyGroup>
  <ResourceSources>
    $(RestoreSources);
    $(AdditionalRestoreSources);
  </ResourceSources>
</PropertyGroup>

and then this line in validate-sdk.ps1...

  . .\common\build.ps1 -configuration $configuration @Args  /p:ArcadeSelfTest=true

… becomes...

  . .\common\build.ps1 -configuration $configuration @Args /p:AdditionalRestoreSources=$packagesSource 

</RestoreSources>
</PropertyGroup>
</Project>
3 changes: 1 addition & 2 deletions eng/common/CIBuild.cmd
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
@echo off
powershell -ExecutionPolicy ByPass -NoProfile -command "& """%~dp0Build.ps1""" -restore -build -test -sign -pack -publish -ci %*"
exit /b %ErrorLevel%
powershell -ExecutionPolicy ByPass -NoProfile -command "& """%~dp0Build.ps1""" -restore -build -test -sign -pack -publish -ci %*"
5 changes: 4 additions & 1 deletion eng/common/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Param(
[string] $projects = "",
[string][Alias('v')]$verbosity = "minimal",
[string] $msbuildEngine = $null,
[string] $logFileName = "Build.binlog",
jcagme marked this conversation as resolved.
Show resolved Hide resolved
[bool] $warnAsError = $true,
[bool] $nodeReuse = $true,
[switch] $execute,
Expand Down Expand Up @@ -57,6 +58,8 @@ function Print-Usage() {
Write-Host " -prepareMachine Prepare machine for CI run"
Write-Host " -msbuildEngine <value> Msbuild engine to use to run build ('dotnet', 'vs', or unspecified)."
Write-Host ""
Write-Host "Optional settings:"
Write-Host " -logFileName <value> Binlog file name"
Write-Host "Command line arguments not listed above are passed thru to msbuild."
Write-Host "The above arguments can be shortened as much as to be unambiguous (e.g. -co for configuration, -t for test, etc.)."
}
Expand All @@ -77,7 +80,7 @@ function InitializeCustomToolset {
function Build {
$toolsetBuildProj = InitializeToolset
InitializeCustomToolset
$bl = if ($binaryLog) { "/bl:" + (Join-Path $LogDir "Build.binlog") } else { "" }
$bl = if ($binaryLog) { "/bl:" + (Join-Path $LogDir $logFileName) } else { "" }

MSBuild $toolsetBuildProj `
$bl `
Expand Down
5 changes: 4 additions & 1 deletion eng/common/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ usage()
echo " --nodeReuse <value> Sets nodereuse msbuild parameter ('true' or 'false')"
echo " --warnAsError <value> Sets warnaserror msbuild parameter ('true' or 'false')"
echo ""
echo "Optional settings:"
echo " -logFileName <value> Binlog file name"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed anymore.

echo "Command line arguments starting with '/p:' are passed through to MSBuild."
}

Expand Down Expand Up @@ -62,6 +64,7 @@ projects=''
configuration='Debug'
prepare_machine=false
verbosity='minimal'
logFileName='Build.binlog'
properties=''

while [[ $# > 0 ]]; do
Expand Down Expand Up @@ -165,7 +168,7 @@ function Build {

local bl=""
if [[ "$binary_log" == true ]]; then
bl="/bl:\"$log_dir/Build.binlog\""
bl="/bl:\"$log_dir/$logFileName\""
fi

MSBuild $_InitializeToolset \
Expand Down
2 changes: 2 additions & 0 deletions eng/validate-sdk.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
powershell -ExecutionPolicy ByPass -NoProfile -command "& """%~dp0validate-sdk.ps1""" -restore -build -test -sign -pack -publish -ci %*"
95 changes: 95 additions & 0 deletions eng/validate-sdk.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
Param(
[string] $barToken,
[string] $gitHubPat,
[string] $configuration = "Debug"
)

$ErrorActionPreference = "Stop"
. $PSScriptRoot\common\tools.ps1
$LocalNugetConfigSourceName = "arcade-local"

function Check-ExitCode ($exitCode)
{
if ($exitCode -ne 0) {
Write-Host "Arcade self-build failed"
ExitWithExitCode $exitCode
}
}

function StopDotnetIfRunning
{
$dotnet = Get-Process "dotnet" -ErrorAction SilentlyContinue
if ($dotnet) {
stop-process $dotnet
}
}

function AddSourceToNugetConfig([string]$nugetConfigPath, [string]$source)
{
Write-Host "Adding '$source' to '$nugetConfigPath'..."

$nugetConfig = New-Object XML
$nugetConfig.PreserveWhitespace = $true
$nugetConfig.Load($nugetConfigPath)
$packageSources = $nugetConfig.SelectSingleNode("//packageSources")
$keyAttribute = $nugetConfig.CreateAttribute("key")
$keyAttribute.Value = $LocalNugetConfigSourceName
$valueAttribute = $nugetConfig.CreateAttribute("value")
$valueAttribute.Value = $source
$newSource = $nugetConfig.CreateElement("add")
$newSource.Attributes.Append($keyAttribute)
$newSource.Attributes.Append($valueAttribute)
$packageSources.AppendChild($newSource)
$nugetConfig.Save($nugetConfigPath)
}

try {
Write-Host "STEP 1: Build and create local packages"

Push-Location $PSScriptRoot

$validateSdkDir = "$ArtifactsDir\validatesdk\\"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the double backslash?

Copy link
Contributor Author

@jcagme jcagme Dec 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was originally a typo but when fixing it I realized that somewhere in the process last \ is removed ending up in folders like "validatesdktoolset". I searched the source and could not find a place where this could happen. $properties in build.ps1 does receive the correct value so is probably something MSBuild does is stripping that last '' from the path. @tmat do you know what might be causing this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Join-Path

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using Join-Path had no effect. Again, I think this is been removed in MSBuild rather than at the PS1 level

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may need to do a check at https://github.com/dotnet/arcade/blob/master/src/Microsoft.DotNet.Arcade.Sdk/tools/RepoLayout.props#L54 and ensure the path provided properly ends with a \

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually based on the last change we won't need to set the ArtifactDir anymore so this is a no-op now

$packagesSource = "$validateSdkDir\packages\$configuration\NonShipping"
$toolsProjPath = "$RepoRoot\src\Microsoft.DotNet.Arcade.Sdk\tools\Tools.proj"
$nugetConfigPath = "$RepoRoot\NuGet.config"

# When restoring, we check if local sources defined in Tools.proj actually exist so we need to create
# the validation SDK folder beforehand
if (!(Test-Path -Path $packagesSource)) {
Create-Directory $packagesSource
}
jcagme marked this conversation as resolved.
Show resolved Hide resolved

. .\common\build.ps1 -restore -build -pack -configuration $configuration -logFileName "Build_Local.binlog" /p:ArtifactsDir=$validateSdkDir

Write-Host "STEP 2: Build using the local packages"

AddSourceToNugetConfig $nugetConfigPath $packagesSource

Write-Host "Updating Dependencies using Darc..."

. .\common\darc-init.ps1

$DarcExe = "$env:USERPROFILE\.dotnet\tools"
$DarcExe = Resolve-Path $DarcExe

& $DarcExe\darc.exe update-dependencies --packages-folder $packagesSource --password $barToken --github-pat $gitHubPat --channel ".NET Tools - Latest"

Check-ExitCode $lastExitCode
StopDotnetIfRunning

Write-Host "Building with updated dependencies"

. .\common\build.ps1 -configuration $configuration @Args /p:ArcadeSelfTest=true
}
catch {
Write-Host $_
Write-Host $_.Exception
Write-Host $_.ScriptStackTrace
ExitWithExitCode 1
}
finally {
Write-Host "Cleaning up workspace..."
StopDotnetIfRunning
Pop-Location
Write-Host "Finished building Arcade SDK with validation enabled!"
}