Skip to content

Build and Deploy

Build and Deploy #497

name: Build and Deploy
on:
push:
branches:
- main
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
env:
AZURE_WEBAPP_NAME: cashtrack-demo
AZURE_WEBAPP_PACKAGE_PATH: ./published
CONFIGURATION: Release
DOTNET_CORE_VERSION: 8.0.x
WORKING_DIRECTORY: ./src
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_CORE_VERSION }}
- name: Check out ct-data
uses: actions/checkout@v3
with:
repository: mitchellscot/ct-data
token: ${{ secrets.CHECKOUT_CT_DATA_TOKEN }}
path: ./ct-data
- name: Copy Appsettings.Production.json
run: cp ./ct-data/appsettings.Production.json ./src/appsettings.Production.json
- name: Copy Appsettings.json
run: cp ./ct-data/appsettings.json ./src/appsettings.json
- name: Add Variables To Appsettings Files
uses: microsoft/variable-substitution@v1
with:
files: ./src/appsettings.Production.json, ./src/appsettings.json
env:
AppSettings.Secret: ${{ secrets.SECRET }}
AppSettings.ConnectionStrings.Development: ${{ secrets.CONNECTION_STRING }}
AppSettings.ConnectionStrings.Test: ${{ secrets.CONNECTION_STRING }}
- name: Restore
run: dotnet restore "${{ env.WORKING_DIRECTORY }}"
- name: Build
run: dotnet build "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-restore
- name: Prepare DB
shell: pwsh
run: . ./Prod-Db.ps1
env:
ASPNETCORE_ENVIRONMENT: Production
- name: Publish
run: dotnet publish "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-build --output "${{ env.AZURE_WEBAPP_PACKAGE_PATH }}"
- name: Copy Database to Publish folder
run: cp ./src/cashtrack.db ./published/cashtrack.db
- name: Publish Artifacts
uses: actions/upload-artifact@v3
with:
name: webapp
path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
deploy:
runs-on: ubuntu-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 }}
publish-profile: ${{ secrets.cashtrack_demo_7CC9 }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}