This repository has been archived by the owner on Jan 22, 2024. It is now read-only.
119 lines (101 loc) · 4.22 KB
/
ch4-build-deploy-poi.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
117
118
119
name: POI CICD - Ch4-BuildAndDeploy
# Variables used in the jobs
env:
registry: openhackflo1xyl7acr.azurecr.io
repository: devopsoh/api-poi
docker_path: apis/poi/web
webapp_name: openhackflo1xyl7poi
# If you want to trigger this branch then change the branch name to a usable branch name
on:
push:
branches: [ REPLACE-WITH-MASTER-BRANCH-NAME ]
paths:
- apis/poi/**
- .github/workflows/ch4-build-deploy-poi.yml
pull_request:
branches: [ REPLACE-WITH-MASTER-BRANCH-NAME ]
paths:
- apis/poi/**
- .github/workflows/ch4-build-deploy-poi.yml
jobs:
# CI Phase - BUILD AND TEST CODE CHANGES
build_and_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
# If you want to specify a specific DOTNET version you may uncomment this line. It is not needed.
#with:
# dotnet-version: '3.1.202'
- name: Add Code Coverage Tools
working-directory: apis/poi/tests/UnitTests
run: dotnet add package coverlet.msbuild
- name: Install dependencies
run: dotnet restore apis/poi/web/*.csproj
- name: .NET Build Web
run: dotnet build --configuration Release --no-restore apis/poi/web/*.csproj
- name: .NET Build Unit Tests
run: dotnet build --configuration Release apis/poi/tests/UnitTests/UnitTests.csproj
- name: .NET Test
run: dotnet test --no-restore --verbosity normal apis/poi/tests/UnitTests /p:CollectCoverage=true /p:CoverletOutput=lcov/ /p:CoverletOutputFormat=lcov
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: apis/poi/tests/UnitTests/lcov/coverage.info
base-path: apis/poi
flag-name: Unit
- uses: actions/github-script@0.9.0
if: failure()
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
let body = "${{ env.build_name }} Worflow Failure \n Build Number: ${{ github.run_number }} \n Build Log: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} \n SHA: [${{ github.sha }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) \n";
github.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: "${{ env.build_name }} Workflow ${{ github.run_number }} Failed! ",
body: body
});
# CD Phase 2 - 1 - PUSH TO ACR
docker_build_and_push:
if: github.ref == 'refs/heads/openhack_refresh'
runs-on: ubuntu-latest
needs: build_and_test
steps:
- uses: actions/checkout@v2
- name: Docker login
run: docker login $registry -u ${{ secrets.ACR_USER }} -p ${{ secrets.ACR_KEY }}
- name: Docker build
run: docker build -t $registry/$repository:${{github.run_number}} --build-arg build_version=${{github.run_number}} $docker_path
- name: Docker Push
run: docker push $registry/$repository:${{github.run_number}}
- uses: actions/github-script@0.9.0
if: failure()
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
let body = "${{ env.build_name }} Worflow Failure \n Build Number: ${{ github.run_number }} \n Build Log: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} \n SHA: [${{ github.sha }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) \n";
github.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: "${{ env.build_name }} Workflow ${{ github.run_number }} Failed! ",
body: body
});
# CD Phase 2 - 2 - PUSH NEW CODE FROM ACR TO WEBAPP STAGING SLOT
deploy_staging:
if: github.ref == 'refs/heads/openhack_refresh'
runs-on: ubuntu-latest
needs: docker_build_and_push
steps:
- name: Azure authentication
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Azure WebApp
uses: Azure/webapps-deploy@v2
with:
app-name: ${{ env.webapp_name }}
slot-name: staging
images: ${{ env.registry }}/${{ env.repository }}:${{github.run_number}}