Migrating to GH actions #12
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: CI | |
on: | |
push: | |
branches: | |
- master | |
- ci-gh-action-migration # For testing GitHub Action Workflows | |
pull_request: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: display git info about the checkout stuff | |
run: git branch --show-current | |
- name: Set up JDK 15 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'adopt' | |
java-version: '15' | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: '6.0.x' | |
- name: List files | |
run: ls -la | |
- name: Install .NET tools | |
run: | | |
dotnet tool install -g GitVersion.Tool | |
dotnet tool install -g dotnet-format | |
dotnet tool install -g dotnet-sonarscanner -v:m | |
- name: Add .NET tools to PATH | |
run: echo "::add-path::$HOME/.dotnet/tools" | |
- uses: gittools/actions/gitversion/[email protected] | |
id: gitversion | |
- name: Restore dependencies | |
run: dotnet restore | |
- name: Patch csproj files with version | |
run: | | |
find . -name '*.csproj' -exec sed -i 's/<Version>.*<\/Version>/<Version>${{ steps.gitversion.outputs.nugetversion }}<\/Version>/g' {} + | |
- name: SonarScanner begin | |
run: | | |
dotnet sonarscanner begin \ | |
/d:sonar.host.url=https://sonarcloud.io \ | |
/d:sonar.login=$SONAR_TOKEN \ | |
/k:mariotoffia_FluentDocker \ | |
/o:mariotoffia \ | |
/v:"${{ steps.gitversion.outputs.nugetversion }}" \ | |
/d:sonar.cs.opencover.reportsPaths="./output/coverage.opencover.xml" \ | |
/d:sonar.coverage.exclusions="**Tests*.cs" | |
env: | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
- name: Build | |
run: dotnet build FluentDocker.sln --configuration Release --no-restore --verbosity minimal /p:Version=${{ steps.gitversion.outputs.nugetversion }} | |
- name: Test | |
run: dotnet test --settings coverletArgs.runsettings --filter TestCategory=CI -f netcoreapp3.1 | |
- name: SonarScanner end | |
run: dotnet sonarscanner end /d:sonar.login=$SONAR_TOKEN | |
env: | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
- name: Package NuGet | |
run: dotnet pack FluentDocker.sln --configuration Release -o output /p:Version=${{ steps.gitversion.outputs.nugetversion }} | |
- name: Upload Artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: NuGet Packages | |
path: ./output/*.nupkg | |
# Deployment step conditioned to run only on master branch | |
- name: Deploy to NuGet | |
if: github.ref == 'refs/heads/master' && github.event_name == 'push' | |
run: echo "Deploying to NuGet..." | |
#run: dotnet nuget push ./output/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json |