|
| 1 | +# ============================================================================= |
| 2 | +# Author: Vladyslav Zaiets | https://sarmkadan.com |
| 3 | +# CTO & Software Architect |
| 4 | +# ============================================================================= |
| 5 | + |
| 6 | +name: Build & Test |
| 7 | + |
| 8 | +on: |
| 9 | + push: |
| 10 | + branches: [ main, develop ] |
| 11 | + pull_request: |
| 12 | + branches: [ main, develop ] |
| 13 | + |
| 14 | +jobs: |
| 15 | + build: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + services: |
| 19 | + mssql: |
| 20 | + image: mcr.microsoft.com/mssql/server:2022-latest |
| 21 | + env: |
| 22 | + SA_PASSWORD: TestPassword123! |
| 23 | + ACCEPT_EULA: Y |
| 24 | + options: >- |
| 25 | + --health-cmd="/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P TestPassword123! -Q 'SELECT 1'" |
| 26 | + --health-interval 15s |
| 27 | + --health-timeout 5s |
| 28 | + --health-retries 5 |
| 29 | + ports: |
| 30 | + - 1433:1433 |
| 31 | + |
| 32 | + steps: |
| 33 | + - uses: actions/checkout@v4 |
| 34 | + with: |
| 35 | + fetch-depth: 0 |
| 36 | + |
| 37 | + - name: Setup .NET |
| 38 | + uses: actions/setup-dotnet@v4 |
| 39 | + with: |
| 40 | + dotnet-version: '10.0.x' |
| 41 | + |
| 42 | + - name: Restore dependencies |
| 43 | + run: dotnet restore |
| 44 | + |
| 45 | + - name: Build |
| 46 | + run: dotnet build --configuration Release --no-restore |
| 47 | + |
| 48 | + - name: Run tests |
| 49 | + run: dotnet test --configuration Release --no-build --logger "console;verbosity=detailed" |
| 50 | + env: |
| 51 | + ConnectionStrings__DefaultConnection: "Server=localhost;Database=FeatureFlagEngineTest;User Id=sa;Password=TestPassword123!;TrustServerCertificate=true;" |
| 52 | + |
| 53 | + - name: Pack NuGet |
| 54 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 55 | + run: dotnet pack src/FeatureFlags/FeatureFlags.csproj --configuration Release --output ./nupkg |
| 56 | + |
| 57 | + - name: Upload NuGet artifacts |
| 58 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 59 | + uses: actions/upload-artifact@v4 |
| 60 | + with: |
| 61 | + name: nuget-package |
| 62 | + path: ./nupkg/**/*.nupkg |
| 63 | + |
| 64 | + code-quality: |
| 65 | + runs-on: ubuntu-latest |
| 66 | + |
| 67 | + steps: |
| 68 | + - uses: actions/checkout@v4 |
| 69 | + with: |
| 70 | + fetch-depth: 0 |
| 71 | + |
| 72 | + - name: Setup .NET |
| 73 | + uses: actions/setup-dotnet@v4 |
| 74 | + with: |
| 75 | + dotnet-version: '10.0.x' |
| 76 | + |
| 77 | + - name: Restore dependencies |
| 78 | + run: dotnet restore |
| 79 | + |
| 80 | + - name: Analyze code style |
| 81 | + run: dotnet format --verify-no-changes --verbosity diagnostic |
| 82 | + |
| 83 | + - name: SonarCloud Scan |
| 84 | + uses: SonarSource/sonarcloud-github-action@master |
| 85 | + env: |
| 86 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 87 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 88 | + |
| 89 | + security: |
| 90 | + runs-on: ubuntu-latest |
| 91 | + |
| 92 | + steps: |
| 93 | + - uses: actions/checkout@v4 |
| 94 | + |
| 95 | + - name: Run Trivy vulnerability scanner |
| 96 | + uses: aquasecurity/trivy-action@master |
| 97 | + with: |
| 98 | + scan-type: 'fs' |
| 99 | + scan-ref: '.' |
| 100 | + format: 'sarif' |
| 101 | + output: 'trivy-results.sarif' |
| 102 | + |
| 103 | + - name: Upload Trivy results to GitHub Security tab |
| 104 | + uses: github/codeql-action/upload-sarif@v3 |
| 105 | + with: |
| 106 | + sarif_file: 'trivy-results.sarif' |
| 107 | + |
| 108 | + docker-build: |
| 109 | + runs-on: ubuntu-latest |
| 110 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 111 | + |
| 112 | + steps: |
| 113 | + - uses: actions/checkout@v4 |
| 114 | + |
| 115 | + - name: Set up Docker Buildx |
| 116 | + uses: docker/setup-buildx-action@v3 |
| 117 | + |
| 118 | + - name: Build Docker image |
| 119 | + uses: docker/build-push-action@v5 |
| 120 | + with: |
| 121 | + context: . |
| 122 | + push: false |
| 123 | + tags: feature-flags:${{ github.sha }} |
| 124 | + cache-from: type=registry,ref=feature-flags:buildcache |
| 125 | + cache-to: type=registry,ref=feature-flags:buildcache,mode=max |
0 commit comments