This repository has been archived by the owner on Aug 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
117 lines (93 loc) · 3.18 KB
/
build_release.yaml
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
name: Build and Release
on:
# Enable manual trigger
workflow_dispatch:
# Triggers on push to the following paths
push:
branches:
- main
paths:
# Any change to code, infra as code and configuration
- "deploy/**"
- "services/**"
# Changes to the workflow
- ".github/workflows/build_release.yaml"
env:
PROJECT_PATH: './services/webapi/src/webapi.csproj'
TEST_PATH: './services/webapi/tests/'
OUTPUT_PATH: './output/webapi/'
jobs:
# Build and tests the webapi
build_webapi:
name: "Build WebAPI"
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.404
- name: Build
run: dotnet build ${{ env.PROJECT_PATH }}
- name: Test
run: dotnet test ${{ env.TEST_PATH }}
- name: Publish
run: dotnet publish --no-build --output ${{ env.OUTPUT_PATH }} ${{ env.PROJECT_PATH }}
- name: Package webapi
run: (cd ${{ env.OUTPUT_PATH }} && zip -r ../../webapi.zip .)
- name: Upload application zip package
uses: actions/upload-artifact@v2
with:
name: webapi
path: ./webapi.zip
retention-days: 7
validate_bicep:
name: "Validate Bicep files"
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v2
- name: Validate that bicep builds
run: |
az bicep build -f main.bicep
az bicep build -f webapi/dbrestore.bicep
working-directory: ./deploy/infra
deploy:
name: 'Deploy'
needs: [validate_bicep, build_webapi]
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v2
- name: Install yq to parse yaml file
run: |
sudo wget -O /usr/local/bin/yq https://github.com/mikefarah/yq/releases/download/v4.5.0/yq_linux_amd64
sudo chmod +x /usr/local/bin/yq
- name: Parse config.yaml as output to GitHub Actions matrix
run: |
echo "config=$(yq e ./deploy/config.yaml -j -I=0)" >> $GITHUB_ENV
- name: Write deployment information to log
run: |
echo "Deploying to ${{fromJson(env.config).AZURE_LOCATION }} with name prefix ${{fromJson(env.config).ENVIRONMENT_TAG }}"
- name: Download application artifacts
uses: actions/download-artifact@v2
with:
path: ./output
- name: Login to Azure
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Set Azure subscription
run: |
az account set --subscription $(jq -r '.subscriptionId' <<< $CREDS)
env:
CREDS: ${{ secrets.AZURE_CREDENTIALS }}
- name: Run installation script to deploy
run: >
deploy/scripts/install.sh
--resource-name-prefix "${{fromJson(env.config).RESOURCE_NAME_PREFIX }}"
--environment-tag "${{fromJson(env.config).ENVIRONMENT_TAG }}"
--location "${{fromJson(env.config).AZURE_LOCATION }}"
--resource-group-tag "$GITHUB_REPOSITORY"
--no-build