diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..45dda10e --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,116 @@ +name: Build, Test and Analyze + +on: + push: + branches: + - main + pull_request: + types: [opened, synchronize, reopened] + workflow_dispatch: + +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + name: Build, Test and Analyze + runs-on: ubuntu-latest + + services: + couchdb: + image: couchdb:3.3.3 + env: + COUCHDB_USER: Admin + COUCHDB_PASSWORD: myP@ssw0rd + ports: + - 5984:5984 + options: >- + --health-cmd "curl -sf http://localhost:5984/_up" + --health-interval 10s + --health-timeout 5s + --health-retries 10 + + steps: + - name: ๐Ÿ“ฅ Checkout repository + uses: actions/checkout@v6 + with: + ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: 0 + + - name: โ˜• Setup Java runtime + uses: actions/setup-java@v5 + with: + java-version: 17 + distribution: temurin + + - name: ๐Ÿงฐ Setup .NET SDK + uses: actions/setup-dotnet@v5 + with: + dotnet-version: '10.0.x' + + - name: ๐Ÿ”ง Install SonarCloud scanner + run: dotnet tool install --global dotnet-sonarscanner + + - name: ๐Ÿ“ก Install DeepSource scanner + run: curl https://deepsource.io/cli | sh + + - name: ๐Ÿ’พ Cache NuGet packages + uses: actions/cache@v5 + with: + path: ~/.nuget/packages + key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/global.json', '**/packages.lock.json') }} + restore-keys: | + ${{ runner.os }}-nuget- + - name: ๐Ÿ“ฆ Restore dependencies + run: dotnet restore + + - name: ๐Ÿ” Begin SonarCloud analysis + run: | + dotnet sonarscanner begin \ + /k:"guibranco_CrispyWaffle" \ + /o:"guibranco" \ + /d:sonar.token="$SONAR_TOKEN" \ + /d:sonar.host.url="https://sonarcloud.io" \ + /d:sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + + - name: ๐Ÿ—๏ธ Build solution + run: dotnet build --no-restore --configuration Release + + - name: ๐Ÿงช Run tests with coverage + run: | + dotnet test \ + --no-build \ + --configuration Release \ + /p:CollectCoverage=true \ + /p:CoverletOutputFormat=opencover%2ccobertura + + - name: ๐Ÿ“Š End SonarCloud analysis + run: dotnet sonarscanner end /d:sonar.token="$SONAR_TOKEN" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + + - name: โ˜‚๏ธ Upload coverage to Codecov + uses: codecov/codecov-action@v6 + with: + token: ${{ secrets.CODECOV_TOKEN }} + + - name: ๐Ÿ“ˆ Report coverage to DeepSource + if: >- + ( + github.event_name == 'pull_request' && + github.event.pull_request.head.repo.full_name == github.repository + ) || ( + github.event_name == 'workflow_dispatch' + ) + env: + DEEPSOURCE_DSN: ${{ secrets.DEEPSOURCE_DSN }} + run: | + ./bin/deepsource report \ + --analyzer test-coverage \ + --key csharp \ + --value-file ./Tests/CrispyWaffle.Tests/coverage.net9.0.cobertura.xml diff --git a/.github/workflows/deep-source.yml b/.github/workflows/deep-source.yml deleted file mode 100644 index 39292b41..00000000 --- a/.github/workflows/deep-source.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: Deep Source - -on: - push: - branches: - - main - pull_request: - types: [opened, synchronize, reopened] - -jobs: - DeepSource: - name: Deep Source Coverage report - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - with: - ref: ${{ github.event.pull_request.head.sha }} - - - name: Docker compose up - run: docker compose up -d && sleep 10 - - - name: Install DeepSource scanner - run: curl https://deepsource.io/cli | sh - - - name: Setup .NET - uses: actions/setup-dotnet@v5 - with: - dotnet-version: '9.x' - - - name: Build and analyze - env: - DEEPSOURCE_DSN: ${{ secrets.DEEPSOURCE_DSN }} - run: | - dotnet build -c Debug --verbosity minimal - dotnet test -c Debug --verbosity minimal --no-build --no-restore /p:CollectCoverage=true /p:CoverletOutputFormat="cobertura" - ./bin/deepsource report --analyzer test-coverage --key csharp --value-file ./Tests/CrispyWaffle.Tests/coverage.net9.0.cobertura.xml diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml deleted file mode 100644 index c9388825..00000000 --- a/.github/workflows/sonarcloud.yml +++ /dev/null @@ -1,69 +0,0 @@ -name: SonarCloud Analysis - -on: - push: - branches: - - main - pull_request: - types: [opened, synchronize, reopened] - -jobs: - SonarCloudAnalysis: - name: SonarCloud Analysis - runs-on: ubuntu-latest - - steps: - - name: Set up Java - uses: actions/setup-java@v5 - with: - distribution: 'temurin' - java-version: 21 - - - uses: actions/checkout@v6 - with: - fetch-depth: 0 - - - name: Setup .NET - uses: actions/setup-dotnet@v5 - with: - dotnet-version: '9.x' - - - name: Docker compose up - run: docker compose up -d && sleep 10 - - - name: Cache SonarCloud packages - uses: actions/cache@v5 - with: - path: ~/.sonar/cache - key: ${{ runner.os }}-sonar - restore-keys: ${{ runner.os }}-sonar - - - name: Cache SonarCloud scanner - id: cache-sonar-scanner - uses: actions/cache@v5 - with: - path: ~/.sonar/cache - key: ${{ runner.os }}-sonar-scanner - restore-keys: ${{ runner.os }}-sonar-scanner - - - name: Install SonarCloud scanner - if: steps.cache-sonar-scanner.outputs.cache-hit != 'true' - run: dotnet tool update dotnet-sonarscanner --tool-path ~/.sonar/cache/ - - - name: Set SonarCloud variables - shell: bash - run: | - KEY="${{ github.repository_owner }}_${{ github.event.repository.name }}" - ORG="${{ github.repository_owner }}" - echo "KEY=${KEY}" >> "${GITHUB_ENV}" # Keep the variable KEY as it - echo "ORG=${ORG@L}" >> "${GITHUB_ENV}" # Lowercase the ORG variable - - - name: Build and analyze - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: | - ~/.sonar/cache/dotnet-sonarscanner begin /k:"${{ env.KEY }}" /o:"${{ env.ORG }}" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.scanner.scanAll=false /d:sonar.cs.opencover.reportsPaths="Tests/**/coverage.net9.0.opencover.xml" - dotnet build -c Release --verbosity minimal - dotnet test -c Release --verbosity minimal --no-build --no-restore /p:CollectCoverage=true /p:CoverletOutputFormat="opencover" - ~/.sonar/cache/dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 8502228e..00000000 --- a/appveyor.yml +++ /dev/null @@ -1,143 +0,0 @@ -version: 10.0.{build} -skip_tags: true -image: Visual Studio 2022 -configuration: Release - -environment: - CODACY_PROJECT_TOKEN: - secure: +P1Y06uyyjji43oS/FfAYhH3gaK3QIFdsLVwINJHXfdC6uJ+RvX5EYzBE21yqdLM - -dotnet_csproj: - patch: true - file: '**\*.props' - version: "{version}" - package_version: "{version}" - assembly_version: "{version}" - file_version: "{version}" - informational_version: "{version}" - -init: - - SET JAVA_HOME=C:\Program Files\Java\jdk21 - - SET PATH=%JAVA_HOME%\bin;%PATH% - -install: - # If a newer build is queued for the same PR, cancel this one. - # The AppVeyor 'rollout builds' option is supposed to serve the same - # purpose, but it is problematic because it tends to cancel builds pushed - # directly to main/master instead of just PR builds (or the converse). - # credits: JuliaLang developers. - - ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod ` - https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | ` - Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { ` - throw "There are newer queued builds for this pull request, failing early." } - - ps: (new-object net.webclient).DownloadFile('https://couchdb.neighbourhood.ie/downloads/3.3.3-3/win/apache-couchdb-3.3.3-3.msi', 'apache-couchdb-3.3.3.msi') - - ps: msiexec /i .\apache-couchdb-3.3.3.msi /quiet /norestart ADMINUSER=Admin ADMINPASSWORD=myP@ssw0rd - - ps: | - $dotnetInstallScript = 'https://dot.net/v1/dotnet-install.ps1' - Invoke-WebRequest $dotnetInstallScript -OutFile 'dotnet-install.ps1' - & ./dotnet-install.ps1 -Version 9.0.100 -InstallDir "$env:USERPROFILE\.dotnet" - $env:PATH += ";$env:USERPROFILE\.dotnet" - -before_build: - - ps: dotnet --info - - 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: 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`" /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.net9.0.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 ' ')" - - 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.net9.0.opencover.xml" - - if %LOCAL_PR% EQU 1 java -jar ./codacy-test-reporter.jar report -l CSharp -t %CODACY_PROJECT_TOKEN% -r "Tests\%SOLUTION_NAME%.Tests\coverage.net9.0.opencover.xml" - - if %LOCAL_PR% EQU 1 dotnet sonarscanner end /d:sonar.token="%SONAR_TOKEN%" - -after_build: - - echo refs > exclusions.txt - - echo "Generating binaries artifacts" - - ps: $VERSIONS = ("netstandard2.0", "netstandard2.1", "net6.0", "net9.0") - - ps: $PROJECTS = ("Configuration", "ElasticSearch", "Elmah", "EventLog", "I18n.PtBr", "Log4Net", "RabbitMQ", "Redis", "Utils") - - 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 - } - } - - - 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