This repository was archived by the owner on Nov 11, 2025. It is now read-only.
CI #25
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 | |
| - main | |
| - develop | |
| - beta/* | |
| - release/* | |
| - experimental/* | |
| - feature/* | |
| paths-ignore: | |
| - 'README.md' | |
| - 'docs/**' | |
| - 'samples/**' | |
| pull_request: | |
| branches: | |
| - master | |
| - main | |
| - develop | |
| env: | |
| DOTNET_VERSION: '10.x' | |
| NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages | |
| jobs: | |
| validate: | |
| name: Validate Build Context | |
| runs-on: windows-latest | |
| steps: | |
| - name: Display build context | |
| run: | | |
| echo "Build branch: ${{ github.ref }}" | |
| echo "Build configuration: ${{ env.BUILD_CONFIGURATION }}" | |
| echo ".NET Version: ${{ env.DOTNET_VERSION }}" | |
| build: | |
| name: Build and Test | |
| runs-on: windows-latest | |
| needs: validate | |
| env: | |
| BUILD_CONFIGURATION: ${{ github.ref == 'refs/heads/master' && 'Release' || github.ref == 'refs/heads/develop' && 'Alpha' || startsWith(github.ref, 'refs/heads/beta/') && 'Beta' || startsWith(github.ref, 'refs/heads/release/') && 'Preview' || startsWith(github.ref, 'refs/heads/experimental/') && 'Experimental' || 'Debug' }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| dotnet-quality: 'preview' | |
| - name: Cache NuGet packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ env.NUGET_PACKAGES }} | |
| key: ${{ runner.os }}-nuget-${{ hashFiles('**/Directory.Packages.props') }} | |
| restore-keys: | | |
| ${{ runner.os }}-nuget- | |
| - name: Set version variables | |
| uses: dotnet/nbgv@master | |
| with: | |
| setAllVars: true | |
| - name: Install ReportGenerator | |
| run: dotnet tool install -g dotnet-reportgenerator-globaltool | |
| - name: Restore packages | |
| run: dotnet restore | |
| - name: Build | |
| run: dotnet build --configuration ${{ env.BUILD_CONFIGURATION }} --no-restore -p:ContinuousIntegrationBuild=true | |
| - name: Run unit tests with coverage | |
| run: | | |
| dotnet test --configuration ${{ env.BUILD_CONFIGURATION }} --no-build --collect:"XPlat Code Coverage" --settings coverlet.runsettings --filter "Category!=Integration" --logger trx --results-directory ${{ runner.temp }} | |
| continue-on-error: ${{ contains(fromJSON('["Experimental", "Alpha"]'), env.BUILD_CONFIGURATION) }} | |
| - name: Generate coverage report | |
| if: always() | |
| run: | | |
| reportgenerator -reports:${{ runner.temp }}/**/coverage.cobertura.xml -targetdir:${{ runner.temp }}/CodeCoverage -reporttypes:"Cobertura;HtmlInline_AzurePipelines;Badges" | |
| continue-on-error: true | |
| - name: Upload test results | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-results | |
| path: ${{ runner.temp }}/*.trx | |
| - name: Upload coverage report | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-report | |
| path: ${{ runner.temp }}/CodeCoverage | |
| - name: Pack packages | |
| run: | | |
| dotnet pack --configuration ${{ env.BUILD_CONFIGURATION }} --no-build --output ${{ github.workspace }}/packages -p:RepositoryUrl=${{ github.server_url }}/${{ github.repository }} -p:RepositoryBranch=${{ github.ref_name }} -p:RepositoryCommit=${{ github.sha }} | |
| - name: Upload packages | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: packages | |
| path: ${{ github.workspace }}/packages | |
| security-scan: | |
| name: Security Scanning | |
| runs-on: windows-latest | |
| needs: validate | |
| if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/heads/beta/') || startsWith(github.ref, 'refs/heads/release/') | |
| permissions: | |
| actions: read | |
| contents: read | |
| security-events: write | |
| env: | |
| BUILD_CONFIGURATION: Release | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| dotnet-quality: 'preview' | |
| - name: Cache NuGet packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ env.NUGET_PACKAGES }} | |
| key: ${{ runner.os }}-nuget-${{ hashFiles('**/Directory.Packages.props') }} | |
| restore-keys: | | |
| ${{ runner.os }}-nuget- | |
| - name: Initialize CodeQL | |
| uses: github/codeql-action/init@v3 | |
| with: | |
| languages: csharp | |
| - name: Restore packages | |
| run: dotnet restore | |
| - name: Build for CodeQL | |
| run: dotnet build --configuration ${{ env.BUILD_CONFIGURATION }} --no-restore | |
| - name: Perform CodeQL Analysis | |
| uses: github/codeql-action/analyze@v3 | |
| - name: Security audit | |
| run: dotnet list package --vulnerable --include-transitive | |
| publish-packages: | |
| name: Publish Packages | |
| runs-on: windows-latest | |
| needs: [build, security-scan] | |
| if: | | |
| github.event_name == 'push' && | |
| (github.ref == 'refs/heads/master' || | |
| github.ref == 'refs/heads/main' || | |
| github.ref == 'refs/heads/develop' || | |
| startsWith(github.ref, 'refs/heads/beta/') || | |
| startsWith(github.ref, 'refs/heads/release/')) | |
| steps: | |
| - name: Download packages | |
| uses: actions/download-artifact@v6 | |
| with: | |
| name: packages | |
| path: ${{ github.workspace }}/packages | |
| # For GitHub Packages | |
| - name: Push to GitHub Packages | |
| if: github.event_name == 'push' | |
| run: | | |
| dotnet nuget push "${{ github.workspace }}/packages/*.nupkg" --source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate | |
| continue-on-error: true | |
| # For Azure Artifacts - requires secret AZURE_DEVOPS_PAT | |
| - name: Push to Azure Artifacts | |
| if: github.event_name == 'push' && env.AZURE_DEVOPS_PAT != '' | |
| env: | |
| AZURE_DEVOPS_PAT: ${{ secrets.AZURE_DEVOPS_PAT }} | |
| run: | | |
| dotnet nuget push "${{ github.workspace }}/packages/*.nupkg" --source "https://pkgs.dev.azure.com/REC-DevOps/_packaging/dotnet-packages/nuget/v3/index.json" --api-key ${{ secrets.AZURE_DEVOPS_PAT }} --skip-duplicate | |
| continue-on-error: true | |
| # For NuGet.org - publish stable and prerelease versions | |
| - name: Push to NuGet.org | |
| if: | | |
| github.event_name == 'push' && | |
| (github.ref == 'refs/heads/master' || | |
| github.ref == 'refs/heads/main' || | |
| github.ref == 'refs/heads/develop' || | |
| startsWith(github.ref, 'refs/heads/release/')) && | |
| env.NUGET_API_KEY != '' | |
| env: | |
| NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} | |
| run: | | |
| dotnet nuget push "${{ github.workspace }}/packages/*.nupkg" --source "https://api.nuget.org/v3/index.json" --api-key ${{ secrets.NUGET_API_KEY }} --skip-duplicate | |
| continue-on-error: true | |
| - name: Tag release | |
| if: github.ref == 'refs/heads/master' | |
| run: | | |
| git config user.email "mike.blair@rayburnelectric.com" | |
| git config user.name "Mike Blair" | |
| git tag -a "v${{ env.NBGV_SemVer2 }}" -m "Release v${{ env.NBGV_SemVer2 }}" | |
| git push origin "v${{ env.NBGV_SemVer2 }}" | |
| continue-on-error: true |