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 .NET Core application to Web App MealMaster with API Management Service MealMasterapi-MealMaster | |
on: | |
push: | |
branches: | |
- production | |
env: | |
AZURE_WEBAPP_NAME: MealMaster | |
AZURE_WEBAPP_PACKAGE_PATH: .\publish | |
AZURE_APIM_RESOURCE_PATH: / | |
AZURE_APIM_RESOURCEGROUP: Mealmaster | |
AZURE_APIM_SERVICENAME: MealMasterapi | |
AZURE_APIM_API_ID: MealMaster | |
AZURE_APIM_APPSERVICEURL: https://mealmaster.azurewebsites.net | |
SWASHBUCLE_ASPNET_CORE_CLI_PACKAGE_VERSION: 5.6.3 | |
SWASHBUCKLE_DOTNET_CORE_VERSION: 3.1.x | |
API_IMPORT_SPECIFICATION_PATH: .\publish\swagger.json | |
API_IMPORT_DLL: .\bin\Release\net8.0\CookingApp.dll | |
API_IMPORT_VERSION: v1 | |
CONFIGURATION: Release | |
DOTNET_CORE_VERSION: 8.0.x | |
WORKING_DIRECTORY: ./src/server/CookingApp | |
jobs: | |
build: | |
runs-on: windows-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup .NET SDK | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: ${{ env.DOTNET_CORE_VERSION }} | |
- name: Setup SwashBuckle .NET Core | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: ${{ env.SWASHBUCKLE_DOTNET_CORE_VERSION }} | |
- name: Restore | |
run: dotnet restore ${{ env.WORKING_DIRECTORY }}/CookingApp.sln | |
- name: Build | |
run: dotnet build ${{ env.WORKING_DIRECTORY }}/CookingApp.sln --configuration ${{ env.CONFIGURATION }} --no-restore | |
- name: Test | |
run: dotnet test ${{ env.WORKING_DIRECTORY }}/CookingApp.sln --no-build | |
- name: Publish | |
run: dotnet publish ${{ env.WORKING_DIRECTORY }}/CookingApp.sln --configuration ${{ env.CONFIGURATION }} --no-build --output ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} | |
- name: Install Swashbuckle CLI .NET Global Tool | |
run: dotnet tool install --global Swashbuckle.AspNetCore.Cli --version ${{ env.SWASHBUCLE_ASPNET_CORE_CLI_PACKAGE_VERSION }} | |
working-directory: ${{ env.WORKING_DIRECTORY }} | |
- name: Generate Open API Specification Document | |
run: swagger tofile --output "${{ env.API_IMPORT_SPECIFICATION_PATH }}" "${{ env.API_IMPORT_DLL }}" "${{ env.API_IMPORT_VERSION }}" | |
- name: Publish Artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: webapp | |
path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} | |
deploy: | |
runs-on: windows-latest | |
needs: build | |
steps: | |
- name: Download artifact from build job | |
uses: actions/download-artifact@v3 | |
with: | |
name: webapp | |
path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} | |
- name: Deploy to Azure WebApp | |
uses: azure/webapps-deploy@v2 | |
with: | |
app-name: ${{ env.AZURE_WEBAPP_NAME }} | |
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} | |
publish-profile: ${{ secrets.MealMaster_C09E }} | |
- name: Azure Login | |
uses: azure/login@v1 | |
with: | |
creds: ${{ secrets.MealMasterapi_SPN }} | |
- name: Import API into Azure API Management | |
run: az apim api import --path "${{ env.AZURE_APIM_RESOURCE_PATH }}" --resource-group "${{ env.AZURE_APIM_RESOURCEGROUP }}" --service-name "${{ env.AZURE_APIM_SERVICENAME }}" --api-id "${{ env.AZURE_APIM_API_ID }}" --service-url "${{ env.AZURE_APIM_APPSERVICEURL }}" --specification-path "${{ env.API_IMPORT_SPECIFICATION_PATH }}" --specification-format OpenApi --subscription-required false | |
- name: logout | |
run: > | |
az logout |