Upgrade Dockerfile and global.json to .NET 10 for improved compatibility #52
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
| # Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy | |
| # More GitHub Actions for Azure: https://github.com/Azure/actions | |
| name: Build and deploy ASP.Net Core app to Azure Web App - SampleCRUD | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths-ignore: | |
| - '**.md' | |
| - '.vscode/**' | |
| - '.gitignore' | |
| pull_request: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| env: | |
| DOTNET_VERSION: '10.0.x' | |
| AZURE_WEBAPP_NAME: 'SampleCRUD' | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read #This is required for actions/checkout | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up .NET Core | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Cache .NET packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.nuget/packages | |
| key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} | |
| restore-keys: | | |
| ${{ runner.os }}-nuget- | |
| - name: Cache npm packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.npm | |
| key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-npm- | |
| - name: Restore dependencies | |
| run: dotnet restore | |
| - name: Build with dotnet | |
| run: dotnet build --configuration Release --no-restore | |
| - name: Run tests | |
| run: dotnet test --configuration Release --no-build --verbosity normal --logger "trx;LogFileName=test-results.trx" | |
| - name: Publish test results | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: test-results | |
| path: '**/TestResults/*.trx' | |
| - name: dotnet publish | |
| run: dotnet publish Mwh.Sample.Web/Mwh.Sample.Web.csproj -c Release -o ${{env.DOTNET_ROOT}}/myapp --no-restore | |
| - name: Upload artifact for deployment job | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: .net-app | |
| path: ${{env.DOTNET_ROOT}}/myapp | |
| deploy: | |
| runs-on: ubuntu-latest | |
| needs: build | |
| environment: | |
| name: 'Production' | |
| url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} | |
| permissions: | |
| id-token: write #This is required for requesting the JWT | |
| contents: read #This is required for actions/checkout | |
| steps: | |
| - name: Download artifact from build job | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: .net-app | |
| - name: Login to Azure | |
| uses: azure/login@v2 | |
| with: | |
| client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_230B1FB69A024F8383CCEC208F65C72B }} | |
| tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_D3DD409B19D54D61B9593E42A3F27EBB }} | |
| subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_3A52DE86194D40A5BA27A5A31B4A1984 }} | |
| - name: Deploy to Azure Web App | |
| id: deploy-to-webapp | |
| uses: azure/webapps-deploy@v3 | |
| with: | |
| app-name: ${{ env.AZURE_WEBAPP_NAME }} | |
| slot-name: 'Production' | |
| package: . | |
| - name: Verify deployment | |
| run: | | |
| echo "Deployment successful!" | |
| echo "Application URL: ${{ steps.deploy-to-webapp.outputs.webapp-url }}" | |
| - name: Health check | |
| run: | | |
| sleep 30 | |
| response=$(curl -s -o /dev/null -w "%{http_code}" ${{ steps.deploy-to-webapp.outputs.webapp-url }}) | |
| if [ $response -eq 200 ]; then | |
| echo "Health check passed with status code: $response" | |
| else | |
| echo "Health check failed with status code: $response" | |
| exit 1 | |
| fi |