.github/workflows/main_your-app-name.yml #6
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 ASP.Net Core app to Azure Web App - your-app-name | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read # requis pour actions/checkout | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up .NET Core | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: '8.0' | |
| - name: Restore dependencies | |
| run: dotnet restore | |
| - name: Build with dotnet | |
| run: dotnet build --configuration Release --no-restore | |
| - name: Publish app | |
| run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp | |
| - name: Upload artifact for next jobs | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: .net-app | |
| path: ${{env.DOTNET_ROOT}}/myapp | |
| test: | |
| runs-on: ubuntu-latest | |
| needs: build | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up .NET Core | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: '8.0' | |
| - name: Restore dependencies | |
| run: dotnet restore | |
| - name: Run tests | |
| run: dotnet test --configuration Release --verbosity normal | |
| deploy: | |
| runs-on: ubuntu-latest | |
| if: ${{ false }} # ce job ne s'exécutera jamais | |
| needs: [build, test] # Ne s’exécute que si build et test réussissent | |
| environment: | |
| name: 'Production' | |
| url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} | |
| steps: | |
| - name: Download artifact from build job | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: .net-app | |
| - name: Deploy to Azure Web App | |
| id: deploy-to-webapp | |
| uses: azure/webapps-deploy@v3 | |
| with: | |
| app-name: 'your-app-name' | |
| slot-name: 'Production' | |
| package: . | |
| publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_4BB9B797473748639415218DA8C649AD }} | |