101 lines (90 loc) · 3.5 KB
/
prod-build-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
name: .NET Core-Build and Test
env:
registry: openhackacr.azurecr.io
repository: devopsoh/api-poi
docker_path: apis/poi/web
webapp_name: openhkweb-dotnet
build_name: POI
on:
push:
branches: [ master ]
paths: [apis/poi/**,.github/workflows/prod-build-dotnetcore.yml]
pull_request:
branches: [ master ]
paths: [apis/poi/**,.github/workflows/prod-build-dotnetcore.yml]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 2.1.301
- name: Install dependencies
run: dotnet restore ./apis/poi/poi.sln
- name: Build
run: dotnet build ./apis/poi/poi.sln --configuration Release --no-restore
- name: Create issue on build failure
if: ${{ failure() }}
uses: JasonEtco/create-an-issue@v2.4.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Test
run: dotnet test ./apis/poi/tests/UnitTests/UnitTests.csproj --no-restore --verbosity normal
docker_build_and_push:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v2
- name: Azure Container Registry Login
uses: Azure/docker-login@v1
with:
# Container registry username
username: ${{ secrets.ACR_USER }}
# Container registry password
password: ${{ secrets.ACR_KEY }}
# Container registry server url
login-server: https://openhackacr.azurecr.io
- 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
});
deploy_staging:
if: github.ref == 'refs/heads/master'
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 }}
images: ${{ env.registry }}/${{ env.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
});