Merge pull request #3 from islero/dependabot/github_actions/actions/d… #27
This file contains hidden or 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, beta, dev] | |
| tags: ['v*'] | |
| pull_request: | |
| branches: [master, beta, dev] | |
| env: | |
| DOTNET_VERSION: '9.0.x' | |
| DOTNET_NOLOGO: true | |
| DOTNET_CLI_TELEMETRY_OPTOUT: true | |
| NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages | |
| jobs: | |
| build: | |
| name: Build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Cache NuGet packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ env.NUGET_PACKAGES }} | |
| key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/Directory.Build.props') }} | |
| restore-keys: | | |
| ${{ runner.os }}-nuget- | |
| - name: Restore dependencies | |
| run: dotnet restore | |
| - name: Build | |
| run: dotnet build --configuration Release --no-restore | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: build-artifacts | |
| path: | | |
| **/bin/Release/ | |
| !**/bin/Release/**/*.nupkg | |
| retention-days: 1 | |
| test: | |
| name: Test | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Cache NuGet packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ env.NUGET_PACKAGES }} | |
| key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/Directory.Build.props') }} | |
| restore-keys: | | |
| ${{ runner.os }}-nuget- | |
| - name: Restore dependencies | |
| run: dotnet restore | |
| - name: Test with coverage | |
| run: | | |
| dotnet test --configuration Release \ | |
| --logger "trx;LogFileName=test-results.trx" \ | |
| --collect:"XPlat Code Coverage" \ | |
| --results-directory ./TestResults | |
| - name: Upload test results | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: test-results | |
| path: ./TestResults | |
| retention-days: 7 | |
| pack: | |
| name: Pack | |
| needs: test | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/beta' || startsWith(github.ref, 'refs/tags/v') | |
| outputs: | |
| version: ${{ steps.version.outputs.version }} | |
| is_prerelease: ${{ steps.version.outputs.is_prerelease }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Cache NuGet packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ env.NUGET_PACKAGES }} | |
| key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/Directory.Build.props') }} | |
| restore-keys: | | |
| ${{ runner.os }}-nuget- | |
| - name: Restore dependencies | |
| run: dotnet restore | |
| - name: Build | |
| run: dotnet build src/Backtest.Net/Backtest.Net.csproj --configuration Release --no-restore | |
| - name: Determine version | |
| id: version | |
| run: | | |
| # Read base version from csproj | |
| BASE_VERSION=$(grep -oP '(?<=<Version>)[^<]+' src/Backtest.Net/Backtest.Net.csproj || echo "4.2.0") | |
| if [[ "${{ github.ref }}" == "refs/heads/beta" ]]; then | |
| VERSION="${BASE_VERSION}-beta.${{ github.run_number }}" | |
| IS_PRERELEASE="true" | |
| elif [[ "${{ github.ref }}" == refs/tags/v* ]]; then | |
| VERSION="${GITHUB_REF#refs/tags/v}" | |
| IS_PRERELEASE="false" | |
| else | |
| VERSION="${BASE_VERSION}" | |
| IS_PRERELEASE="false" | |
| fi | |
| echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
| echo "is_prerelease=${IS_PRERELEASE}" >> $GITHUB_OUTPUT | |
| echo "Package version: ${VERSION}" | |
| - name: Pack | |
| run: | | |
| dotnet pack src/Backtest.Net/Backtest.Net.csproj \ | |
| --configuration Release \ | |
| --output ./artifacts \ | |
| -p:PackageVersion=${{ steps.version.outputs.version }} \ | |
| -p:IncludeSymbols=true \ | |
| -p:SymbolPackageFormat=snupkg | |
| - name: Upload package artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: nuget-packages | |
| path: ./artifacts/*.nupkg | |
| retention-days: 30 | |
| - name: Upload symbol packages | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: nuget-symbols | |
| path: ./artifacts/*.snupkg | |
| retention-days: 30 | |
| publish: | |
| name: Publish to NuGet | |
| needs: pack | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/beta' || startsWith(github.ref, 'refs/tags/v') | |
| environment: nuget | |
| steps: | |
| - name: Download package artifacts | |
| uses: actions/download-artifact@v7 | |
| with: | |
| name: nuget-packages | |
| path: ./artifacts | |
| - name: Download symbol packages | |
| uses: actions/download-artifact@v7 | |
| with: | |
| name: nuget-symbols | |
| path: ./artifacts | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Push to NuGet | |
| run: | | |
| dotnet nuget push ./artifacts/*.nupkg \ | |
| --api-key ${{ secrets.NUGET_API_KEY }} \ | |
| --source https://api.nuget.org/v3/index.json \ | |
| --skip-duplicate | |
| - name: Create GitHub Release | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: | | |
| ./artifacts/*.nupkg | |
| ./artifacts/*.snupkg | |
| generate_release_notes: true | |
| prerelease: ${{ needs.pack.outputs.is_prerelease == 'true' }} |