diff --git a/.github/workflows/dependencies/DotnetDocsTools.LocateProjects.2.0.0.nupkg b/.github/workflows/dependencies/DotnetDocsTools.LocateProjects.2.0.0.nupkg deleted file mode 100644 index 8da2539f261..00000000000 Binary files a/.github/workflows/dependencies/DotnetDocsTools.LocateProjects.2.0.0.nupkg and /dev/null differ diff --git a/.github/workflows/dependencies/Get-MSBuildResults.ps1 b/.github/workflows/dependencies/Get-MSBuildResults.ps1 deleted file mode 100644 index 9d80d95ea2e..00000000000 --- a/.github/workflows/dependencies/Get-MSBuildResults.ps1 +++ /dev/null @@ -1,312 +0,0 @@ -<# - -.SYNOPSIS - Invokes dotnet build on the samples sln and project files. - -.DESCRIPTION - Invokes dotnet build on the samples sln and project files. - -.PARAMETER RepoRootDir - The directory of the repository files on the local machine. - -.PARAMETER PullRequest - The pull requst to process. If 0 or not passed, processes the whole repo - -.PARAMETER RepoOwner - The name of the repository owner. - -.PARAMETER RepoName - The name of the repository. - -.PARAMETER RangeStart - A range of results to process. - -.PARAMETER RangeEnd - A range of results to process. - -.INPUTS - None - -.OUTPUTS - None - -.NOTES - Version: 1.6 - Author: adegeo@microsoft.com - Creation Date: 12/11/2020 - Update Date: 03/10/2022 - Purpose/Change: Export proj/sln settings config to output.json file. -#> - -[CmdletBinding()] -Param( - [Parameter(Mandatory = $true, ValueFromPipeline = $false)] - [System.String] $RepoRootDir = $env:RepoRootDir, - - [Parameter(Mandatory = $false, ValueFromPipeline = $false)] - [System.Int64] $PullRequest = 0, - - [Parameter(Mandatory = $false, ValueFromPipeline = $false)] - [System.String] $RepoOwner = "", - - [Parameter(Mandatory = $false, ValueFromPipeline = $false)] - [System.String] $RepoName = "", - - [Parameter(Mandatory = $false, ValueFromPipeline = $false)] - [System.Int32] $RangeStart = $env:rangestart, - - [Parameter(Mandatory = $false, ValueFromPipeline = $false)] - [System.Int32] $RangeEnd = $env:rangeend -) - -$Global:statusOutput = @() - -Write-Host "Gathering solutions and projects... (v1.6)" - -if ($PullRequest -ne 0) { - Write-Host "Running `"LocateProjects `"$RepoRootDir`" --pullrequest $PullRequest --owner $RepoOwner --repo $RepoName`"" - $output = Invoke-Expression "LocateProjects `"$RepoRootDir`" --pullrequest $PullRequest --owner $RepoOwner --repo $RepoName" -} -else { - Write-Host "Running `"LocateProjects `"$RepoRootDir`"" - $output = Invoke-Expression "LocateProjects `"$RepoRootDir`"" -} - -if ($LASTEXITCODE -ne 0) -{ - $output - throw "Error on running LocateProjects" -} - -function New-Result($inputFile, $projectFile, $exitcode, $outputText, $settingsJson) -{ - $info = @{} - - $info.InputFile = $inputFile - $info.ProjectFile = $projectFile - $info.ExitCode = $exitcode - $info.Output = $outputText - $info.Settings = $settingsJson - - $object = New-Object -TypeName PSObject -Prop $info - $Global:statusOutput += $object -} - -$workingSet = $output - -if (($RangeStart -ne 0) -and ($RangeEnd -ne 0)){ - $workingSet = $output[$RangeStart..$RangeEnd] -} - -# Log working set items prior to filtering -$workingSet | Write-Host - -# Remove duplicated projects -$projects = @() -$workingSetTemp = @() - -foreach ($item in $workingSet) { - $data = $item.Split('|') - if ($projects.Contains($data[2].Trim())) { - continue - } - if ($data[2].Trim() -ne "") { - $projects += $data[2].Trim() - } - $workingSetTemp += $item -} - -$workingSet = $workingSetTemp - -# Process working set -$counter = 1 -$length = $workingSet.Count -$thisExitCode = 0 - -$ErrorActionPreference = "Continue" - -foreach ($item in $workingSet) { - try { - Write-Host "$counter/$length :: $Item" - - $data = $item.Split('|') - - # this was added to avoid compile errors in the dotnet/samples repo mono-samples folder. - # I don't think this is needed now that we have ways to avoid errors - # leaving this here for reference - # - #if ($data[1].Contains("mono-samples")){ - # Write-Host "Found mono-sample project, Skipping." - # $counter++ - # Continue - #} - - # Project found, build it - if ([int]$data[0] -eq 0) { - $projectFile = Resolve-Path "$RepoRootDir\$($data[2])" - $configFile = [System.IO.Path]::Combine([System.IO.Path]::GetDirectoryName($projectFile), "snippets.5000.json") - $settings = $null - - # Create the default build command - "dotnet build `"$projectFile`"" | Out-File ".\run.bat" - - # Check for config file - if ([System.IO.File]::Exists($configFile) -eq $true) { - Write-Host "- Config file found" - - $settings = $configFile | Get-ChildItem | Get-Content | ConvertFrom-Json - - if ($settings.host -eq "visualstudio") { - Write-Host "- Using visual studio as build host" - - # Create the visual studio build command - "CALL `"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat`"`n" + - "nuget.exe restore `"$projectFile`"`n" + - "msbuild.exe `"$projectFile`" -restore:True" ` - | Out-File ".\run.bat" - } - elseif ($settings.host -eq "custom") { - Write-Host "- Using custom build host: $($settings.command)" - - $ExecutionContext.InvokeCommand.ExpandString($settings.command) | Out-File ".\run.bat" - } - elseif ($settings.host -eq "dotnet") { - Write-Host "- Using dotnet build host" - - "dotnet build `"$projectFile`"" | Out-File ".\run.bat" - } - else { - throw "snippets.5000.json file isn't valid." - } - } - - Write-Host "run.bat contents: " - Get-Content .\run.bat | Write-Host - Write-Host - - $thisExitCode = 0 - - Invoke-Expression ".\run.bat" | Out-String | Tee-Object -Variable "result" - - if ($LASTEXITCODE -ne 0) { - $thisExitCode = 4 - } - - New-Result $data[1] $projectFile $thisExitCode $result $settings - } - - # No project found - elseif ([int]$data[0] -eq 1) { - New-Result $data[1] "" 1 "😵 Project missing. A project (and optionally a solution file) must be in this directory or one of the parent directories to validate and build this code." $null - - $thisExitCode = 1 - } - - # Too many projects found - elseif ([int]$data[0] -eq 2) { - New-Result $data[1] $data[2] 2 "😕 Too many projects found. A single project or solution must exist in this directory or one of the parent directories." $null - - $thisExitCode = 2 - } - - # Solution found, but no project - elseif ([int]$data[0] -eq 3) { - New-Result $data[1] $data[2] 2 "😲 Solution found, but missing project. A project is required to compile this code." $null - $thisExitCode = 3 - } - } - catch { - New-Result $data[1] $projectFile 1000 "ERROR: $($_.Exception)" $null - $thisExitCode = 4 - Write-Host $_.Exception.Message -Foreground "Red" - Write-Host $_.ScriptStackTrace -Foreground "DarkGray" - } - - $counter++ -} - -$resultItems = $Global:statusOutput | Select-Object InputFile, ProjectFile, ExitCode, Output, Settings - -# Add our output type -$typeResult = @" -public class ResultItem -{ - public string ProjectFile; - public string InputFile; - public int ExitCode; - public string BuildOutput; - public object Settings; - public MSBuildError[] Errors; - public int ErrorCount; - - public class MSBuildError - { - public string Line; - public string Error; - } -} -"@ -Add-Type $typeResult - -$transformedItems = $resultItems | ForEach-Object { New-Object ResultItem -Property @{ - ProjectFile = $_.ProjectFile.Path; - InputFile = $_.InputFile; - ExitCode = $_.ExitCode; - BuildOutput = $_.Output; - Settings = $_.Settings; - Errors = @(); - ErrorCount = 0; - } } - -# Transform the build output to break it down into MSBuild result entries -foreach ($item in $transformedItems) { - $list = @() - - # Clean - if ($item.ExitCode -eq 0) { - #$list += New-Object -TypeName "ResultItem+MSBuildError" -Property @{ Line = $item.BuildOutput; Error = $item.BuildOutput } - } - # No project found - # Too many projects found - # Solution found, but no project - elseif ($item.ExitCode -ne 4) { - $list += New-Object -TypeName "ResultItem+MSBuildError" -Property @{ Line = $item.BuildOutput; Error = $item.BuildOutput } - $item.ErrorCount = 1 - } - - # Actual build error found - else { - $errorInfo = $item.BuildOutput -Split [System.Environment]::NewLine | - Select-String ": (?:Solution file error|error) ([^:]*)" | ` - Select-Object Line -ExpandProperty Matches | ` - Select-Object Line, Groups | ` - Sort-Object Line | Get-Unique -AsString - $item.ErrorCount = $errorInfo.Count - foreach ($err in $errorInfo) { - $list += New-Object -TypeName "ResultItem+MSBuildError" -Property @{ Line = $err.Line; Error = $err.Groups[1].Value } - } - - # Error count of 0 here means that no error was detected from build results, but there was still a failure of some kind - if ($item.ErrorCount -eq 0) { - $list += New-Object -TypeName "ResultItem+MSBuildError" -Property @{ Line = "Unknown error occurred. Check log and build output."; Error = "4" } - $item.ErrorCount = 1 - } - } - - # Set build errors - $item.Errors = $list - -} - -$transformedItems | ConvertTo-Json -Depth 4 | Out-File 'output.json' - -exit 0 - - -# Sample snippets.5000.json file -<# -{ - "host": "visualstudio" -} - -#> diff --git a/.github/workflows/dependencies/Out-GithubActionStatus.ps1 b/.github/workflows/dependencies/Out-GithubActionStatus.ps1 deleted file mode 100644 index b116a856d6f..00000000000 --- a/.github/workflows/dependencies/Out-GithubActionStatus.ps1 +++ /dev/null @@ -1,79 +0,0 @@ -<# - -.SYNOPSIS - Reads the output.json file and outputs status to GitHub Actions - -.DESCRIPTION - Reads the output.json file and outputs status to GitHub Actions - -.INPUTS - None - -.OUTPUTS - None - -.NOTES - Version: 1.2 - Author: adegeo@microsoft.com - Creation Date: 06/24/2020 - Update Date: 03/10/2022 - Purpose/Change: Support ignoring known errors. -#> - -[CmdletBinding()] -Param( -) - -$json = Get-Content output.json | ConvertFrom-Json - -$errors = $json | Where-Object ErrorCount -ne 0 | Select-Object InputFile, Settings -ExpandProperty Errors | Select-Object InputFile, Settings, Error, Line - -# Exit if no error entries were found -$count = $errors.Count - -if ($count -eq 0) { - Write-Host "All builds passed" - exit 0 -} - -Write-Host "Total errors: $count" - -foreach ($er in $errors) { - - $skipError = $false - - $lineColMatch = $er.Line | Select-String "(^.*)\((\d*),(\d*)\)" | Select-Object -ExpandProperty Matches | Select-Object -ExpandProperty Groups - $errorFile = $er.InputFile - $errorLineNumber = 0 - $errorColNumber = 0 - - if ($lineColMatch.Count -eq 4) { - $errorFile = $lineColMatch[1].Value.Replace("D:\a\$($env:repo)\$($env:repo)\", "").Replace("\", "/") - $errorLineNumber = $lineColMatch[2].Value - $errorColNumber = $lineColMatch[3].Value - } - - # Check if there are any errors that should be skipped because they're known failures - foreach ($expectedError in $er.Settings.expectederrors) { - if (($expectedError.file -eq $errorFile) -and ($expectedError.error -eq $er.error)) { - Write-Host "Skipping error:`n- File: $errorFile`n- Error: $($er.error)" - $skipError = $true - break - } - } - - if ($skipError -eq $false) { - Write-Host "::error file=$errorFile,line=$errorLineNumber,col=$errorColNumber::$($er.Line)" - } - else { - $count -= 1 - } -} - -Write-Host "Errors after skips: $count" - -if ($count -eq 0) { - exit 0 -} - -exit 1 diff --git a/.github/workflows/build-validation.yml b/.github/workflows/snippets5000.yml similarity index 62% rename from .github/workflows/build-validation.yml rename to .github/workflows/snippets5000.yml index f23fa74fc3f..1760342e85e 100644 --- a/.github/workflows/build-validation.yml +++ b/.github/workflows/snippets5000.yml @@ -12,17 +12,17 @@ on: reason: description: 'The reason for running the workflow' required: true - default: 'Force a snippets build' + default: 'Manual run' env: - DOTNET_INSTALLER_CHANNEL: '7.0' + DOTNET_INSTALLER_CHANNEL: '8.0' DOTNET_DO_INSTALL: 'true' # True to install preview versions, False to use the pre-installed (released) SDK EnableNuGetPackageRestore: 'True' repo: 'samples' # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "build-samples" + # This workflow contains a single job called "snippets-build" snippets-build: # The type of runner that the job will run on runs-on: windows-2022 @@ -32,7 +32,7 @@ jobs: # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@a81bbbf8298c0fa03ea29cdc473d45769f953675 #@v2 + - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 #@v3.1.0 # Get the latest preview SDK (or sdk not installed by the runner) - name: Setup .NET SDK @@ -41,34 +41,28 @@ jobs: echo "Downloading dotnet-install.ps1" Invoke-WebRequest https://raw.githubusercontent.com/dotnet/install-scripts/master/src/dotnet-install.ps1 -OutFile dotnet-install.ps1 echo "Installing dotnet version ${{ env.DOTNET_INSTALLER_CHANNEL }}" - .\dotnet-install.ps1 -InstallDir "c:\program files\dotnet" -Channel "${{ env.DOTNET_INSTALLER_CHANNEL }}" + .\dotnet-install.ps1 -InstallDir "c:\program files\dotnet" -Channel "${{ env.DOTNET_INSTALLER_CHANNEL }}" -Quality preview # Print dotnet info - name: Display .NET info run: | dotnet --info - # Install locate projs global tool - - name: Install LocateProjects tool + # Clone docs tools repo + - name: Clone docs-tools repository run: | - dotnet tool install --global --add-source ./.github/workflows/dependencies/ DotnetDocsTools.LocateProjects - - # Run locate projs tool - - name: Locate projects for PR + git clone https://github.com/dotnet/docs-tools + + # Run snippets 5000 + - name: Run snippets 5000 for PR env: GitHubKey: ${{ secrets.GITHUB_TOKEN }} - LocateExts: ".cs;.vb;.fs;.cpp;.h;.xaml;.razor;.cshtml;.vbhtml;.csproj;.fsproj;.vbproj;.vcxproj;.sln" run: | - ./.github/workflows/dependencies/Get-MSBuildResults.ps1 "${{ github.workspace }}" -PullRequest ${{ github.event.number }} -RepoOwner ${{ github.repository_owner }} -RepoName ${{ github.event.repository.name }} - + dotnet run --project docs-tools\snippets5000\Snippets5000\Snippets5000.csproj -- --sourcepath "${{ github.workspace }}" --pullrequest ${{ github.event.number }} --owner ${{ github.repository_owner }} --repo ${{ github.event.repository.name }} + # Update build output json file - name: Upload build results - uses: actions/upload-artifact@3446296876d12d4e3a0f3145a3c87e67bf0a16b5 #@v1 + uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce #@v3.1.2 with: name: build path: ./output.json - - # Return status based on json file - - name: Report status - run: | - ./.github/workflows/dependencies/Out-GithubActionStatus.ps1