-
Notifications
You must be signed in to change notification settings - Fork 0
225 lines (189 loc) · 9.28 KB
/
pull-request-validation.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
name: Pull Request Validation
on:
workflow_dispatch:
pull_request:
branches:
- main
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
actions: read # Required by CodeQL
security-events: write # Required by CodeQL
concurrency: # This is required to prevent multiple runs of the same workflow from running at the same time.
group: ${{ github.workflow }}
jobs:
dependency-review:
runs-on: ubuntu-latest
steps:
- name: "Checkout Repository"
uses: actions/checkout@v3
- name: "Dependency Review"
uses: actions/dependency-review-action@v2
dotnet-web-ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 1.11
- name: Cache SonarCloud packages
uses: actions/cache@v1
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Install SonarCloud scanners
shell: bash
run: |
cd src
dotnet tool install --global dotnet-sonarscanner
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: "csharp"
- name: Begin SonarScanner
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
cd src
dotnet-sonarscanner begin /k:"frasermolyneux_portal-repository" /o:"frasermolyneux" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"
- uses: frasermolyneux/actions/dotnet-web-ci@main
with:
dotnet-project: "repository-webapi"
dotnet-version: 7.0.x
src-folder: "src"
majorMinorVersion: "1.1"
- name: End SonarScanner
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
cd src
dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:'csharp'"
terraform-plan-and-apply-dev:
environment: Development
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: frasermolyneux/actions/terraform-plan-and-apply@main
with:
terraform-folder: "terraform"
terraform-var-file: "tfvars/dev.tfvars"
terraform-backend-file: "backends/dev.backend.hcl"
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- id: terraform-output
shell: bash
run: |
cd terraform
echo "web_app_name=$(terraform output -raw web_app_name)" >> $GITHUB_OUTPUT
echo "web_app_resource_group=$(terraform output -raw web_app_resource_group)" >> $GITHUB_OUTPUT
echo "workload_public_url=$(terraform output -raw workload_public_url)" >> $GITHUB_OUTPUT
echo "sql_server_fqdn=$(terraform output -raw sql_server_fqdn)" >> $GITHUB_OUTPUT
echo "sql_database_name=$(terraform output -raw sql_database_name)" >> $GITHUB_OUTPUT
echo "key_vault_name=$(terraform output -raw key_vault_name)" >> $GITHUB_OUTPUT
echo "integration_tests_account_name=$(terraform output -raw integration_tests_account_name)" >> $GITHUB_OUTPUT
echo "api_audience=$(terraform output -raw api_audience)" >> $GITHUB_OUTPUT
env:
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
ARM_USE_OIDC: true
outputs:
web_app_name: ${{ steps.terraform-output.outputs.web_app_name }}
web_app_resource_group: ${{ steps.terraform-output.outputs.web_app_resource_group }}
workload_public_url: ${{ steps.terraform-output.outputs.workload_public_url }}
sql_server_fqdn: ${{ steps.terraform-output.outputs.sql_server_fqdn }}
sql_database_name: ${{ steps.terraform-output.outputs.sql_database_name }}
key_vault_name: ${{ steps.terraform-output.outputs.key_vault_name }}
integration_tests_account_name: ${{ steps.terraform-output.outputs.integration_tests_account_name }}
api_audience: ${{ steps.terraform-output.outputs.api_audience }}
deploy-sql-database-dev:
environment: Development
runs-on: ubuntu-latest
needs: [terraform-plan-and-apply-dev]
steps:
- uses: actions/checkout@v3
- uses: frasermolyneux/actions/deploy-sql-database@main
with:
sql-args: /Variables:env=dev /Variables:instance=01
sql-server-fqdn: ${{ needs.terraform-plan-and-apply-dev.outputs.sql_server_fqdn }}
sql-database-name: ${{ needs.terraform-plan-and-apply-dev.outputs.sql_database_name }}
project-folder: "src/database"
project-file: "database.sqlproj"
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
app-service-deploy-dev:
environment: Development
runs-on: ubuntu-latest
needs:
[dotnet-web-ci, deploy-sql-database-dev, terraform-plan-and-apply-dev]
steps:
- uses: actions/checkout@v3
- uses: frasermolyneux/actions/deploy-app-service@main
with:
web-artifact-name: "repository-webapi"
web-app-name: ${{ needs.terraform-plan-and-apply-dev.outputs.web_app_name }}
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
run-api-integration-tests-dev:
environment: Development
runs-on: ubuntu-latest
needs: [app-service-deploy-dev, terraform-plan-and-apply-dev]
steps:
- name: "Az CLI Login"
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- shell: bash
run: |
client_id=$(az keyvault secret show --name "${{ needs.terraform-plan-and-apply-dev.outputs.integration_tests_account_name }}-client-id" --vault-name "${{ needs.terraform-plan-and-apply-dev.outputs.key_vault_name }}" --query value -o tsv)
client_secret=$(az keyvault secret show --name "${{ needs.terraform-plan-and-apply-dev.outputs.integration_tests_account_name }}-client-secret" --vault-name "${{ needs.terraform-plan-and-apply-dev.outputs.key_vault_name }}" --query value -o tsv)
client_tenant_id=$(az keyvault secret show --name "${{ needs.terraform-plan-and-apply-dev.outputs.integration_tests_account_name }}-client-tenant-id" --vault-name "${{ needs.terraform-plan-and-apply-dev.outputs.key_vault_name }}" --query value -o tsv)
api_key=$(az keyvault secret show --name "${{ needs.terraform-plan-and-apply-dev.outputs.integration_tests_account_name }}-api-key-primary" --vault-name "${{ needs.terraform-plan-and-apply-dev.outputs.key_vault_name }}" --query value -o tsv)
echo "::add-mask::$client_id"
echo "::add-mask::$client_secret"
echo "::add-mask::$client_tenant_id"
echo "::add-mask::$api_key"
echo "int_test_client_id=$client_id" >> $GITHUB_ENV
echo "int_test_client_secret=$client_secret" >> $GITHUB_ENV
echo "int_test_client_tenant_id=$client_tenant_id" >> $GITHUB_ENV
echo "int_test_api_key=$api_key" >> $GITHUB_ENV
- uses: frasermolyneux/actions/run-api-integration-tests@main
with:
dotnet-version: 7.0.x
src-folder: "src"
api-base-url: ${{ needs.terraform-plan-and-apply-dev.outputs.workload_public_url }}
api-key: ${{ env.int_test_api_key }}
api-audience: ${{ needs.terraform-plan-and-apply-dev.outputs.api_audience }}
AZURE_CLIENT_ID: ${{ env.int_test_client_id }}
AZURE_CLIENT_SECRET: ${{ env.int_test_client_secret }}
AZURE_TENANT_ID: ${{ env.int_test_client_tenant_id }}
terraform-plan-prd:
if: github.actor != 'dependabot[bot]' # dependabot context has no permissions to prod so skip this check
environment: Production
runs-on: ubuntu-latest
needs: [terraform-plan-and-apply-dev]
steps:
- uses: actions/checkout@v3
- uses: frasermolyneux/actions/terraform-plan@main
with:
terraform-folder: "terraform"
terraform-var-file: "tfvars/prd.tfvars"
terraform-backend-file: "backends/prd.backend.hcl"
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}