MarketAlly.AIPlugin.Extensions/MarketAlly.AIPlugin.DevOps/.github/workflows/ci.yml

280 lines
8.1 KiB
YAML
Executable File

name: CI/CD Pipeline
on:
push:
branches: [ main, develop, Working/Implementation ]
pull_request:
branches: [ main ]
permissions:
contents: read
checks: write
security-events: write
env:
DOTNET_VERSION: '8.0.x'
BUILD_CONFIGURATION: 'Release'
jobs:
test:
name: Test
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Cache NuGet packages
uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Restore dependencies
run: dotnet restore MarketAlly.AIPlugin.DevOps.csproj
- name: Build
run: dotnet build MarketAlly.AIPlugin.DevOps.csproj --no-restore --configuration ${{ env.BUILD_CONFIGURATION }}
- name: Test
run: |
dotnet test Tests/ --no-build --configuration ${{ env.BUILD_CONFIGURATION }} \
--collect:"XPlat Code Coverage" \
--logger "trx;LogFileName=test-results.trx" \
--results-directory ./TestResults/
continue-on-error: true
- name: Upload test results
uses: actions/upload-artifact@v3
if: always()
with:
name: test-results
path: ./TestResults/
security-scan:
name: Security Scan
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Install Security Scan Tools
run: |
dotnet tool install -g security-scan
dotnet tool install -g dotnet-sonarscanner
continue-on-error: true
- name: Run Security Analysis
run: |
echo "Running security analysis..."
# Add your security scanning commands here
# Example: security-scan --project . --format sarif --output security-results.sarif
continue-on-error: true
- name: Upload security results
uses: github/codeql-action/upload-sarif@v2
if: always()
with:
sarif_file: security-results.sarif
continue-on-error: true
build-and-package:
name: Build and Package
runs-on: ubuntu-latest
needs: [test, security-scan]
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/Working/Implementation'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for versioning
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Cache NuGet packages
uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Restore dependencies
run: dotnet restore MarketAlly.AIPlugin.DevOps.csproj
- name: Build Release
run: dotnet build MarketAlly.AIPlugin.DevOps.csproj --configuration ${{ env.BUILD_CONFIGURATION }} --no-restore
- name: Package
run: dotnet pack MarketAlly.AIPlugin.DevOps.csproj --configuration ${{ env.BUILD_CONFIGURATION }} --no-build --output ./packages
- name: Upload packages
uses: actions/upload-artifact@v3
with:
name: nuget-packages
path: ./packages/*.nupkg
performance-test:
name: Performance Test
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/Working/Implementation')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Build for Performance Testing
run: |
dotnet restore MarketAlly.AIPlugin.DevOps.csproj
dotnet build MarketAlly.AIPlugin.DevOps.csproj --configuration Release
- name: Run Performance Tests
run: |
echo "Running performance tests..."
# Add performance testing commands here
# Example: dotnet run --project PerformanceTests -- --benchmark
continue-on-error: true
integration-test:
name: Integration Test
runs-on: ubuntu-latest
needs: test
strategy:
matrix:
pipeline-type: [github, azure, gitlab]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Build
run: |
dotnet restore MarketAlly.AIPlugin.DevOps.csproj
dotnet build MarketAlly.AIPlugin.DevOps.csproj --configuration ${{ env.BUILD_CONFIGURATION }}
- name: Test ${{ matrix.pipeline-type }} Pipeline Analysis
run: |
echo "Testing ${{ matrix.pipeline-type }} pipeline analysis..."
# Add integration test commands here
# Example: dotnet test IntegrationTests/ --filter "Category=${{ matrix.pipeline-type }}"
continue-on-error: true
quality-gate:
name: Quality Gate
runs-on: ubuntu-latest
needs: [test, security-scan, performance-test, integration-test]
if: always()
steps:
- name: Check Previous Jobs
run: |
echo "Test Status: ${{ needs.test.result }}"
echo "Security Scan Status: ${{ needs.security-scan.result }}"
echo "Performance Test Status: ${{ needs.performance-test.result }}"
echo "Integration Test Status: ${{ needs.integration-test.result }}"
- name: Quality Gate Decision
run: |
if [[ "${{ needs.test.result }}" != "success" ]]; then
echo "Quality Gate FAILED: Tests did not pass"
exit 1
fi
if [[ "${{ needs.security-scan.result }}" == "failure" ]]; then
echo "Quality Gate WARNING: Security scan failed"
# In production, you might want to fail here
fi
echo "Quality Gate PASSED"
deploy-staging:
name: Deploy to Staging
runs-on: ubuntu-latest
needs: [quality-gate]
if: github.ref == 'refs/heads/Working/Implementation' && github.event_name == 'push'
environment:
name: staging
url: https://staging.marketally.com
steps:
- name: Download packages
uses: actions/download-artifact@v3
with:
name: nuget-packages
path: ./packages
- name: Deploy to Staging
run: |
echo "Deploying to staging environment..."
echo "Package files:"
ls -la ./packages/
# Add deployment commands here
env:
STAGING_API_KEY: ${{ secrets.STAGING_API_KEY }}
deploy-production:
name: Deploy to Production
runs-on: ubuntu-latest
needs: [quality-gate]
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
environment:
name: production
url: https://www.nuget.org/packages/MarketAlly.AIPlugin.DevOps
steps:
- name: Download packages
uses: actions/download-artifact@v3
with:
name: nuget-packages
path: ./packages
- name: Deploy to NuGet
run: |
echo "Deploying to NuGet..."
echo "Package files:"
ls -la ./packages/
# dotnet nuget push "./packages/*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
cleanup:
name: Cleanup
runs-on: ubuntu-latest
needs: [deploy-staging, deploy-production]
if: always()
steps:
- name: Cleanup artifacts
run: |
echo "Cleaning up build artifacts and temporary files..."
# Add cleanup commands if needed