forked from Azure-Samples/dotnetcore-sqldb-ghactions
-
Notifications
You must be signed in to change notification settings - Fork 0
87 lines (73 loc) · 3.79 KB
/
workflow.yml
File metadata and controls
87 lines (73 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
name: Build and deploy app
on:
push
# CONFIGURATION
# For help, go to https://github.com/Azure/Actions
#
# 1. Set up the following secrets in your repository:
# AZURE_WEBAPP_PUBLISH_PROFILE
#
# 2. Change these variables for your configuration:
env:
AZURE_WEBAPP_NAME: app-azcl-webappsql-gh-actions-01 # set this to your application's name
AZURE_WEBAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
DOTNET_VERSION: '3.1' # set this to the dot net version to use
AZURE_RESOURCEGROUP_NAME: rg-azcl-webappsql-gh-actions # set this to your preferred resource group name
SQLSERVER_NAME: sql-azcl-webappsql-gh-actions-srv # set this to your preferred sql server name
DATABASE_NAME: sqldb-azcl-webappsql-gh-actions-db # set this to your preferred sql database name
SQLADMIN_LOGIN: ${{ secrets.SQLADMIN_LOGIN }} # Create a secret in your Github repo for the SQL Admin login name you want to use
SQLADMIN_PASS: ${{ secrets.SQLADMIN_PASS }} # Create a secret in your Github repo for the SQL Admin password you want to use
permissions:
id-token: write
contents: read
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
# Checkout the repo
- uses: actions/checkout@master
# Setup .NET Core SDK
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
# Run dotnet build and publish
- name: dotnet build and publish
run: |
dotnet build --configuration Release
dotnet publish -c Release -o myapp
# Deploy to Azure Web apps staging slot
- name: 'Run Azure webapp deploy action using publish profile credentials'
uses: azure/webapps-deploy@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }} # Replace with your app name
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} # Define secret variable in repository settings as per action documentation
package: '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/myapp'
slot-name: staging
# - name: Login for az cli commands
# uses: azure/login@v1
# with:
# creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Azure Login with Federated Identity
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: create db connection string
run: |
CONN_STR=$(az sql db show-connection-string --client ado.net --server ${{ env.SQLSERVER_NAME }} --name ${{ env.DATABASE_NAME }} -o tsv)
CONN_STR=$(echo $CONN_STR | sed "s/<username>/${{ env.SQLADMIN_LOGIN }}/g")
CONN_STR=$(echo $CONN_STR | sed "s/<password>/${{ env.SQLADMIN_PASS }}/g")
echo "SQL_DB_CONN_STR=$CONN_STR" >> $GITHUB_ENV
- name: Update Database
run: |
dotnet tool install --global dotnet-ef --version 3.1.3
dotnet ef database update
env:
ConnectionStrings__MyDbConnection: ${{ env.SQL_DB_CONN_STR }}
- name: Swap to production slot
run: |
az webapp deployment slot swap --resource-group ${{ env.AZURE_RESOURCEGROUP_NAME }} --name ${{ env.AZURE_WEBAPP_NAME }} --slot staging --target-slot production
echo "Swap finished. App Service Application URL: https://$(az webapp show --resource-group ${{ env.AZURE_RESOURCEGROUP_NAME }} --name ${{ env.AZURE_WEBAPP_NAME }} --query hostNames[0] -o tsv)"
# For more samples to get started with GitHub Action workflows to deploy to Azure, refer to https://github.com/Azure/actions-workflow-samples