-
Notifications
You must be signed in to change notification settings - Fork 0
197 lines (163 loc) · 5.59 KB
/
pr.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
name: Pull request build
on:
pull_request:
merge_group:
permissions:
checks: write
deployments: write
packages: write
pull-requests: write
id-token: write
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: extractions/setup-just@v2
- name: Install tools
run: just install-tools
- name: Lint
run: |
git fetch origin main --quiet --depth=1
CHANGED_FILES=$(git diff --name-only origin/main $GITHUB_SHA | { grep -oP '^TeachingRecordSystem\/\K.*\.cs(proj)?$' || true; })
if [ "$CHANGED_FILES" == "" ]; then
echo "::notice::No changes to lint"
exit 0
fi
# If project files have changed then dependencies may have been updated, which may effect lint results (e.g. namespace imports);
# lint everything.
if [ $(echo "$CHANGED_FILES" | grep -c '\.csproj$') -gt 0 ]; then
INCLUDE_ARG=""
echo "::notice::Linting entire codebase"
else
INCLUDE_ARG="--include $(echo "$CHANGED_FILES" | grep '\.cs$' | tr '\n' ' ')"
echo "::notice::Linting changed files only"
fi
dotnet dotnet-format --verify-no-changes $INCLUDE_ARG
working-directory: TeachingRecordSystem
validate_terraform:
name: Validate Terraform
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.5.0
- name: Check formatting
run: terraform fmt -check -diff
working-directory: terraform/aks
- name: Download terraform modules
run: make ci dev vendor-modules
- name: Validate
run: |
terraform init -backend=false
terraform validate -no-color
working-directory: terraform/aks
- name: Lint
uses: reviewdog/action-tflint@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
tflint_rulesets: azurerm
working_directory: terraform/aks
continue-on-error: true # temporary- we're getting sporadic 503 errors here in action setup
tests:
name: Tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
project:
[
TeachingRecordSystem.Core.Tests,
TeachingRecordSystem.Api.Tests,
TeachingRecordSystem.SupportUi.Tests,
TeachingRecordSystem.AuthorizeAccess.Tests,
TeachingRecordSystem.SupportUi.EndToEndTests,
TeachingRecordSystem.AuthorizeAccess.EndToEndTests,
TeachingRecordSystem.WebCommon.Tests,
]
services:
postgres:
image: postgres:15
env:
POSTGRES_PASSWORD: trs
POSTGRES_DB: trs
options: >-
--name postgres
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Set postgres wal_level to logical
run: |
docker exec -i postgres bash << EOF
echo "wal_level = logical" >> /var/lib/postgresql/data/postgresql.conf
EOF
docker restart --time 0 postgres
- uses: actions/checkout@v4
- uses: extractions/setup-just@v2
- name: Install tools
run: just install-tools
- name: Restore cached packages
id: cache-packages-restore
uses: actions/cache/restore@v4
with:
path: |
~/.nuget/packages
~/.local/share/.librarymanager/cache
key: ${{ hashFiles('**/packages.lock.json', '**/libman.json') }}
- name: Restore
run: just restore
- name: Cache restored packages
id: cache-packages-save
uses: actions/cache/save@v4
with:
path: |
~/.nuget/packages
~/.local/share/.librarymanager/cache
key: ${{ steps.cache-packages-restore.outputs.cache-primary-key }}
if: steps.cache-packages-restore.outputs.cache-hit != 'true'
- name: Build project
run: dotnet build -c Release --no-restore
working-directory: TeachingRecordSystem/tests/${{ matrix.project }}
- name: Install Playwright if required
run: |
if [[ "$PROJECT_NAME" =~ .*EndToEndTests ]]; then
pwsh ./bin/Release/net8.0/playwright.ps1 install chromium
fi
working-directory: TeachingRecordSystem/tests/${{ matrix.project }}
env:
PROJECT_NAME: ${{ matrix.project }}
- name: Run tests
uses: ./.github/workflows/actions/test
with:
test_project_path: TeachingRecordSystem/tests/${{ matrix.project }}
report_name: "${{ matrix.project }} test results"
dotnet_test_args: >-
--no-build
-e ConnectionStrings__DefaultConnection="Host=localhost;Username=postgres;Password=trs;Database=trs"
timeout-minutes: 15
package:
name: Package application
uses: ./.github/workflows/package.yml
secrets: inherit
deploy_dev:
name: Deploy dev environment
runs-on: ubuntu-latest
needs: [lint, validate_terraform, tests, package]
environment: dev
concurrency: deploy_dev
steps:
- uses: actions/checkout@v4
- uses: ./.github/workflows/actions/deploy-aks-environment
id: deploy
with:
environment_name: dev
docker_image: ${{ needs.package.outputs.docker_image }}
azure_credentials: ${{ secrets.AZURE_CREDENTIALS }}