-
Notifications
You must be signed in to change notification settings - Fork 99
247 lines (206 loc) · 7.97 KB
/
1-pr.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
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
name: 1-PR checks
on:
pull_request:
branches: [ dev, main ]
workflow_dispatch:
env:
# web app
DOCKERFILE_PATH: "CarbonAware.WebApi/src/Dockerfile"
HEALTH_ENDPOINT: "0.0.0.0:8080/health"
DLL_FILE_PATH: "./bin/Release/net6.0/CarbonAware.WebApi.dll"
DOTNET_SRC_DIR: "./src"
# console app packages
DOTNET_SOLUTION: "src/CarbonAwareSDK.sln"
OUTPUT_DIR: "packages"
CONSOLE_APP: "samples/lib-integration/ConsoleApp/ConsoleApp.csproj"
CREATE_PKGS: "scripts/package/create_packages.ps1"
ADD_PKGS: "scripts/package/add_packages.ps1"
jobs:
sln-build-and-test:
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ 'csharp' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support
defaults:
run:
working-directory: ./src
steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Unit Tests
run: dotnet test --no-build --verbosity normal
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
#- name: Autobuild
# uses: github/codeql-action/autobuild@v2
# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
#- run: |
# make bootstrap
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
webapp-container-dotnet-build:
needs: sln-build-and-test
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/dotnet/sdk:6.0
steps:
- uses: actions/checkout@v3
- name: Setup .NET Core SDK 6
uses: actions/setup-dotnet@v2
with:
dotnet-version: '6.0.x'
include-prerelease: false
- name: Install dependencies
run: dotnet restore
working-directory: ${{ env.DOTNET_SRC_DIR }}
- name: Install tools
run: dotnet tool restore
working-directory: ${{ env.DOTNET_SRC_DIR }}/CarbonAware.WebApi/src
- name: Build
run: dotnet build --configuration Release --no-restore
working-directory: ${{ env.DOTNET_SRC_DIR }}
- name: Unit Test + Code Coverage
run: dotnet test --filter TestCategory=Unit --no-restore --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=json
working-directory: ${{ env.DOTNET_SRC_DIR }}
- name: Integration Test + Code Coverage
run: dotnet test --filter TestCategory=Integration --no-restore --verbosity normal /p:CollectCoverage=true /p:MergeWith=\"./coverage.json\" /p:CoverletOutputFormat=\"json,opencover\"
working-directory: ${{ env.DOTNET_SRC_DIR }}
- name: Codecov
uses: codecov/codecov-action@v2
with:
directory: ${{ env.DOTNET_SRC_DIR }}
- name: Generate Open API
run: dotnet tool run swagger tofile --output ./wwwroot/api/v1/swagger.yaml --yaml ${{ env.DLL_FILE_PATH }} v1
working-directory: ./src/CarbonAware.WebApi/src
- name: Upload swagger artifact
uses: actions/upload-artifact@v1
with:
name: pr-swagger.yaml
path: src/CarbonAware.WebApi/src/wwwroot/api/v1/swagger.yaml
webapp-container-validation:
needs: sln-build-and-test
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Docker Target Final
run: docker build . -f ${DOCKERFILE_PATH} -t ca-api
working-directory: ./src
- name: Docker Run Container
run: |
docker run -d --name runnable-container -p 8080:80 ca-api
docker container ls
- name: Docker WGET Health Endpoint
run: |
wget -t 5 --waitretry=5 ${HEALTH_ENDPOINT}
api-comparison:
needs: webapp-container-dotnet-build
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./src/CarbonAware.WebApi/src
container:
image: mcr.microsoft.com/dotnet/sdk
steps:
- name: Checkout Dev Branch
uses: actions/checkout@v3
with:
ref: dev
- name: Setup .NET Core SDK 6
uses: actions/setup-dotnet@v2
with:
dotnet-version: '6.0.x'
include-prerelease: false
- name: Install dependencies
run: dotnet restore
working-directory: ${{ env.DOTNET_SRC_DIR }}
- name: Install tools
run: dotnet tool restore
- name: Build
run: dotnet build --configuration Release --no-restore
working-directory: ${{ env.DOTNET_SRC_DIR }}
- name: Generate Open API
run: dotnet tool run swagger tofile --output ./wwwroot/api/v1/swagger.yaml --yaml ${{ env.DLL_FILE_PATH }} v1
- name: Upload dev artifact
uses: actions/upload-artifact@v1
with:
name: dev-swagger.yaml
path: src/CarbonAware.WebApi/src/wwwroot/api/v1/swagger.yaml
- uses: actions/download-artifact@v3
with:
name: pr-swagger.yaml
path: ./src/CarbonAware.WebApi/src/wwwroot/api/v1/pr-swagger.yaml
- name: API Diff Comparison
run: |
diff ./wwwroot/api/v1/pr-swagger.yaml ./wwwroot/api/v1/swagger.yaml && echo "No API Changes detected" || echo "::warning:: API Changed"
dotnet-pack:
needs: sln-build-and-test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup .NET Core SDK 6
uses: actions/setup-dotnet@v2
with:
dotnet-version: '6.0.x'
include-prerelease: false
- name: Create packages
shell: pwsh
run: ${{ env.CREATE_PKGS }} ${{ env.DOTNET_SOLUTION }} ${{ env.OUTPUT_DIR }}
- name: Restore current packages for ConsoleApp
run: dotnet restore ${{ env.CONSOLE_APP }}
- name: Add packages to ConsoleApp
shell: pwsh
run: ${{ env.ADD_PKGS }} ${{ env.CONSOLE_APP}} ${{ env.OUTPUT_DIR }}
- name: Cat ConsoleApp project file
run: cat ${{ env.CONSOLE_APP }}
- name: Restore packages for ConsoleApp
run: dotnet restore ${{ env.CONSOLE_APP }}
- name: Build ConsoleApp
run: dotnet build ${{ env.CONSOLE_APP }}
# Non-blocking job that checks .md file locations and also lints them
markdown-linting:
runs-on: ubuntu-latest
steps:
- name: Check out the code
uses: actions/checkout@v2
# See the script for details about exceptions to this check
- name: Markdown files should be located in docs folder
continue-on-error: true
run: "scripts/markdown/check-markdown-files.sh"
- name: markdownlint-cli2-action
uses: DavidAnson/markdownlint-cli2-action@v9
continue-on-error: true
with:
command: config
globs: |
./custom.markdownlint.jsonc
{"*[^.github]/**,*"}.md