Skip to content

Commit

Permalink
New build system
Browse files Browse the repository at this point in the history
  • Loading branch information
bradwilson committed Aug 27, 2019
1 parent c054815 commit 9f40d46
Show file tree
Hide file tree
Showing 30 changed files with 795 additions and 158 deletions.
4 changes: 4 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"version": "0.2.0",
"configurations": []
}
17 changes: 17 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"cSpell.words": [
"app",
"nuget",
"nupkg",
"parallelization",
"veyor"
],
"files.exclude": {
"**/.git": true,
"**/.DS_Store": true,
"**/bin": true,
"**/obj": true,
"artifacts": true,
"packages": true
}
}
89 changes: 89 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"type": "process",
"command": "dotnet",
"args": [
"run",
"--project",
"tools/builder",
"--no-launch-profile",
"--",
"Build"
],
"options": {
"cwd": "${workspaceRoot}"
},
"group": "build",
"presentation": {
"focus": true
},
"problemMatcher": []
},
{
"label": "Pre-PR Validation",
"type": "process",
"command": "dotnet",
"args": [
"run",
"--project",
"tools/builder",
"--no-launch-profile",
"--",
"Packages"
],
"options": {
"cwd": "${workspaceRoot}"
},
"group": "build",
"presentation": {
"focus": true
},
"problemMatcher": []
},
{
"label": "Unit Tests (.NET Core)",
"type": "process",
"command": "dotnet",
"args": [
"run",
"--project",
"tools/builder",
"--no-launch-profile",
"--",
"TestCore"
],
"options": {
"cwd": "${workspaceRoot}"
},
"group": "build",
"presentation": {
"focus": true
},
"problemMatcher": []
},
{
"label": "Unit Tests (.NET Framework)",
"type": "process",
"command": "dotnet",
"args": [
"run",
"--project",
"tools/builder",
"--no-launch-profile",
"--",
"TestFx"
],
"options": {
"cwd": "${workspaceRoot}"
},
"group": "build",
"presentation": {
"focus": true
},
"problemMatcher": []
}
]
}
3 changes: 1 addition & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ nuget:
disable_publish_on_pr: true

build_script:
- ps: .\build.ps1 -target appveyor -buildAssemblyVersion ($env:BuildVersion + $env:APPVEYOR_BUILD_NUMBER) -buildSemanticVersion ($env:BuildSemanticVersion + $env:APPVEYOR_BUILD_NUMBER)
- ps: .\build.ps1 ci --buildAssemblyVersion ($env:BuildVersion + $env:APPVEYOR_BUILD_NUMBER) --buildSemanticVersion ($env:BuildSemanticVersion + $env:APPVEYOR_BUILD_NUMBER)

test: off

Expand All @@ -49,7 +49,6 @@ deploy: off
artifacts:
- path: artifacts/packages
- path: artifacts/test
- path: artifacts/build

notifications:
- provider: Slack
Expand Down
28 changes: 28 additions & 0 deletions build
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
set -euo pipefail

PUSHED=0

cleanup () {
if [[ $PUSHED == 1 ]]; then
popd >/dev/null
PUSHED=0
fi
}

trap cleanup EXIT ERR INT TERM

if which dotnet > /dev/null; then
if which mono > /dev/null; then
pushd $( cd "$(dirname "$0")" ; pwd -P ) >/dev/null
PUSHED=1

dotnet run --project tools/builder --no-launch-profile -- "$@"
else
echo "error(1): Could not find 'mono'; please install Mono" 2>&1
exit 1
fi
else
echo "error(1): Could not find 'dotnet'; please install the .NET Core SDK" 2>&1
exit 1
fi
154 changes: 11 additions & 143 deletions build.ps1
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,150 +1,18 @@
param(
[string] $target = "test",
[string] $configuration = "Release",
[string] $buildAssemblyVersion = "",
[string] $buildSemanticVersion = ""
)
#!/usr/bin/env pwsh
#Requires -Version 5.1

if ($PSScriptRoot -eq $null) {
fatal "This build script requires PowerShell 3 or later."
}

$buildModuleFile = join-path $PSScriptRoot "build\tools\xunit-build-module.psm1"

if ((test-path $buildModuleFile) -eq $false) {
write-host "Could not find build module. Did you forget to 'git submodule update --init'?" -ForegroundColor Red
exit -1
}

Set-StrictMode -Version 2
Import-Module $buildModuleFile -Scope Local -Force -ArgumentList "4.1.0"
Set-Location $PSScriptRoot

$packageOutputFolder = (join-path (Get-Location) "artifacts\packages")
$parallelFlags = "-parallel all -maxthreads 16"
$testOutputFolder = (join-path (Get-Location) "artifacts\test")
$solutionFolder = Get-Location

$signClientVersion = "0.9.1"
$signClientFolder = (join-path (Get-Location) "packages\SignClient.$signClientVersion")
$signClientAppSettings = (join-path (Get-Location) "tools\SignClient\appsettings.json")

# Helper functions

function _xunit_console([string] $command) {
_exec ('& "' + $PSScriptRoot + '\packages\xunit.runner.console\tools\net472\xunit.console.x86.exe" ' + $command)
}
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"

# Top-level targets

function __target_appveyor() {
__target_ci
__target__signpackages
__target__pushmyget
}

