|
| 1 | +# This workflow will build and push a .NET Core app to an Azure Web App when a commit is pushed to your default branch. |
| 2 | +# |
| 3 | +# This workflow assumes you have already created the target Azure App Service web app. |
| 4 | +# For instructions see https://docs.microsoft.com/en-us/azure/app-service/quickstart-dotnetcore?tabs=net60&pivots=development-environment-vscode |
| 5 | +# |
| 6 | +# To configure this workflow: |
| 7 | +# |
| 8 | +# 1. Download the Publish Profile for your Azure Web App. You can download this file from the Overview page of your Web App in the Azure Portal. |
| 9 | +# For more information: https://docs.microsoft.com/en-us/azure/app-service/deploy-github-actions?tabs=applevel#generate-deployment-credentials |
| 10 | +# |
| 11 | +# 2. Create a secret in your repository named AZURE_WEBAPP_PUBLISH_PROFILE, paste the publish profile contents as the value of the secret. |
| 12 | +# For instructions on obtaining the publish profile see: https://docs.microsoft.com/azure/app-service/deploy-github-actions#configure-the-github-secret |
| 13 | +# |
| 14 | +# 3. Change the value for the AZURE_WEBAPP_NAME. Optionally, change the AZURE_WEBAPP_PACKAGE_PATH and DOTNET_VERSION environment variables below. |
| 15 | +# |
| 16 | +# For more information on GitHub Actions for Azure: https://github.com/Azure/Actions |
| 17 | +# For more information on the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy |
| 18 | +# For more samples to get started with GitHub Action workflows to deploy to Azure: https://github.com/Azure/actions-workflow-samples |
| 19 | + |
| 20 | +name: Build and deploy ASP.Net Core app to an Azure Web App |
| 21 | + |
| 22 | +env: |
| 23 | + AZURE_WEBAPP_NAME: github-actions-workflow # set this to the name of your Azure Web App |
| 24 | + AZURE_WEBAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root |
| 25 | + DOTNET_VERSION: '6.0.x' # set this to the .NET Core version to use |
| 26 | + |
| 27 | +on: |
| 28 | + push: |
| 29 | + branches: none |
| 30 | + workflow_dispatch: |
| 31 | + |
| 32 | +permissions: |
| 33 | + contents: read |
| 34 | + |
| 35 | +jobs: |
| 36 | + build: |
| 37 | + runs-on: ubuntu-latest |
| 38 | + |
| 39 | + steps: |
| 40 | + - uses: actions/checkout@v4 |
| 41 | + |
| 42 | + - name: Set up .NET Core |
| 43 | + uses: actions/setup-dotnet@v2 |
| 44 | + with: |
| 45 | + dotnet-version: ${{ env.DOTNET_VERSION }} |
| 46 | + |
| 47 | + - name: Set up dependency caching for faster builds |
| 48 | + uses: actions/cache@v3 |
| 49 | + with: |
| 50 | + path: ~/.nuget/packages |
| 51 | + key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} |
| 52 | + restore-keys: | |
| 53 | + ${{ runner.os }}-nuget- |
| 54 | +
|
| 55 | + - name: Build with dotnet |
| 56 | + run: dotnet build --configuration Release |
| 57 | + |
| 58 | + - name: dotnet publish |
| 59 | + run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp |
| 60 | + |
| 61 | + - name: Upload artifact for deployment job |
| 62 | + uses: actions/upload-artifact@v3 |
| 63 | + with: |
| 64 | + name: .net-app |
| 65 | + path: ${{env.DOTNET_ROOT}}/myapp |
| 66 | + |
| 67 | + deploy: |
| 68 | + permissions: |
| 69 | + contents: none |
| 70 | + runs-on: ubuntu-latest |
| 71 | + needs: build |
| 72 | + environment: |
| 73 | + name: 'Development' |
| 74 | + url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} |
| 75 | + |
| 76 | + steps: |
| 77 | + - name: Download artifact from build job |
| 78 | + uses: actions/download-artifact@v3 |
| 79 | + with: |
| 80 | + name: .net-app |
| 81 | + |
| 82 | + - name: Deploy to Azure Web App |
| 83 | + id: deploy-to-webapp |
| 84 | + uses: azure/webapps-deploy@v2 |
| 85 | + with: |
| 86 | + app-name: ${{ env.AZURE_WEBAPP_NAME }} |
| 87 | + publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} |
| 88 | + package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} |
0 commit comments