Skip to content
Merged
88 changes: 54 additions & 34 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,80 @@ on:
branches:
- master
- develop
- dev

pull_request:
branches:
- master
- develop
- dev
types: [opened, synchronize, reopened]

jobs:
sonarcloud_branch:
name: SonarCloud analysis
runs-on: windows-latest

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Java
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'adopt'
java-version: '17'
distribution: 'temurin'

- name: Setup .NET
uses: actions/setup-dotnet@v1
- name: Setup .NET 10
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.x
dotnet-version: '10.0.100'

- name: Install SonarScanner
run: dotnet tool update --global dotnet-sonarscanner

- name: Restore Dependencies
run: dotnet restore ./Streetcode/Streetcode.sln

- name: Install xmldocmd
run: dotnet tool install xmldocmd -g

- name: Build
run: dotnet build ./Streetcode/Streetcode.sln --configuration Release --no-restore
- name: SonarScanner Begin
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: >
dotnet sonarscanner begin
/k:"ita-social-projects_StreetCode"
/o:"ita-social-projects"
/d:sonar.token="$env:SONAR_TOKEN"
/d:sonar.host.url="https://sonarcloud.io"
/d:sonar.cs.opencover.reportsPaths="${{ github.workspace }}\coverage\coverage.opencover.xml"

- name: Install coverlet.console
run: dotnet tool install -g coverlet.console

- name: Test and Code Coverage
run: |
dotnet test ./Streetcode/Streetcode.XUnitTest/Streetcode.XUnitTest.csproj --configuration Release --no-build --verbosity normal --collect:"XPlat Code Coverage" --results-directory ./coverage /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput=./coverage/coverage.xml

- name: Install SonarScanner
run: dotnet tool install --global dotnet-sonarscanner
- name: Build Solution
run: >
dotnet build ./Streetcode/Streetcode.sln
--configuration Release
--no-restore
/p:TreatWarningsAsErrors=false

- name: Set SonarCloud Token
run: echo "SONAR_TOKEN=${{ secrets.SONAR_TOKEN }}" >> $GITHUB_ENV
- name: Run Tests with Coverage
run: >
dotnet test ./Streetcode/Streetcode.XUnitTest/Streetcode.XUnitTest.csproj
--configuration Release
--no-build
/p:CollectCoverage=true
/p:CoverletOutputFormat=opencover
/p:CoverletOutput="${{ github.workspace }}\coverage\coverage.opencover.xml"

- name: SonarScanner Analysis
id: sonar
run: |
dotnet sonarscanner begin /k:"ita-social-projects_StreetCode" /o:"ita-social-projects" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportPaths="./coverage/coverage.xml"
dotnet build ./Streetcode/Streetcode.sln --configuration Release
dotnet sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"
- name: SonarScanner End
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: >
dotnet sonarscanner end
/d:sonar.token="$env:SONAR_TOKEN"

- name: Publish Code Coverage Report
- name: Upload Coverage Artifact
if: always()
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: Code Coverage Report
path: |
./coverage/coverage.xml
name: coverage-report
path: coverage/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,4 @@ Reach out to us at one of the following places!

## License
- **[MIT license](http://opensource.org/licenses/mit-license.php)**
- Copyright 2022 © <a href="https://softserve.academy/" target="_blank"> SoftServe IT Academy</a>.
- Copyright 2022 © <a href="https://softserve.academy/" target="_blank"> SoftServe IT Academy</a>.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Loading