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

Update appveyor.yml #373

Merged
merged 6 commits into from
Nov 13, 2024
Merged
Changes from 4 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
187 changes: 102 additions & 85 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 2.3.{build}
version: 2.4.{build}
skip_tags: true
image: Visual Studio 2022
configuration: Release
Expand All @@ -19,8 +19,8 @@ dotnet_csproj:
informational_version: '{version}'

init:
- SET JAVA_HOME=C:\Program Files\Java\jdk19
- SET PATH=%JAVA_HOME%\bin;%PATH%
- SET JAVA_HOME=C:\Program Files\Java\jdk19
- SET PATH=%JAVA_HOME%\bin;%PATH%

install:
# If a newer build is queued for the same PR, cancel this one.
Expand All @@ -34,91 +34,108 @@ install:
throw "There are newer queued builds for this pull request, failing early." }

before_build:
- ps: $env:SOLUTION_NAME = $([io.path]::GetFileNameWithoutExtension($(Get-ChildItem -Path .\* -Include *.sln)))
- ps: $env:SONAR_PROJECT = "$env:APPVEYOR_REPO_NAME" -replace "/","_"
- ps: $env:SONAR_ORGANIZATION = "$env:APPVEYOR_REPO_NAME" -replace "/.*$",""
- ps: $env:LOCAL_PR = 0
- ps: if(-Not $env:APPVEYOR_PULL_REQUEST_NUMBER) { $env:LOCAL_PR = 1 }
- ps: if($env:APPVEYOR_PULL_REQUEST_HEAD_REPO_NAME -Eq $env:APPVEYOR_REPO_NAME) { $env:LOCAL_PR = 1 }
- cmd: nuget restore
- cmd: choco install opencover.portable
- cmd: choco install codecov
- cmd: curl -L https://github.com/codacy/codacy-coverage-reporter/releases/latest/download/codacy-coverage-reporter-assembly.jar > ./codacy-test-reporter.jar
- cmd: curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-windows-amd64 > codeclimate-test-reporter.exe
- cmd: dotnet tool install --global dotnet-sonarscanner

build:
publish_nuget: true
include_nuget_references: true
parallel: true
verbosity: normal
- ps: $env:SOLUTION_NAME = $([io.path]::GetFileNameWithoutExtension($(Get-ChildItem -Path .\* -Include *.sln)))
- ps: $env:SONAR_PROJECT = "$env:APPVEYOR_REPO_NAME" -replace "/","_"
- ps: $env:SONAR_ORGANIZATION = "$env:APPVEYOR_REPO_NAME" -replace "/.*$",""
- ps: $env:LOCAL_PR = 0
- ps: if(-Not $env:APPVEYOR_PULL_REQUEST_NUMBER) { $env:LOCAL_PR = 1 }
- ps: if($env:APPVEYOR_PULL_REQUEST_HEAD_REPO_NAME -Eq $env:APPVEYOR_REPO_NAME) { $env:LOCAL_PR = 1 }
- cmd: nuget restore
- cmd: choco install opencover.portable
- cmd: choco install codecov
- cmd: curl -L https://github.com/codacy/codacy-coverage-reporter/releases/latest/download/codacy-coverage-reporter-assembly.jar > ./codacy-test-reporter.jar
- cmd: curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-windows-amd64 > codeclimate-test-reporter.exe
Comment on lines +44 to +46
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Enhance security and reliability of tool installation

  1. Specify versions for Chocolatey packages to ensure reproducible builds
  2. Verify downloaded files' integrity using checksums
