name: CI/CD Pipeline on: workflow_dispatch: push: branches: [main, dev] pull_request: branches: [main, dev] env: DOTNET_VERSION: '8.0.x' JAVA_VERSION: '11' JAVA_DISTRIBUTION: 'zulu' jobs: build_test_publish: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 with: fetch-depth: 0 - name: Setup environment run: | sudo mkdir -p /Quantower/ sudo chmod -R 777 /Quantower - name: Setup .NET uses: actions/setup-dotnet@v3 with: dotnet-version: ${{ env.DOTNET_VERSION }} - name: Setup Java uses: actions/setup-java@v3 with: java-version: ${{ env.JAVA_VERSION }} distribution: ${{ env.JAVA_DISTRIBUTION }} - name: Install tools run: | dotnet tool install --global GitVersion.Tool dotnet tool install --global dotnet-sonarscanner --version 8.0.3 dotnet tool install --global dotnet-coverage - name: Determine Version id: gitversion run: | dotnet-gitversion echo "::set-output name=MajorMinorPatch::$(dotnet-gitversion /output json /showvariable MajorMinorPatch)" echo "::set-output name=FullSemVer::$(dotnet-gitversion /output json /showvariable FullSemVer)" echo "::set-output name=SemVer::$(dotnet-gitversion /output json /showvariable SemVer)" - name: Start Sonar analysis if: github.ref == 'refs/heads/dev' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} run: | dotnet sonarscanner begin /o:"mihakralj" /k:"mihakralj_QuanTAlib" \ /d:sonar.token="${{ secrets.SONAR_TOKEN }}" \ /d:sonar.scanner.scanAll=false \ /d:sonar.host.url="https://sonarcloud.io" \ /d:sonar.cs.opencover.reportsPaths="**/TestResults/coverage.opencover.xml" \ /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml - name: Build projects run: | dotnet build ./lib/quantalib.csproj --configuration Release --nologo \ -p:PackageVersion=${{ github.ref == 'refs/heads/dev' && steps.gitversion.outputs.FullSemVer || steps.gitversion.outputs.MajorMinorPatch }} dotnet build ./quantower/Averages/Averages.csproj --configuration Release --nologo dotnet build ./quantower/Statistics/Statistics.csproj --configuration Release --nologo dotnet build ./SyntheticVendor/SyntheticVendor.csproj --configuration Release --nologo - name: Run tests with coverage if: github.ref == 'refs/heads/dev' run: | dotnet test --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput="./TestResults/" dotnet-coverage collect "dotnet test" -f xml -o "coverage.xml" - name: Generate and process coverage report if: github.ref == 'refs/heads/dev' uses: danielpalme/ReportGenerator-GitHub-Action@5.1.26 with: reports: '**/TestResults/coverage.opencover.xml' targetdir: 'coveragereport' reporttypes: 'HtmlInline;Cobertura' - name: Upload coverage to Codacy if: github.ref == 'refs/heads/dev' uses: codacy/codacy-coverage-reporter-action@v1 with: project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} coverage-reports: "coveragereport/Cobertura.xml" - name: Upload coverage to Codecov if: github.ref == 'refs/heads/dev' uses: codecov/codecov-action@v3 with: files: coveragereport/Cobertura.xml verbose: true - name: Finish Sonar analysis if: github.ref == 'refs/heads/dev' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} run: dotnet sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" - name: Publish release assets uses: SourceSprint/upload-multiple-releases@1.0.7 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: prerelease: ${{ github.ref == 'refs/heads/dev' }} overwrite: true release_name: ${{ github.ref == 'refs/heads/dev' && steps.gitversion.outputs.SemVer || steps.gitversion.outputs.MajorMinorPatch }} tag_name: ${{ steps.gitversion.outputs.SemVer }} release_config: | quantower/Averages/bin/Release/Averages.dll quantower/Statistics/bin/Release/Statistics.dll SyntheticVendor/bin/Release/SyntheticVendor.dll - name: Push package to myget.org run: | dotnet nuget push 'lib/bin/Release/QuanTAlib.*.nupkg' \ --api-key ${{ secrets.MYGET_DEPLOY_KEY_QUANTALIB }} \ --source https://www.myget.org/F/quantalib/api/v2/package \ --skip-duplicate - name: Push package to nuget.org if: github.ref == 'refs/heads/main' run: | dotnet nuget push 'lib/bin/Release/QuanTAlib.*.nupkg' \ --api-key ${{ secrets.NUGET_DEPLOY_KEY_QUANTLIB }} \ --source https://api.nuget.org/v3/index.json \ --skip-duplicate