Build, Test and Deploy ASP.Net Core app #5
This file contains 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 and deploy ASP.Net Core app to Azure Web App | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- 'NewsApi/**' # Only trigger on changes to NewsApi folder | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up .NET Core | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: '8.0.x' | |
- name: Build with dotnet | |
working-directory: ./NewsApi # Specify working directory | |
run: dotnet build --configuration Release | |
- name: dotnet publish | |
working-directory: ./NewsApi # Specify working directory | |
run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp | |
- name: Upload artifact | |
uses: actions/upload-artifact@v3 | |
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 }} | |
steps: | |
- name: Download artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: .net-app | |
- name: Deploy to Azure Web App | |
id: deploy-to-webapp | |
uses: azure/webapps-deploy@v2 | |
with: | |
app-name: 'ntnewsapi' | |
publish-profile: ${{ secrets.AZUREWEBAPP_PUBLISHPROFILE }} | |
package: . |