This repository has been archived by the owner on Feb 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
229 lines (199 loc) · 6.4 KB
/
ci.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
name: Rat API - CI/CD
on:
push:
branches: [ branch0 ]
paths-ignore:
- 'src/Rat.Database/**'
- '.github/workflows/sqlserver.yml'
- '.github/workflows/redoc.yml'
- make.sh
- index.html
pull_request:
branches: [ branch0 ]
paths:
- 'src/Rat.Database/**'
- '.github/workflows/sqlserver.yml'
- '.github/workflows/redoc.yml'
- make.sh
- index.html
env:
DEFAULT_BRANCH: branch0
VERSION: 0.4.0
CONTAINER_REGISTRY: ghcr.io
jobs:
build:
name: Build assemblies and run the tests
runs-on: ubuntu-latest
services:
sqlserver:
image: mcr.microsoft.com/mssql/server:2019-latest
env:
ACCEPT_EULA: Y
SA_PASSWORD: Password1!
ports:
- 1433:1433
steps:
- name: Setup .NET Core SDK
id: install-dotnet-6xx
uses: actions/setup-dotnet@v1.8.1
with:
dotnet-version: '6.0.x'
include-prerelease: false
- name: Install tools
id: install-dotnet-tools
run: |
dotnet tool install -g Swashbuckle.AspNetCore.Cli --version 6.3.1
- name: Checkout
id: git-checkhot
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup CodeQL
id: codeql-setup
uses: github/codeql-action/init@v1
with:
languages: 'csharp'
- name: Restore nuget packages
id: dotnet-restore
run: dotnet restore ./src/Rat.sln
- name: Build
id: dotnet-build
run: dotnet build ./src/Rat.sln --configuration Release --no-restore
# Disable test until DB creation step is added
#- name: Test
# id: dotnet-test
# env:
# DATABASE_PROJECT_PATH: ${{ github.workspace }}
# run: dotnet test ./src/Rat.sln --configuration Release --no-build --collect:"XPlat Code Coverage" --settings ./src/Rat.Api.Test/runsettings.xml
- name: Run CodeQL Analysis
id: codeql-run
uses: github/codeql-action/analyze@v2
- name: Publish built binaries
id: dotnet-publish
run: dotnet publish ./src/Rat.Api/Rat.Api.csproj -o ./published
- name: Upload publish result
id: artifacts-upload
uses: actions/upload-artifact@v2
with:
name: 'published-artifact'
path: published
docker:
name: Build and push Docker image
needs: build
runs-on: ubuntu-latest
outputs:
dockerTag: ${{ env.DOCKER_TAG }}
steps:
- name: Checkout
id: git-checkhot
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Download published artifact
id: artifacts-download
uses: actions/download-artifact@v2
with:
name: 'published-artifact'
path: ./published
- name: Setup Docker Buildx
id: docker-buildx
uses: docker/setup-buildx-action@v1
with:
buildkitd-flags: --debug
- name: Log in to the Container registry
uses: docker/login-action@v1.14.1
with:
registry: ${{ env.CONTAINER_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.CONTAINER_REGISTRY_PAT }}
- name: Prepare docker tag
id: docker-prepareTags
run: |
if [[ $GITHUB_REF != 'refs/heads/${{ env.DEFAULT_BRANCH }}' ]]
then
echo "DOCKER_TAG=$(echo $VERSION-$GITHUB_RUN_ID)" >> $GITHUB_ENV
else
echo "DOCKER_TAG=$VERSION" >> $GITHUB_ENV
fi
- name: Docker tag
id: docker-printTag
run: echo "Docker tag ${{ env.DOCKER_TAG }}"
- name: Set docker image metadata
id: docker-metadata
uses: docker/metadata-action@v3
with:
images: ${{ env.CONTAINER_REGISTRY }}/${{ github.repository }}
tags: type=semver,pattern={{version}},value=${{ env.DOCKER_TAG }}
- name: Docker build and publish
id: docker-buildAndPublish
uses: docker/build-push-action@v2.10.0
with:
context: .
file: ./src/Rat.Api/Dockerfile
build-args: PUBLISH_RESULT_PATH=published
push: true
tags: ${{ steps.docker-metadata.outputs.tags }}
- name: Print published docker image tags
id: print-docker-image-tags
run: echo '${{ steps.docker-metadata.outputs.tags }}'
azure:
name: Deploy to Azure
needs: Docker
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
steps:
- name: 'Deploy container to Azure'
id: azure-deployContainer
uses: azure/webapps-deploy@v2
with:
app-name: rattus
publish-profile: ${{ secrets.RAT_AZURE_PUBLISH_PROFILE }}
images: '${{ env.CONTAINER_REGISTRY }}/${{ github.repository }}:${{needs.docker.outputs.dockerTag}}'
- name: Login to Azure
id: azure-loging
uses: azure/login@v1
with:
creds: '${{ secrets.RATCAT_AZURE_CREDENTIALS }}'
- name: Deploy environment configurations for Azure Web App
id: azure-deployAppSettings
uses: azure/appservice-settings@v1
with:
app-name: 'rattus'
app-settings-json: |
[
{
"name": "ASPNETCORE_ENVIRONMENT",
"value": "Production",
"slotSetting": false
},
{
"name": "DOCKER_REGISTRY_SERVER_URL",
"value": "https://index.docker.io/v1",
"slotSetting": false
},
{
"name": "WEBSITE_HEALTHCHECK_MAXPINGFAILURES",
"value": "2",
"slotSetting": false
},
{
"name": "WEBSITE_HTTPLOGGING_RETENTION_DAYS",
"value": "7",
"slotSetting": false
},
{
"name": "WEBSITES_ENABLE_APP_SERVICE_STORAGE",
"value": "false",
"slotSetting": false
},
{
"name": "DOCKER_IMAGE_TAG",
"value": "${{ needs.docker.outputs.dockerTag }}",
"slotSetting": false
},
{
"name": "SqlConnectionFactoryOptions__ConnectionString",
"value": "${{ secrets.RAT_DATABASE_CONNECTION_STRING }}",
"slotSettings": false
}
]