|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + pull_request: |
| 7 | + branches: [ main ] |
| 8 | + |
| 9 | +env: |
| 10 | + DOTNET_NOLOGO: true |
| 11 | + INCLUDE_SYMBOLS: true |
| 12 | + |
| 13 | +jobs: |
| 14 | + pr-checks: |
| 15 | + if: github.event_name == 'pull_request' |
| 16 | + runs-on: ubuntu-latest |
| 17 | + permissions: |
| 18 | + contents: read |
| 19 | + pull-requests: write |
| 20 | + steps: |
| 21 | + - name: Checkout |
| 22 | + uses: actions/checkout@v4 |
| 23 | + |
| 24 | + - name: Setup .NET |
| 25 | + uses: actions/setup-dotnet@v4 |
| 26 | + with: |
| 27 | + dotnet-version: 10.0.x |
| 28 | + |
| 29 | + - name: Restore |
| 30 | + run: | |
| 31 | + dotnet tool restore |
| 32 | + dotnet restore --use-lock-file |
| 33 | +
|
| 34 | + - name: Build (Release) |
| 35 | + run: dotnet build ExperimentFramework.slnx --configuration Release --no-restore /p:ContinuousIntegrationBuild=true |
| 36 | + |
| 37 | + - name: Test with coverage |
| 38 | + run: | |
| 39 | + dotnet test ExperimentFramework.slnx \ |
| 40 | + --configuration Release \ |
| 41 | + --collect:"XPlat Code Coverage" \ |
| 42 | + -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura \ |
| 43 | + -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Include="[ExperimentFramework*]*" \ |
| 44 | + -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Exclude="[*Tests]*" |
| 45 | +
|
| 46 | + - name: Install ReportGenerator |
| 47 | + run: dotnet tool update -g dotnet-reportgenerator-globaltool |
| 48 | + |
| 49 | + - name: Combine coverage and create reports |
| 50 | + shell: bash |
| 51 | + run: | |
| 52 | + REPORTS=$(find . -type f -path "*/TestResults/*/coverage.cobertura.xml" | tr '\n' ';') |
| 53 | + reportgenerator \ |
| 54 | + -reports:"$REPORTS" \ |
| 55 | + -targetdir:"coverage-report" \ |
| 56 | + -reporttypes:"HtmlInline;Cobertura;TextSummary;lcov;Badges" \ |
| 57 | + -assemblyfilters:"+ExperimentFramework*;-*Tests*" \ |
| 58 | + -filefilters:"-**/*.Tests/*;-**/*Tests*/**" |
| 59 | + echo "COVERAGE_SUMMARY<<EOF" >> $GITHUB_ENV |
| 60 | + cat coverage-report/Summary.txt >> $GITHUB_ENV |
| 61 | + echo "EOF" >> $GITHUB_ENV |
| 62 | +
|
| 63 | + - name: Upload coverage HTML report |
| 64 | + uses: actions/upload-artifact@v4 |
| 65 | + with: |
| 66 | + name: coverage-report |
| 67 | + path: coverage-report |
| 68 | + |
| 69 | + - name: Add coverage summary to PR |
| 70 | + uses: marocchino/sticky-pull-request-comment@v2 |
| 71 | + with: |
| 72 | + recreate: true |
| 73 | + message: | |
| 74 | + ## Code Coverage |
| 75 | + ``` |
| 76 | + ${{ env.COVERAGE_SUMMARY }} |
| 77 | + ``` |
| 78 | +
|
| 79 | + - name: Upload coverage to Codecov |
| 80 | + uses: codecov/codecov-action@v4 |
| 81 | + with: |
| 82 | + files: | |
| 83 | + **/TestResults/*/coverage.cobertura.xml |
| 84 | + flags: unittests |
| 85 | + fail_ci_if_error: true |
| 86 | + verbose: true |
| 87 | + env: |
| 88 | + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |
| 89 | + |
| 90 | + release: |
| 91 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 92 | + runs-on: ubuntu-latest |
| 93 | + permissions: |
| 94 | + contents: write |
| 95 | + packages: write |
| 96 | + steps: |
| 97 | + - name: Checkout |
| 98 | + uses: actions/checkout@v4 |
| 99 | + with: |
| 100 | + fetch-depth: 0 |
| 101 | + |
| 102 | + - name: Setup .NET |
| 103 | + uses: actions/setup-dotnet@v4 |
| 104 | + with: |
| 105 | + dotnet-version: 10.0.x |
| 106 | + |
| 107 | + - name: Restore |
| 108 | + run: | |
| 109 | + dotnet restore --use-lock-file |
| 110 | + dotnet tool restore |
| 111 | +
|
| 112 | + - name: Fetch tags |
| 113 | + run: git fetch --prune --tags |
| 114 | + |
| 115 | + - name: Install GitVersion |
| 116 | + uses: gittools/actions/gitversion/setup@v1 |
| 117 | + with: |
| 118 | + versionSpec: '5.x' |
| 119 | + |
| 120 | + - name: Run GitVersion |
| 121 | + id: gitversion |
| 122 | + uses: gittools/actions/gitversion/execute@v1 |
| 123 | + |
| 124 | + - name: Set version env vars |
| 125 | + run: | |
| 126 | + echo "PACKAGE_VERSION=${{ steps.gitversion.outputs.nuGetVersionV2 }}" >> $GITHUB_ENV |
| 127 | + echo "ASSEMBLY_VERSION=${{ steps.gitversion.outputs.assemblySemVer }}" >> $GITHUB_ENV |
| 128 | + echo "FILE_VERSION=${{ steps.gitversion.outputs.assemblySemFileVer }}" >> $GITHUB_ENV |
| 129 | +
|
| 130 | + - name: Build (Release) |
| 131 | + run: > |
| 132 | + dotnet build ExperimentFramework.slnx |
| 133 | + --configuration Release |
| 134 | + --no-restore |
| 135 | + /p:ContinuousIntegrationBuild=true |
| 136 | + /p:Version=${{ env.PACKAGE_VERSION }} |
| 137 | + /p:AssemblyVersion=${{ env.ASSEMBLY_VERSION }} |
| 138 | + /p:FileVersion=${{ env.FILE_VERSION }} |
| 139 | + /p:PackageVersion=${{ env.PACKAGE_VERSION }} |
| 140 | +
|
| 141 | + - name: Test (Release) |
| 142 | + run: dotnet test ExperimentFramework.slnx --configuration Release --no-build --verbosity normal |
| 143 | + |
| 144 | + - name: Pack (all packable projects) |
| 145 | + run: > |
| 146 | + dotnet pack ExperimentFramework.slnx |
| 147 | + --configuration Release |
| 148 | + --no-build |
| 149 | + --output ./artifacts |
| 150 | + /p:ContinuousIntegrationBuild=true |
| 151 | + /p:IncludeSymbols=${{ env.INCLUDE_SYMBOLS }} |
| 152 | + /p:SymbolPackageFormat=snupkg |
| 153 | + /p:Version=${{ env.PACKAGE_VERSION }} |
| 154 | + /p:AssemblyVersion=${{ env.ASSEMBLY_VERSION }} |
| 155 | + /p:FileVersion=${{ env.FILE_VERSION }} |
| 156 | + /p:PackageVersion=${{ env.PACKAGE_VERSION }} |
| 157 | +
|
| 158 | + - name: Upload packages as artifact |
| 159 | + uses: actions/upload-artifact@v4 |
| 160 | + with: |
| 161 | + name: nuget-packages |
| 162 | + path: | |
| 163 | + ./artifacts/*.nupkg |
| 164 | + ./artifacts/*.snupkg |
| 165 | +
|
| 166 | + - name: Create and push git tag |
| 167 | + shell: bash |
| 168 | + run: | |
| 169 | + set -euo pipefail |
| 170 | + git config user.name "github-actions" |
| 171 | + git config user.email "[email protected]" |
| 172 | + if git rev-parse "v${PACKAGE_VERSION}" >/dev/null 2>&1; then |
| 173 | + echo "Tag v${PACKAGE_VERSION} already exists. Skipping tag push." |
| 174 | + else |
| 175 | + git tag "v${PACKAGE_VERSION}" |
| 176 | + git push origin "v${PACKAGE_VERSION}" |
| 177 | + fi |
| 178 | +
|
| 179 | + - name: Create GitHub Release |
| 180 | + uses: softprops/action-gh-release@v2 |
| 181 | + with: |
| 182 | + tag_name: v${{ env.PACKAGE_VERSION }} |
| 183 | + name: Release v${{ env.PACKAGE_VERSION }} |
| 184 | + files: | |
| 185 | + ./artifacts/*.nupkg |
| 186 | + ./artifacts/*.snupkg |
| 187 | + generate_release_notes: true |
| 188 | + |
| 189 | + - name: Push to NuGet.org |
| 190 | + env: |
| 191 | + NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} |
| 192 | + run: | |
| 193 | + if [ -n "$NUGET_API_KEY" ]; then |
| 194 | + dotnet nuget push ./artifacts/*.nupkg \ |
| 195 | + --api-key "$NUGET_API_KEY" \ |
| 196 | + --source https://api.nuget.org/v3/index.json \ |
| 197 | + --skip-duplicate |
| 198 | + else |
| 199 | + echo "Skipping NuGet.org push: API key not set." |
| 200 | + fi |
| 201 | +
|
| 202 | + - name: Push to GitHub Packages (optional) |
| 203 | + run: | |
| 204 | + dotnet nuget push "./artifacts/*.nupkg" \ |
| 205 | + --source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" \ |
| 206 | + --api-key "${{ secrets.GITHUB_TOKEN }}" \ |
| 207 | + --skip-duplicate |
| 208 | + dotnet nuget push "./artifacts/*.snupkg" \ |
| 209 | + --source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" \ |
| 210 | + --api-key "${{ secrets.GITHUB_TOKEN }}" \ |
| 211 | + --skip-duplicate |
0 commit comments