function __target_build() {
__target_packagerestore

_build_step "Compiling binaries"
_msbuild "xunit.analyzers.sln" $configuration

_dotnet ("tools\DocBuilder\bin\Release\netcoreapp2.1\Xunit.Analyzers.DocBuilder.dll " + (Join-Path $PSScriptRoot "docs")) # "Verifying documentation files"
if ($null -eq (Get-Command "dotnet" -ErrorAction Ignore)) {
throw "Could not find 'dotnet'; please install the .NET Core SDK"
}

function __target_ci() {
__target__setversion
__target_test
__target__packages
}

function __target_packagerestore() {
_download_nuget
Push-Location (Split-Path $MyInvocation.MyCommand.Definition)

_build_step "Restoring NuGet packages"
_mkdir packages
_exec ('& "' + $nugetExe + '" restore xunit.analyzers.sln -NonInteractive')
_exec ('& "' + $nugetExe + '" install xunit.runner.console -OutputDirectory "' + (Join-Path $PSScriptRoot "packages") + '" -NonInteractive -ExcludeVersion')
try {
& dotnet run --project tools/builder --no-launch-profile -- $args
}

function __target_packages() {
__target_build
__target__packages
}

function __target_test() {
__target_build
__target__test
finally {
Pop-Location
}

# Dependent targets

function __target__packages() {
_download_nuget

_build_step "Creating NuGet packages"
Get-ChildItem -Recurse -Filter *.nuspec | _nuget_pack -outputFolder $packageOutputFolder -configuration $configuration
}

function __target__pushmyget() {
_build_step "Pushing packages to MyGet"
if ($env:MyGetApiKey -eq $null) {
Write-Host -ForegroundColor Yellow "Skipping MyGet push because environment variable 'MyGetApiKey' is not set."
Write-Host ""
} else {
Get-ChildItem -Filter *.nupkg $packageOutputFolder | _nuget_push -source https://www.myget.org/F/xunit/api/v2/package -apiKey $env:MyGetApiKey
}
}

function __target__setversion() {
if ($buildAssemblyVersion -ne "") {
_build_step ("Setting assembly version: '" + $buildAssemblyVersion + "'")
Get-ChildItem -Recurse -Filter AssemblyInfo.cs | _replace -match '\("99\.99\.99\.0"\)' -replacement ('("' + $buildAssemblyVersion + '")')
}

if ($buildSemanticVersion -ne "") {
_build_step ("Setting semantic version: '" + $buildSemanticVersion + "'")
Get-ChildItem -Recurse -Filter AssemblyInfo.cs | _replace -match '\("99\.99\.99-dev"\)' -replacement ('("' + $buildSemanticVersion + '")')
Get-ChildItem -Recurse -Filter *.nuspec | _replace -match '99\.99\.99-dev' -replacement $buildSemanticVersion
}
}

function __target__signpackages() {
if ($env:SignClientSecret -ne $null) {
if ((test-path $signClientFolder) -eq $false) {
_build_step ("Downloading SignClient " + $signClientVersion)
_exec ('& "' + $nugetExe + '" install SignClient -version ' + $signClientVersion + ' -SolutionDir "' + $solutionFolder + '" -Verbosity quiet -NonInteractive')
}

_build_step "Signing NuGet packages"
$appPath = (join-path $signClientFolder "tools\netcoreapp2.0\SignClient.dll")
$nupgks = Get-ChildItem (join-path $packageOutputFolder "*.nupkg") | ForEach-Object { $_.FullName }
foreach ($nupkg in $nupgks) {
$cmd = '& dotnet "' + $appPath + '" sign -c "' + $signClientAppSettings + '" -r "' + $env:SignClientUser + '" -s "' + $env:SignClientSecret + '" -n "xUnit.net" -d "xUnit.net" -u "https://github.com/xunit/xunit.analyzers" -i "' + $nupkg + '"'
$msg = $cmd.Replace($env:SignClientSecret, '[Redacted]')
$msg = $msg.Replace($env:SignClientUser, '[Redacted]')
_exec $cmd $msg
}
}
}

function __target__test() {
_build_step "Running unit tests"
_xunit_console ("test\xunit.analyzers.tests\bin\" + $configuration + "\net472\xunit.analyzers.tests.dll -xml artifacts\test\TestResults.xml -diagnostics")
}

# Dispatch

$targetFunction = (Get-ChildItem ("Function:__target_" + $target.ToLowerInvariant()) -ErrorAction SilentlyContinue)
if ($targetFunction -eq $null) {
_fatal "Unknown target '$target'"
}

_build_step "Performing pre-build verifications"
_require dotnet "Could not find 'dotnet'. Please ensure .NET CLI Tooling is installed."
_require msbuild "Could not find 'msbuild'. Please ensure MSBUILD.EXE v15 is on the path."
_verify_msbuild15

_mkdir $packageOutputFolder
_mkdir $testOutputFolder
& $targetFunction
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.CodeAnalysis.CodeFixes;
using System;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Diagnostics;

namespace Xunit.Analyzers
Expand Down Expand Up @@ -86,6 +87,10 @@ public void Test1()
}";
var actual = await CodeAnalyzerHelper.GetFixedCodeAsync(analyzer, fixer, original);

// Code fixer always inserts \r\n even on Linux, so fix up the actual result
if (Environment.NewLine != "\r\n")
actual = actual.Replace("\r\n", Environment.NewLine);

Assert.Equal(expected, actual);
}
}
Expand Down
Loading

0 comments on commit 9f40d46

Please sign in to comment.