116 lines (109 loc) · 3.36 KB
/
dotnetcore.yml
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
name: .NET Core
on:
push:
branches:
- master
paths:
- 'apis/poi/**'
- '.github/workflows/dotnetcore.yml'
pull_request:
branches: [ master ]
paths:
- 'apis/poi/**'
env:
working_directory: apis/poi/web
repo: devopsoh/api-poi
acr: openhackq811qdi1acr.azurecr.io
appname: openhackq811qdi1poi
staging-slot: staging
staging-url: https://openhackq811qdi1poi-staging.azurewebsites.net/
prod-slot: production
resource_group: openhackq811qdi1rg
jobs:
test:
defaults:
run:
working-directory: ${{ env.working_directory }}
name: POI API Unit Test
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.101
- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Test
run: dotnet test --no-restore --verbosity normal
working-directory: apis/poi/tests/UnitTests
build:
name: poi api docker build
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
#needs: test ##used for action development
steps:
- uses: actions/checkout@v2
- name: docker build and push
uses: docker/build-push-action@v1.1.0
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: ${{ env.repo }}
registry: ${{ env.acr }}
dockerfile: ${{ env.working_directory }}/Dockerfile
path: ${{ env.working_directory }}
tag_with_ref: false
tag_with_sha: true
tags: ${{ github.run_number }}
deploy:
name: POI API Deployment
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
needs: build
steps:
- uses: actions/checkout@v2
- name: Get short SHA
run: echo "::set-env name=short_sha::$(git rev-parse --short=7 HEAD)"
- name: "Login via Azure CLI"
uses: azure/login@v1.1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- uses: azure/webapps-deploy@v2
with:
app-name: "${{ env.appname }}"
images: "${{ env.acr }}/${{ env.repo }}:${{ github.run_number }}"
slot-name: ${{ env.staging-slot }}
check-staging:
name: Check staging
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
needs: deploy
continue-on-error: true
steps:
- name: URL Health Check
uses: Jtalk/url-health-check-action@v1.3
with:
url: ${{ env.staging-url }}api/healthcheck/poi
max-attempts: 10
retry-delay: 10s
swap-slots:
name: Swap slots
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
needs: check-staging
steps:
- name: "Login via Azure CLI"
uses: azure/login@v1.1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: swap slots
run: |
az webapp deployment slot swap \
-g ${{ env.resource_group }} \
-n ${{ env.appname }} \
--slot ${{ env.staging-slot }} \
--target-slot ${{ env.prod-slot }}