From 7f1247484d91c0271a0104a8f6485ec263470a36 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sun, 20 Oct 2024 19:01:51 +0700 Subject: [PATCH] Publish projects to individual folders rather than publishing the whole solution to one folder (fixes #974) (#975) * .build/runbuild.ps1: Removed zipPublishedArtifacts and publishedArtifactZipFileName parameters because they are not in use * .build/runbuild.ps1: Changed publish command to put the output into project-specific folders. --output for publish is no longer supported. See: https://learn.microsoft.com/en-us/dotnet/core/compatibility/sdk/7.0/solution-level-output-no-longer-valid * run-tests-on-os.yml: Don't copy the test binaries. We put them in separate directories during publish instead. * azure-pipelines.yml: Removed publish from the PSake run. We will be publishing in the pipeline, instead. * publish-test-binaries.yml: Added dotnet publish command to build the test binaries before uploading as artifacts and to delete them after uploaded to save disk space. * LuceneDocsPlugins.csproj: Don't publish if not on net8.0 * lucene-cli.csproj: Don't publish if not net8.0 or net6.0 * azure-pipelines.yml: Added task to delete nuget artifacts from the build agent after they have been published to the pipeline * azure-pipelines.yml: Cleaned up environment variable usage * .github/workflows: Removed Lucene-Net-Dependency-Conflict-Warning.yml, since we are now publishing projects to individual directories. See: https://learn.microsoft.com/en-us/dotnet/core/compatibility/sdk/7.0/solution-level-output-no-longer-valid * azure-pipelines.yml: Setup BuildPlatform env variable for current pipeline --- .../azure-templates/publish-test-binaries.yml | 32 +++++++++++- .build/azure-templates/run-tests-on-os.yml | 11 +--- .build/runbuild.ps1 | 22 ++------ ...Lucene-Net-Dependency-Conflict-Warning.yml | 45 ---------------- Directory.Build.targets | 4 ++ azure-pipelines.yml | 52 +++++++++++-------- .../LuceneDocsPlugins.csproj | 1 + src/dotnet/tools/lucene-cli/lucene-cli.csproj | 4 +- 8 files changed, 74 insertions(+), 97 deletions(-) delete mode 100644 .github/workflows/Lucene-Net-Dependency-Conflict-Warning.yml diff --git a/.build/azure-templates/publish-test-binaries.yml b/.build/azure-templates/publish-test-binaries.yml index 436b8c090c..870aca6918 100644 --- a/.build/azure-templates/publish-test-binaries.yml +++ b/.build/azure-templates/publish-test-binaries.yml @@ -1,4 +1,4 @@ -# Licensed to the Apache Software Foundation (ASF) under one +# Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The ASF licenses this file @@ -26,8 +26,33 @@ parameters: framework: '' # The target framework binaryArtifactName: '' # The prefix of the binary artifact to publish $(BinaryArtifactName) testSettingsFilePath: '$(Build.ArtifactStagingDirectory)/lucene.testsettings.json' #The name of the lucene test settings file + solution: '$(Build.SourcesDirectory)/Lucene.Net.sln' + configration: '$(BuildConfiguration)' # The build configuration + platform: '$(BuildPlatform)' # The build platform steps: +- pwsh: | + $solution = "${{ parameters.solution }}" + $configuration = "${{ parameters.configration }}" + $framework = "${{ parameters.framework }}" + $publishDirectory = "${{ parameters.publishDirectory }}" + Write-Host "solution: $solution" + Write-Host "configuration: $configuration" + Write-Host "framework: $framework" + Write-Host "publishDirectory: $publishDirectory" + &dotnet publish "${{ parameters.solution }}" --configuration "${{ parameters.configration }}" --framework: "${{ parameters.framework }}" --no-build --no-restore --verbosity normal /p:TestFrameworks=true /p:Platform="${{ parameters.platform }}" /p:AlternatePublishRootDirectory="${{ parameters.publishDirectory }}" + displayName: 'Publish Projects for ${{ parameters.framework }}' + condition: and(succeeded(), ne(variables['RunTests'], 'false')) + +#- task: DotNetCoreCLI@2 +# displayName: 'Publish Projects for ${{ parameters.framework }}' +# inputs: +# command: custom +# projects: '**/*.sln' +# custom: publish +# arguments: '--configuration "${{ parameters.configuration }}" --framework: "${{ parameters.framework }}" --no-build --no-restore --verbosity normal /p:TestFrameworks=true /p:Platform="${{ parameters.platform }}" /p:AlternatePublishRootDirectory="${{ parameters.publishDirectory }}"' +# condition: and(succeeded(), ne(variables['RunTests'], 'false')) + - pwsh: | Copy-Item -Path "${{ parameters.testSettingsFilePath }}" -Destination "${{ parameters.publishDirectory }}/${{ parameters.framework }}/" -Force displayName: 'Copy lucene.testsettings.json File to: ${{ parameters.publishDirectory }}/${{ parameters.framework }}' @@ -40,3 +65,8 @@ steps: artifact: '${{ parameters.binaryArtifactName }}_${{ parameters.framework }}' publishLocation: 'pipeline' condition: and(succeeded(), ne(variables['RunTests'], 'false')) + +- pwsh: | + Remove-Item -Path "${{ parameters.publishDirectory }}/${{ parameters.framework }}/*" -Recurse -Force + displayName: 'Delete temp publish location: ${{ parameters.publishDirectory }}/${{ parameters.framework }}' + condition: and(succeeded(), ne(variables['RunTests'], 'false')) diff --git a/.build/azure-templates/run-tests-on-os.yml b/.build/azure-templates/run-tests-on-os.yml index a6d771d800..9ebbb55a41 100644 --- a/.build/azure-templates/run-tests-on-os.yml +++ b/.build/azure-templates/run-tests-on-os.yml @@ -205,15 +205,6 @@ steps: if (!(Test-Path "$testResultDirectory")) { New-Item "$testResultDirectory" -ItemType Directory -Force } - # Test binaries are copied to a temp directory so locking behavior of other processes doesn't interfere with this test run - $tempTestDirectory = "$tempDirectory/$framework/$testName" - if (!(Test-Path "$tempTestDirectory")) { - New-Item "$tempTestDirectory" -ItemType Directory -Force - } - $testTarget = "$tempTestDirectory/$($testBinary.Name)" - $sourceDirectory = $testBinary.Directory.FullName - - Copy-Item -Path "$sourceDirectory/*" -Destination "$tempTestDirectory" -Recurse -Force if ($isNightly -ne 'true' -and $isWeekly -ne 'true') { $blameHangTimeout = "--blame-hang-timeout 15minutes" @@ -223,7 +214,7 @@ steps: Write-Host "Running with $blameHangTimeout" - $testExpression = "dotnet test ""$testTarget"" --framework ""$framework"" --blame --no-build --no-restore" + ` + $testExpression = "dotnet test ""$($testBinary.FullName)"" --framework ""$framework"" --blame --no-build --no-restore" + ` " --logger:""console;verbosity=normal"" --logger:""trx;LogFileName=$testResultsFileName""" + ` " --results-directory:""$testResultDirectory""" + ` " --blame-hang --blame-hang-dump-type mini $blameHangTimeout" diff --git a/.build/runbuild.ps1 b/.build/runbuild.ps1 index 35f5abe667..4fad5efe5d 100644 --- a/.build/runbuild.ps1 +++ b/.build/runbuild.ps1 @@ -44,8 +44,6 @@ properties { [string]$platform = $(if ($platform) { $platform } else { if ($env:BuildPlatform) { $env:BuildPlatform } else { "Any CPU" } }) #NOTE: Pass in as a parameter (not a property) or environment variable to override [bool]$backupFiles = $true [bool]$prepareForBuild = $true - [bool]$zipPublishedArtifacts = $false - [string]$publishedArtifactZipFileName = "artifact.zip" [int]$maximumParallelJobs = 8 @@ -195,12 +193,7 @@ task Publish -depends Compile -description "This task uses dotnet publish to pac try { $frameworksToTest = Get-FrameworksToTest - - if ($zipPublishedArtifacts) { - $outDirectory = New-TemporaryDirectory - } else { - $outDirectory = $publishDirectory - } + $outDirectory = $publishDirectory foreach ($framework in $frameworksToTest) { @@ -211,15 +204,14 @@ task Publish -depends Compile -description "This task uses dotnet publish to pac } $logPath = "$outDirectory/$framework" - $outputPath = "$logPath" # Do this first so there is no conflict - Ensure-Directory-Exists $outputPath + Ensure-Directory-Exists $logPath Write-Host "Configuration: $configuration" - $expression = "dotnet publish `"$solutionFile`" --configuration `"$configuration`" --framework `"$framework`" --output `"$outputPath`"" - $expression = "$expression --no-build --no-restore --verbosity Normal /p:TestFrameworks=true /p:Platform=`"$platform`"" + $expression = "dotnet publish `"$solutionFile`" --configuration `"$configuration`" --framework `"$framework`"" + $expression = "$expression --no-build --no-restore --verbosity Normal /p:TestFrameworks=true /p:Platform=`"$platform`" /p:AlternatePublishRootDirectory=`"$outDirectory`"" $expression = "$expression > `"$logPath/dotnet-publish.log`" 2> `"$logPath/dotnet-publish-error.log`"" $scriptBlock = { @@ -246,12 +238,6 @@ task Publish -depends Compile -description "This task uses dotnet publish to pac # Getting the information back from the jobs (time consuming) #Get-Job | Receive-Job - if ($zipPublishedArtifacts) { - Ensure-Directory-Exists $publishDirectory - Add-Type -assembly "System.IO.Compression.Filesystem" - [System.IO.Compression.ZipFile]::CreateFromDirectory($outDirectory, "$publishDirectory/$publishedArtifactZipFileName") - } - $success = $true } finally { #if ($success -ne $true) { diff --git a/.github/workflows/Lucene-Net-Dependency-Conflict-Warning.yml b/.github/workflows/Lucene-Net-Dependency-Conflict-Warning.yml deleted file mode 100644 index d8da6c9ddd..0000000000 --- a/.github/workflows/Lucene-Net-Dependency-Conflict-Warning.yml +++ /dev/null @@ -1,45 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -# References: -# https://stackoverflow.com/a/58704739 -# https://docs.github.com/en/actions/security-guides/automatic-token-authentication - -name: 'Lucene.Net Dependency Conflict Warning' - -on: - pull_request: - paths: - - '.build/dependencies.props' - - 'src/**/*.csproj' - -jobs: - - comment: - runs-on: ubuntu-latest - steps: - - name: Add warning comment to PR - env: - URL: ${{ github.event.pull_request.comments_url }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - curl \ - -X POST \ - $URL \ - -H "Content-Type: application/json" \ - -H "Authorization: token $GITHUB_TOKEN" \ - --data '{ "body": ":warning: **IMPORTANT:** This PR may contain changes to dependency versions. The GitHub Actions test runner is not set up to detect dependency version conflicts between projects. To ensure the changes do not cause dependency conflicts, [run the tests for these changes in Azure DevOps](https://github.com/apache/lucenenet#azure-devops) before accepting this pull request. :warning:" }' diff --git a/Directory.Build.targets b/Directory.Build.targets index 966808152a..35988f656f 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -22,6 +22,10 @@ + + $(AlternatePublishRootDirectory)/$(TargetFramework)/$(MSBuildProjectName)/ + + diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 2bd5a72676..9c8282fda1 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -101,9 +101,6 @@ stages: pool: vmImage: 'windows-2019' - variables: - PublishTempDirectory: '$(Build.ArtifactStagingDirectory)/publish' - steps: - checkout: self # self represents the repo where the initial Pipelines YAML file was found @@ -112,6 +109,8 @@ stages: - pwsh: | $configuration = if ($env:BUILDCONFIGURATION) { $env:BUILDCONFIGURATION } else { "Release" } Write-Host "##vso[task.setvariable variable=BuildConfiguration;]$configuration" + $platform = if ($env:BUILDPLATFORM) { $env:BUILDPLATFORM } else { "Any CPU" } + Write-Host "##vso[task.setvariable variable=BuildPlatform;]$platform" $isRelease = if ($env:ISRELEASE -eq 'true') { 'true' } else { 'false' } Write-Host "##vso[task.setvariable variable=IsRelease;]$isRelease" $isNightly = if ($env:ISNIGHTLY -eq 'true') { 'true' } else { 'false' } @@ -132,16 +131,12 @@ stages: $parameters = @{} $properties = @{ backupFiles='false'; - publishDirectory='$(PublishTempDirectory)'; nugetPackageDirectory='$(NuGetArtifactDirectory)' } [string[]]$tasks = @($primaryCommand) - if ($env:RunTests -ne 'false') { - [string[]]$tasks = $primaryCommand,'Publish' - } Invoke-Psake $(BuildDirectory)/runbuild.ps1 -Task $tasks -properties $properties -parameters $parameters exit !($psake.build_success) - displayName: 'PSake Build, Pack, and Publish' + displayName: 'PSake Build and Pack' #- template: '.build/azure-templates/show-all-environment-variables.yml' # Uncomment for debugging @@ -213,14 +208,6 @@ stages: TargetFolder: '$(Build.ArtifactStagingDirectory)/$(DebugArtifactName)' condition: and(succeeded(), ne(variables['ArtifactFeedID'], '')) - - task: PublishPipelineArtifact@1 - displayName: 'Publish Artifact: $(NuGetArtifactName)' - inputs: - targetPath: '$(Build.ArtifactStagingDirectory)/$(NuGetArtifactName)' - artifact: '$(NuGetArtifactName)' - publishLocation: 'pipeline' - condition: and(succeeded(), ne(variables['RunPack'], 'false')) - - task: PublishPipelineArtifact@1 displayName: 'Publish Artifact: $(DebugArtifactName)' inputs: @@ -229,40 +216,63 @@ stages: publishLocation: 'pipeline' condition: and(succeeded(), ne(variables['ArtifactFeedID'], '')) + - task: PublishPipelineArtifact@1 + displayName: 'Publish Artifact: $(NuGetArtifactName)' + inputs: + targetPath: '$(NuGetArtifactDirectory)' + artifact: '$(NuGetArtifactName)' + publishLocation: 'pipeline' + condition: and(succeeded(), ne(variables['RunPack'], 'false')) + + - pwsh: | + Remove-Item -Path "$(NuGetArtifactDirectory)/*" -Recurse -Force + displayName: 'Delete temp publish location: $(NuGetArtifactDirectory)' + condition: and(succeeded(), ne(variables['RunPack'], 'false')) + - template: '.build/azure-templates/publish-test-binaries.yml' parameters: - publishDirectory: $(PublishTempDirectory) + publishDirectory: $(PublishDirectory) framework: 'net8.0' binaryArtifactName: '$(BinaryArtifactName)' testSettingsFilePath: '$(Build.ArtifactStagingDirectory)/$(TestSettingsFileName)' + configration: '$(BuildConfiguration)' + platform: '$(BuildPlatform)' - template: '.build/azure-templates/publish-test-binaries.yml' parameters: - publishDirectory: $(PublishTempDirectory) + publishDirectory: $(PublishDirectory) framework: 'net6.0' binaryArtifactName: '$(BinaryArtifactName)' testSettingsFilePath: '$(Build.ArtifactStagingDirectory)/$(TestSettingsFileName)' + configration: '$(BuildConfiguration)' + platform: '$(BuildPlatform)' - template: '.build/azure-templates/publish-test-binaries.yml' parameters: - publishDirectory: $(PublishTempDirectory) + publishDirectory: $(PublishDirectory) framework: 'net5.0' binaryArtifactName: '$(BinaryArtifactName)' testSettingsFilePath: '$(Build.ArtifactStagingDirectory)/$(TestSettingsFileName)' + configration: '$(BuildConfiguration)' + platform: '$(BuildPlatform)' - template: '.build/azure-templates/publish-test-binaries.yml' parameters: - publishDirectory: $(PublishTempDirectory) + publishDirectory: $(PublishDirectory) framework: 'net472' binaryArtifactName: '$(BinaryArtifactName)' testSettingsFilePath: '$(Build.ArtifactStagingDirectory)/$(TestSettingsFileName)' + configration: '$(BuildConfiguration)' + platform: '$(BuildPlatform)' - template: '.build/azure-templates/publish-test-binaries.yml' parameters: - publishDirectory: $(PublishTempDirectory) + publishDirectory: $(PublishDirectory) framework: 'net48' binaryArtifactName: '$(BinaryArtifactName)' testSettingsFilePath: '$(Build.ArtifactStagingDirectory)/$(TestSettingsFileName)' + configration: '$(BuildConfiguration)' + platform: '$(BuildPlatform)' - job: Docs condition: and(succeeded(), eq(variables['GenerateDocs'], 'true')) diff --git a/src/docs/LuceneDocsPlugins/LuceneDocsPlugins.csproj b/src/docs/LuceneDocsPlugins/LuceneDocsPlugins.csproj index 5e7db5f2f6..75e2664d5a 100644 --- a/src/docs/LuceneDocsPlugins/LuceneDocsPlugins.csproj +++ b/src/docs/LuceneDocsPlugins/LuceneDocsPlugins.csproj @@ -38,6 +38,7 @@ under the License. true + false diff --git a/src/dotnet/tools/lucene-cli/lucene-cli.csproj b/src/dotnet/tools/lucene-cli/lucene-cli.csproj index 21b398da86..73a1446b07 100644 --- a/src/dotnet/tools/lucene-cli/lucene-cli.csproj +++ b/src/dotnet/tools/lucene-cli/lucene-cli.csproj @@ -27,8 +27,8 @@ net8.0;net6.0 Major - true - false + false + true true lucene