.NET #27
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 | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
workflow_dispatch: | |
inputs: | |
publishToNuget: | |
description: 'Publish to nuget' | |
required: true | |
default: true | |
type: boolean | |
jobs: | |
build: | |
name: "CI : Build, Test and publish" | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- run: echo "REPOSITORY_NAME=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_ENV | |
shell: bash | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v1 | |
with: | |
dotnet-version: | | |
6.0.x | |
7.0.x | |
- name: Restore dependencies | |
run: dotnet restore | |
working-directory: src | |
# Generate package version : | |
- name: Generate package version | |
id: generateVersionStep | |
shell: pwsh | |
run: | | |
$version = .\generateVersion.ps1 -query ${{ secrets.NUGETPACKAGEIDENTIFIER }} | |
echo "::set-output name=BUILD_VERSION::$version" | |
working-directory: .github/workflows/scripts | |
- name: Generate package version prefix | |
id: generateVersionPrefixStep | |
shell: pwsh | |
run: | | |
if('${{ github.ref }}' -eq 'refs/heads/main') { echo "::set-output name=BUILD_VERSION_PREFIX::" } | |
else { echo "::set-output name=BUILD_VERSION_PREFIX::-preview-${{ github.run_number }}" } | |
# Build solution (and package nuget) | |
- name: Begin Sonar scan | |
run: | | |
dotnet tool install --global dotnet-sonarscanner | |
dotnet sonarscanner begin /k:mathieumack_${{ env.REPOSITORY_NAME }} /o:mathieumack /d:sonar.login=${{ secrets.SONAR_TOKEN }} /d:sonar.host.url=https://sonarcloud.io /d:sonar.cs.opencover.reportsPaths="sonarqubecoverage.opencover.xml" | |
working-directory: src | |
- name: Build and analyze | |
shell: pwsh | |
run: | | |
dotnet build --configuration Release --no-restore -p:FileVersion=${{ steps.generateVersionStep.outputs.BUILD_VERSION }} /p:Version=${{ steps.generateVersionStep.outputs.BUILD_VERSION }}${{ steps.generateVersionPrefixStep.outputs.BUILD_VERSION_PREFIX }} | |
working-directory: src | |
- name: Launch unit tests | |
run: dotnet test --configuration Release --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover --collect:"Code Coverage" /p:CoverletOutput="../sonarqubecoverage" | |
working-directory: src | |
- name: End Sonar scan | |
run: dotnet sonarscanner end /d:sonar.login=${{ secrets.SONAR_TOKEN }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
working-directory: src | |
# Publish a new version only for new features : | |
- name: Push Package to NuGet.org | |
if: startswith(github.ref,'refs/heads/feature') || startswith(github.head_ref,'feature/') || inputs.publishToNuget | |
run: dotnet nuget push **.nupkg -k ${{ secrets.NUGETAPIKEY }} -s https://api.nuget.org/v3/index.json | |
working-directory: src |