Update project configurations and enhance workflows #37
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: 10 .NET | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: [main] | |
| paths: | |
| - 'dotnet-sample/**' | |
| pull_request: | |
| branches: [main] | |
| paths: | |
| - 'dotnet-sample/**' | |
| permissions: | |
| id-token: write | |
| contents: read | |
| defaults: | |
| run: | |
| working-directory: dotnet-sample | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6.0.2 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v5 | |
| with: | |
| dotnet-version: 10.0.x | |
| - name: Set up dependency caching for faster builds | |
| uses: actions/cache@v5 | |
| with: | |
| path: ~/.nuget/packages | |
| key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-nuget- | |
| - name: Restore dependencies | |
| run: dotnet restore | |
| - name: Build | |
| run: dotnet build --no-restore | |
| - name: Test | |
| run: dotnet test --configuration Release --no-build --verbosity normal | |
| - name: dotnet publish | |
| run: dotnet publish src/dotnet-sample.csproj -c Release -o ./webapp | |
| - name: Upload artifact for deployment job | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: webapp | |
| path: ./dotnet-sample/webapp | |
| - name: Upload artifact for deployment job | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: iac | |
| path: ./dotnet-sample/iac | |
| deploy-webapp: | |
| needs: [build] | |
| environment: dotnet | |
| runs-on: ubuntu-latest | |
| steps: | |
| # Checkout code | |
| - name: Download IaC | |
| uses: actions/download-artifact@v8 | |
| with: | |
| name: iac | |
| path: iac | |
| # Log into Azure | |
| - uses: azure/login@v3 | |
| name: Sign in to Azure | |
| with: | |
| client-id: ${{ secrets.AZURE_CLIENT_ID }} | |
| tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
| subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
| # Deploy Bicep file | |
| - name: deploy | |
| id: deploy | |
| uses: azure/arm-deploy@v2 | |
| with: | |
| resourceGroupName: ${{ secrets.AZURE_RG }} | |
| template: ./iac/main.bicep | |
| parameters: webAppName=${{ secrets.AZURE_APP_NAME }} | |
| failOnStdErr: false | |
| - name: Download App | |
| uses: actions/download-artifact@v8 | |
| with: | |
| name: webapp | |
| path: webapp | |
| - name: 'Run Azure webapp deploy action using publish profile credentials' | |
| uses: azure/webapps-deploy@v3 | |
| with: | |
| app-name: ${{ steps.deploy.outputs.webAppName }} # Replace with your app name | |
| package: 'webapp' |