Skip to content

Merge pull request #34 from eduardo-paes:development #61

Merge pull request #34 from eduardo-paes:development

Merge pull request #34 from eduardo-paes:development #61

name: Deploy WebAPI to Azure
env:
AZURE_WEBAPP_NAME: ${{ secrets.AZURE_WEBAPP_NAME }}
AZURE_WEBAPP_PACKAGE_PATH: "."
DOTNET_VERSION: "7.0"
PROJECT_PATH: "src/Infrastructure/WebAPI/WebAPI.csproj"
WEBAPI_PATH: "src/Infrastructure/WebAPI/"
UNIT_TESTS_PROJ: "src/Domain.Tests/Domain.Tests.csproj"
INTEGRATION_TESTS_PROJ: "src/Application.Tests/Application.Tests.csproj"
ASPNETCORE_ENVIRONMENT: ${{ secrets.ASPNETCORE_ENVIRONMENT }}
on:
push:
branches: ["staging"]
workflow_dispatch:
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
environment: STAGING
steps:
- uses: actions/checkout@v3
- name: Set up .NET Core
uses: actions/setup-dotnet@v2
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Set up dependency caching for faster builds
uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Create env
run: |
echo "AZURE_BLOB_STORAGE_CONNECTION_STRING=${{ secrets.AZURE_BLOB_STORAGE_CONNECTION_STRING }}
AZURE_BLOB_STORAGE_CONTAINER_NAME=${{ secrets.AZURE_BLOB_STORAGE_CONTAINER_NAME }}
POSTGRES_CONNECTION_STRING=${{ secrets.POSTGRES_CONNECTION_STRING }}
FRONTEND_URL=${{ secrets.FRONTEND_URL }}
ALLOW_ORIGINS=${{ secrets.ALLOW_ORIGINS }}
JWT_AUDIENCE=${{ secrets.JWT_AUDIENCE }}
JWT_EXPIRE_IN=${{ secrets.JWT_EXPIRE_IN }}
JWT_ISSUER=${{ secrets.JWT_ISSUER }}
JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }}
SEQ_API_KEY=${{ secrets.SEQ_API_KEY }}
SEQ_URL=${{ secrets.SEQ_URL }}
SMTP_EMAIL_PASSWORD=${{ secrets.SMTP_EMAIL_PASSWORD }}
SMTP_EMAIL_USERNAME=${{ secrets.SMTP_EMAIL_USERNAME }}
EXECUTE_MIGRATION=${{ secrets.EXECUTE_MIGRATION }}" > src/Infrastructure/WebAPI/.env
- name: Set environment variable
run: echo "ASPNETCORE_ENVIRONMENT=${{ env.ASPNETCORE_ENVIRONMENT }}" >> $GITHUB_ENV
- name: Build with dotnet
run: dotnet build ${{env.PROJECT_PATH}} --configuration Release -o ${{env.DOTNET_ROOT}}/dist
- name: Dotnet publish
run: dotnet publish ${{env.PROJECT_PATH}} -c Release -o ${{env.DOTNET_ROOT}}/myapp
- name: Copy XML documentation file
run: cp ${{env.DOTNET_ROOT}}/dist/*.xml ${{env.DOTNET_ROOT}}/myapp/
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v3
with:
name: .net-app
path: ${{env.DOTNET_ROOT}}/myapp
test:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up .NET Core
uses: actions/setup-dotnet@v2
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Run Unit Tests
run: dotnet test ${{ env.UNIT_TESTS_PROJ }} --configuration Release
- name: Run Integration Tests
run: dotnet test ${{ env.INTEGRATION_TESTS_PROJ }} --configuration Release
deploy:
permissions:
contents: none
runs-on: ubuntu-latest
needs: test
environment:
name: STAGING
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
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: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}