-  - cmd: choco install opencover.portable
-  - cmd: choco install codecov
-  - cmd: curl -L https://github.com/codacy/codacy-coverage-reporter/releases/latest/download/codacy-coverage-reporter-assembly.jar > ./codacy-test-reporter.jar
+  - cmd: choco install opencover.portable --version=4.7.1922
+  - cmd: choco install codecov --version=1.13.0
+  - ps: |
+      $codacyUrl = "https://github.com/codacy/codacy-coverage-reporter/releases/latest/download/codacy-coverage-reporter-assembly.jar"
+      $expectedHash = "SHA256_HASH_HERE" # Replace with actual hash
+      Invoke-WebRequest -Uri $codacyUrl -OutFile "./codacy-test-reporter.jar"
+      $actualHash = (Get-FileHash -Path "./codacy-test-reporter.jar" -Algorithm SHA256).Hash
+      if ($actualHash -ne $expectedHash) {
+          throw "Codacy reporter JAR checksum verification failed"
+      }

Committable suggestion skipped: line range outside the PR's diff.

- cmd: dotnet tool install --global dotnet-sonarscanner

build: off

build_script:
- ps: $Params = "/k:`"$env:SONAR_PROJECT`"", "/o:`"$env:SONAR_ORGANIZATION`"", "/v:`"$env:APPVEYOR_BUILD_NUMBER`""
- ps: $Params += "/d:sonar.host.url=`"https://sonarcloud.io`""
- ps: if($env:LOCAL_PR -Eq 1) { $Params += "/d:sonar.token=`"$env:SONAR_TOKEN`"" }
- ps: $Params += "/d:sonar.exclusions=`"**/bin/**/*,**/obj/**/*`"", "/d:sonar.coverage.exclusions=`"**/$env:SOLUTION_NAME.Tests/**,**/*Tests.cs`""
- ps: $Params += "/d:sonar.cs.opencover.reportsPaths=`"Tests\$env:SOLUTION_NAME.Tests\coverage.opencover.xml`""
- ps: if(-Not $env:APPVEYOR_PULL_REQUEST_NUMBER) { $Params += "/d:sonar.branch.name=`"$env:APPVEYOR_REPO_BRANCH`"" }
- ps: if($env:APPVEYOR_PULL_REQUEST_NUMBER) { $Params += "/d:sonar.pullrequest.key=$env:APPVEYOR_PULL_REQUEST_NUMBER", "/d:sonar.pullrequest.branch=`"$env:APPVEYOR_REPO_BRANCH`"" }
- ps: Start-process "dotnet" "sonarscanner begin $($Params -join ' ')"
- codeclimate-test-reporter before-build
- dotnet build %SOLUTION_NAME%.sln
- ps: $TEST_PROJECTS = (Get-ChildItem -Path .\Tests\**\ -Recurse -Include *.csproj).Fullname
- ps: |
foreach($testProject in $TEST_PROJECTS)
{
dotnet test $testProject /p:CollectCoverage=true "/p:CoverletOutputFormat=\`"cobertura,opencover,lcov\`""
}
- if %LOCAL_PR% EQU 1 codecov -f "Tests\%SOLUTION_NAME%.Tests\coverage.opencover.xml"
- if %LOCAL_PR% EQU 1 codeclimate-test-reporter format-coverage -t lcov -o "Tests\%SOLUTION_NAME%.Tests\code-climate.json" "Tests\%SOLUTION_NAME%.Tests\coverage.info"
- if %LOCAL_PR% EQU 1 codeclimate-test-reporter upload-coverage -i "Tests\%SOLUTION_NAME%.Tests\code-climate.json" -r %CODECLIMATE_TOKEN%
- if %LOCAL_PR% EQU 1 java -jar ./codacy-test-reporter.jar report -l CSharp -t %CODACY_PROJECT_TOKEN% -r "Tests\%SOLUTION_NAME%.Tests\coverage.opencover.xml"
- if %LOCAL_PR% EQU 1 dotnet sonarscanner end /d:sonar.token="%SONAR_TOKEN%"
- ps: $Params = "/k:`"$env:SONAR_PROJECT`"", "/o:`"$env:SONAR_ORGANIZATION`"", "/v:`"$env:APPVEYOR_BUILD_NUMBER`""
- ps: $Params += "/d:sonar.host.url=`"https://sonarcloud.io`" /d:sonar.scanner.scanAll=false"
- ps: if($env:LOCAL_PR -Eq 1) { $Params += "/d:sonar.token=`"$env:SONAR_TOKEN`"" }
- ps: $Params += "/d:sonar.exclusions=`"**/bin/**/*,**/obj/**/*`"", "/d:sonar.coverage.exclusions=`"**/$env:SOLUTION_NAME.Tests/**,**/*Tests.cs`""
- ps: $Params += "/d:sonar.cs.opencover.reportsPaths=`"Tests\$env:SOLUTION_NAME.Tests\coverage.net8.0.opencover.xml`""
- ps: if(-Not $env:APPVEYOR_PULL_REQUEST_NUMBER) { $Params += "/d:sonar.branch.name=`"$env:APPVEYOR_REPO_BRANCH`"" }
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Avoid hardcoding .NET version in coverage path

The coverage path is hardcoded to net8.0. Consider making it dynamic to support multiple .NET versions.

-/d:sonar.cs.opencover.reportsPaths=`"Tests\$env:SOLUTION_NAME.Tests\coverage.net8.0.opencover.xml`""
+/d:sonar.cs.opencover.reportsPaths=`"Tests\$env:SOLUTION_NAME.Tests\coverage.*.opencover.xml`""
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- ps: $Params += "/d:sonar.cs.opencover.reportsPaths=`"Tests\$env:SOLUTION_NAME.Tests\coverage.net8.0.opencover.xml`""
- ps: $Params += "/d:sonar.cs.opencover.reportsPaths=`"Tests\$env:SOLUTION_NAME.Tests\coverage.*.opencover.xml`""

- ps: if($env:APPVEYOR_PULL_REQUEST_NUMBER) { $Params += "/d:sonar.pullrequest.key=$env:APPVEYOR_PULL_REQUEST_NUMBER", "/d:sonar.pullrequest.branch=`"$env:APPVEYOR_REPO_BRANCH`"" }
- ps: Start-process "dotnet" "sonarscanner begin $($Params -join ' ')"
- codeclimate-test-reporter before-build
- dotnet build --verbosity minimal %SOLUTION_NAME%.sln
- ps: $TEST_PROJECTS = (Get-ChildItem -Path .\Tests\**\ -Recurse -Include *.csproj).Fullname
- ps: |
foreach($testProject in $TEST_PROJECTS)
{
dotnet test $testProject --no-build --verbosity minimal /p:CollectCoverage=true "/p:CoverletOutputFormat=\`"cobertura,opencover,lcov\`"" --logger:"junit;LogFilePath=test-results.xml"
$path = Split-Path $testProject
$wc = New-Object 'System.Net.WebClient'
$wc.UploadFile("https://ci.appveyor.com/api/testresults/xunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path $path/test-results.xml))
}
- if %LOCAL_PR% EQU 1 codecov -f "Tests\%SOLUTION_NAME%.Tests\coverage.net8.0.opencover.xml"
- if %LOCAL_PR% EQU 1 codeclimate-test-reporter format-coverage -t lcov -o "Tests\%SOLUTION_NAME%.Tests\code-climate.json" "Tests\%SOLUTION_NAME%.Tests\coverage.net8.0.info"
- if %LOCAL_PR% EQU 1 codeclimate-test-reporter upload-coverage -i "Tests\%SOLUTION_NAME%.Tests\code-climate.json" -r %CODECLIMATE_TOKEN%
- if %LOCAL_PR% EQU 1 java -jar ./codacy-test-reporter.jar report -l CSharp -t %CODACY_PROJECT_TOKEN% -r "Tests\%SOLUTION_NAME%.Tests\coverage.net8.0.opencover.xml"
- if %LOCAL_PR% EQU 1 dotnet sonarscanner end /d:sonar.token="%SONAR_TOKEN%"

after_build:
- xcopy Src\%SOLUTION_NAME%\bin\Release\netstandard2.0\*.* Build\.netstandard2.0\Core\
- xcopy Src\%SOLUTION_NAME%\bin\Release\netstandard2.1\*.* Build\.netstandard2.1\Core\

- xcopy Src\%SOLUTION_NAME%.Health\bin\Release\netstandard2.0\*.* Build\.netstandard2.0\Health\
- xcopy Src\%SOLUTION_NAME%.Health\bin\Release\netstandard2.1\*.* Build\.netstandard2.1\Health\

- copy Src\%SOLUTION_NAME%\bin\Release\%SOLUTION_NAME%.%APPVEYOR_BUILD_VERSION%.nupkg %SOLUTION_NAME%.%APPVEYOR_BUILD_VERSION%.nupkg
- copy Src\%SOLUTION_NAME%.Health\bin\Release\%SOLUTION_NAME%.Health.%APPVEYOR_BUILD_VERSION%.nupkg %SOLUTION_NAME%.Health.%APPVEYOR_BUILD_VERSION%.nupkg

- rd /s /q %CD%\Src\%SOLUTION_NAME%\bin\Release\

- xcopy Tests\%SOLUTION_NAME%.Tests\*.xml Coverage\
- xcopy Tests\%SOLUTION_NAME%.Tests\*.json Coverage\
- xcopy Tests\%SOLUTION_NAME%.Tests\*.info Coverage\

- 7z a -tzip -mx9 "%SOLUTION_NAME%.%APPVEYOR_BUILD_VERSION%.zip" Build
- 7z a -tzip -mx9 "%SOLUTION_NAME%.%APPVEYOR_BUILD_VERSION%.Coverage.zip" Coverage

artifacts:
- path: $(SOLUTION_NAME).%APPVEYOR_BUILD_VERSION%.zip
name: ZipFile

- path: $(SOLUTION_NAME).%APPVEYOR_BUILD_VERSION%.nupkg
name: PackageMain

- path: $(SOLUTION_NAME).Health.%APPVEYOR_BUILD_VERSION%.nupkg
name: PackageHealth

- path: $(SOLUTION_NAME).%APPVEYOR_BUILD_VERSION%.Coverage.zip
name: Coverage
- echo refs > exclusions.txt
- echo "Generating binaries artifacts"
- ps: $VERSIONS = ("netstandard2.0", "netstandard2.1", "net6.0", "net8.0")
- ps: $PROJECTS = ("Health")
- ps: |
foreach($version in $VERSIONS)
{
xcopy Src\$env:SOLUTION_NAME\bin\Release\$version\*.* Build\Core\$version\ /s /f /e /r /k /y /EXCLUDE:exclusions.txt
foreach($project in $PROJECTS)
{
xcopy Src\$env:SOLUTION_NAME.$project\bin\Release\$version\*.* Build\$project\$version\ /s /f /e /r /k /y /EXCLUDE:exclusions.txt
}
}
Comment on lines +86 to +90
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error handling for file operations

File operations (xcopy, 7z) lack error handling. Consider adding try-catch blocks and validation:

+  - ps: function Copy-ProjectFiles {
+      param($source, $target)
+      if (-not (Test-Path $source)) {
+          Write-Warning "Source path not found: $source"
+          return $false
+      }
+      try {
+          xcopy $source $target /s /f /e /r /k /y /EXCLUDE:exclusions.txt
+          return $true
+      } catch {
+          Write-Error "Failed to copy files from $source to $target: $_"
+          return $false
+      }
+  }
   - ps: |
       foreach($version in $VERSIONS)
       {
-          xcopy Src\$env:SOLUTION_NAME\bin\Release\$version\*.* Build\Core\$version\ /s /f /e /r /k /y /EXCLUDE:exclusions.txt
+          $success = Copy-ProjectFiles "Src\$env:SOLUTION_NAME\bin\Release\$version\*.*" "Build\Core\$version\"
+          if (-not $success) { continue }
           foreach($project in $PROJECTS)
           {
-              xcopy Src\$env:SOLUTION_NAME.$project\bin\Release\$version\*.* Build\$project\$version\ /s /f /e /r /k /y /EXCLUDE:exclusions.txt
+              Copy-ProjectFiles "Src\$env:SOLUTION_NAME.$project\bin\Release\$version\*.*" "Build\$project\$version\"
           }
       }

Also applies to: 117-122


- echo "Generating nupkg and snupkg artifacts"
- copy Src\%SOLUTION_NAME%\bin\Release\%SOLUTION_NAME%.%APPVEYOR_BUILD_VERSION%.nupkg %SOLUTION_NAME%.%APPVEYOR_BUILD_VERSION%.nupkg
- copy Src\%SOLUTION_NAME%\bin\Release\%SOLUTION_NAME%.%APPVEYOR_BUILD_VERSION%.snupkg %SOLUTION_NAME%.%APPVEYOR_BUILD_VERSION%.snupkg
- ps: |
foreach($project in $PROJECTS)
{
copy Src\$env:SOLUTION_NAME.$project\bin\Release\$env:SOLUTION_NAME.$project.$env:APPVEYOR_BUILD_VERSION.nupkg $env:SOLUTION_NAME.$project.$env:APPVEYOR_BUILD_VERSION.nupkg
copy Src\$env:SOLUTION_NAME.$project\bin\Release\$env:SOLUTION_NAME.$project.$env:APPVEYOR_BUILD_VERSION.snupkg $env:SOLUTION_NAME.$project.$env:APPVEYOR_BUILD_VERSION.snupkg
}
- ps: Get-ChildItem .\*.nupkg | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }
- ps: Get-ChildItem .\*.snupkg | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }

- echo "Generating coverage artifact"
- rd /s /q Src\%SOLUTION_NAME%\bin\Release\
- xcopy Tests\%SOLUTION_NAME%.Tests\*.xml Coverage\
- xcopy Tests\%SOLUTION_NAME%.Tests\*.json Coverage\
- xcopy Tests\%SOLUTION_NAME%.Tests\*.info Coverage\
- 7z a -tzip -mx9 "%SOLUTION_NAME%.%APPVEYOR_BUILD_VERSION%.Coverage.zip" Coverage
- appveyor PushArtifact "%SOLUTION_NAME%.%APPVEYOR_BUILD_VERSION%.Coverage.zip"

- echo "Generating compressed artifacts files"
- ps: |
foreach($version in $VERSIONS)
{
7z a -tzip -mx9 "$env:SOLUTION_NAME.Core.$version.$env:APPVEYOR_BUILD_VERSION:.zip" Build\Core\$version\
Push-AppveyorArtifact "$env:SOLUTION_NAME.Core.$version.$env:APPVEYOR_BUILD_VERSION:.zip"
foreach($project in $PROJECTS)
{
7z a -tzip -mx9 "$env:SOLUTION_NAME.$project.$version.$env:APPVEYOR_BUILD_VERSION.zip" Build\$project\$version\
Push-AppveyorArtifact "$env:SOLUTION_NAME.$project.$version.$env:APPVEYOR_BUILD_VERSION.zip"
}
}

test: off

deploy:
- provider: NuGet
api_key: $(NUGET_TOKEN)
skip_symbols: false
on:
branch: main

- provider: GitHub
on:
branch: main
tag: v$(appveyor_build_version)
description: 'Release of $(SOLUTION_NAME) - v$(appveyor_build_version)'
auth_token: $(GITHUB_TOKEN)
force_update: true
- provider: NuGet
api_key: $(NUGET_TOKEN)
skip_symbols: false
on:
branch: main

- provider: GitHub
on:
branch: main
tag: v$(appveyor_build_version)
description: "Release of $(SOLUTION_NAME) - v$(appveyor_build_version)"
auth_token: $(GITHUB_TOKEN)
force_update: true
Loading