run dump #11
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: Build, Test, and Deploy | |
| on: | |
| push: | |
| branches: ['**'] | |
| pull_request: | |
| branches: ['**'] | |
| jobs: | |
| build-test: | |
| strategy: | |
| matrix: | |
| os: [ubuntu-latest, windows-latest, macos-latest] | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup .NET 10 | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: '10.0.x' | |
| - name: Restore dependencies | |
| run: dotnet restore src/MyBlog.slnx | |
| - name: Build solution | |
| run: dotnet build src/MyBlog.slnx -c Release --no-restore | |
| - name: Run tests | |
| run: dotnet test src/MyBlog.slnx -c Release --no-build --logger trx --results-directory TestResults | |
| - name: Upload test results | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: test-results-${{ matrix.os }} | |
| path: TestResults | |
| retention-days: 7 | |
| deploy: | |
| needs: build-test | |
| if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' | |
| runs-on: windows-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup .NET 10 | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: '10.0.x' | |
| - name: Publish application | |
| run: dotnet publish src/MyBlog.Web/MyBlog.Web.csproj -c Release -o ./publish -r win-x86 --self-contained false | |
| - name: Deploy via WebDeploy | |
| shell: pwsh | |
| env: | |
| DEPLOY_SOURCE: ${{ github.workspace }}\publish | |
| DEPLOY_SITE: ${{ secrets.WEBSITE_NAME }} | |
| DEPLOY_HOST: ${{ secrets.SERVER_COMPUTER_NAME }} | |
| DEPLOY_USER: ${{ secrets.SERVER_USERNAME }} | |
| DEPLOY_PASSWORD: ${{ secrets.SERVER_PASSWORD }} | |
| run: | | |
| $msdeployPath = "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" | |
| if (-not (Test-Path $msdeployPath)) { | |
| Write-Host "Installing Web Deploy..." | |
| choco install webdeploy -y --no-progress | |
| } | |
| Write-Host "Deploying to $env:DEPLOY_HOST..." | |
| Write-Host "Note: Using AppOffline rule to prevent file-in-use errors" | |
| $sourceArg = "-source:contentPath=$env:DEPLOY_SOURCE" | |
| $destArg = "-dest:contentPath=$env:DEPLOY_SITE,computerName=https://$($env:DEPLOY_HOST):8172/MsDeploy.axd?site=$env:DEPLOY_SITE,userName=$env:DEPLOY_USER,password=$env:DEPLOY_PASSWORD,AuthType='Basic'" | |
| # Key fix: Added -enableRule:AppOffline to stop the app during deployment | |
| # This creates app_offline.htm, waits for app to stop, deploys, then removes the file | |
| & $msdeployPath -verb:sync $sourceArg $destArg ` | |
| -allowUntrusted ` | |
| -enableRule:DoNotDeleteRule ` | |
| -enableRule:AppOffline ` | |
| -retryAttempts:3 ` | |
| -retryInterval:3000 | |
| if ($LASTEXITCODE -ne 0) { | |
| Write-Error "Deployment failed with exit code $LASTEXITCODE" | |
| exit 1 | |
| } | |
| Write-Host "Deployment completed successfully!" |