Merge pull request #40 from lk-code/HC-39 #22
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: .NET Build | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
build-and-publish: | |
runs-on: ubuntu-latest | |
env: | |
VERSION: 3.0.${{ github.run_number }}-beta | |
NUGET_FILE: "**/*hetznercloudapi*.nupkg" | |
steps: | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v1 | |
with: | |
java-version: 1.11 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v2 | |
with: | |
dotnet-version: 8.0.x | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Restore dependencies | |
run: dotnet restore source/ | |
- name: Cache SonarCloud packages | |
uses: actions/cache@v1 | |
with: | |
path: ~\sonar\cache | |
key: ${{ runner.os }}-sonar | |
restore-keys: ${{ runner.os }}-sonar | |
- name: Cache SonarCloud scanner | |
id: cache-sonar-scanner | |
uses: actions/cache@v1 | |
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: pwsh | |
run: | | |
dotnet tool update -g dotnet-sonarscanner | |
dotnet tool update -g dotnet-reportgenerator-globaltool | |
dotnet tool update -g dotnet-coverage | |
- name: Build and analyze | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
shell: pwsh | |
run: | | |
dotnet-sonarscanner begin /k:"lk-code_hetzner-cloud-api-net" /o:"lk-code-github" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml | |
dotnet build --configuration Release --no-restore -p:PackageVersion=${{ env.VERSION }} source/ | |
dotnet-coverage collect "dotnet test" -f xml -o "coverage.xml" | |
reportgenerator "-reports:coverage.xml" "-targetdir:sonarqubecoverage" "-reporttypes:SonarQube" | |
dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" | |
- name: Set Version Git Tag | |
run: | | |
git tag ${{ env.VERSION }} | |
git push origin ${{ env.VERSION }} | |
- name: Upload Build Artifact | |
uses: actions/upload-artifact@v3.1.2 | |
with: | |
name: ${{ env.VERSION }} | |
path: ${{ env.NUGET_FILE }} | |
- name: Publish | |
run: dotnet nuget push ${{ env.NUGET_FILE }} --no-symbols --skip-duplicate --api-key ${{ secrets.NUGET_API_KEY }} --source "nuget.org" |