Skip to content

Commit

Permalink
workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
na1307 committed Dec 25, 2024
1 parent 4ad5f0a commit 8ab8e0a
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 31 deletions.
20 changes: 20 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-sonarscanner": {
"version": "9.0.2",
"commands": [
"dotnet-sonarscanner"
],
"rollForward": false
},
"dotnet-coverage": {
"version": "17.13.1",
"commands": [
"dotnet-coverage"
],
"rollForward": false
}
}
}
52 changes: 21 additions & 31 deletions .github/workflows/SonarCloud.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
name: SonarCloud

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
Expand All @@ -11,49 +15,35 @@ jobs:
env:
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 21
distribution: temurin
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarCloud scanner
id: cache-sonar-scanner
uses: actions/cache@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
path: .\.sonar\scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner
- name: Install SonarCloud scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
shell: powershell
run: |
New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
dotnet-version: 9.0.x
- name: Cache NuGet
uses: actions/cache@v4
with:
path: ${{ github.workspace }}\.nuget\packages
key: ${{ runner.os }}-nuget-${{ hashFiles('Directory.Packages.props') }} #hash of project files
restore-keys: ${{ runner.os }}-nuget-
- name: MSBuild
uses: microsoft/setup-msbuild@v2
with:
msbuild-architecture: x64
path: ${{ github.workspace }}/.nuget/packages
key: ${{ runner.os }}-sonar-nuget-${{ hashFiles('Directory.Packages.props', '.config/dotnet-tools.json') }} #hash of project files
restore-keys: ${{ runner.os }}-sonar-nuget-
- name: Install Tools
shell: powershell
run: dotnet tool restore
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner begin /k:"na1307_EncodingConverter" /o:"na1307" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.scanner.skipJreProvisioning=true
msbuild -r -p:CreateVsixContainer=false -p:DeployExtension=false
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
dotnet sonarscanner begin /k:"na1307_EncodingConverter" /o:"na1307" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml /d:sonar.scanner.skipJreProvisioning=true
dotnet restore
dotnet build --no-restore --no-incremental -p:CreateVsixContainer=false -p:DeployExtension=false
dotnet coverage collect 'dotnet test --no-build --verbosity normal' -f xml -o 'coverage.xml'
dotnet sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
35 changes: 35 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: .NET

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
name: .NET
runs-on: windows-latest
env:
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
- name: Cache NuGet
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('Directory.Packages.props') }} #hash of project files
restore-keys: ${{ runner.os }}-nuget-
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore -p:CreateVsixContainer=false -p:DeployExtension=false
- name: Test
run: dotnet test --no-build --verbosity normal

0 comments on commit 8ab8e0a

Please sign in to comment.