-
Notifications
You must be signed in to change notification settings - Fork 0
189 lines (156 loc) · 8.41 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
name: Pull Request Validation
on:
workflow_dispatch:
pull_request:
branches:
- main
permissions:
id-token: write # This is required for Az CLI Login
contents: read # This is required for actions/checkout
jobs:
dependency-review:
runs-on: ubuntu-latest
steps:
- name: "Checkout Repository"
uses: actions/checkout@v4
- name: "Dependency Review"
uses: actions/dependency-review-action@v4
dotnet-web-ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: frasermolyneux/actions/dotnet-web-ci@main
with:
dotnet-project: "repository-webapi"
dotnet-version: 9.0.x
src-folder: "src"
majorMinorVersion: "1.1"
terraform-plan-and-apply-dev:
environment: Development
runs-on: ubuntu-latest
concurrency: # This is required to prevent multiple GitHub Actions invocations against stateful resources. e.g. Terraform state file / Database / Deployed Apps
group: ${{ github.repository }}-dev
steps:
- uses: actions/checkout@v4
- 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: ${{ vars.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ vars.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: ${{ vars.AZURE_CLIENT_ID }}
ARM_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ vars.AZURE_TENANT_ID }}
ARM_USE_AZUREAD: true
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]
concurrency: # This is required to prevent multiple GitHub Actions invocations against stateful resources. e.g. Terraform state file / Database / Deployed Apps
group: ${{ github.repository }}-dev
steps:
- uses: actions/checkout@v4
- 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: ${{ vars.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ vars.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]
concurrency: # This is required to prevent multiple GitHub Actions invocations against stateful resources. e.g. Terraform state file / Database / Deployed Apps
group: ${{ github.repository }}-dev
steps:
- uses: actions/checkout@v4
- 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: ${{ vars.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
run-api-integration-tests-dev:
environment: Development
runs-on: ubuntu-latest
needs: [app-service-deploy-dev, terraform-plan-and-apply-dev]
concurrency: # This is required to prevent multiple GitHub Actions invocations against stateful resources. e.g. Terraform state file / Database / Deployed Apps
group: ${{ github.repository }}-dev
steps:
- name: "Az CLI Login"
uses: azure/login@v2
with:
client-id: ${{ vars.AZURE_CLIENT_ID }}
tenant-id: ${{ vars.AZURE_TENANT_ID }}
subscription-id: ${{ vars.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: 9.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]
concurrency: # This is required to prevent multiple GitHub Actions invocations against stateful resources. e.g. Terraform state file / Database / Deployed Apps
group: ${{ github.repository }}-prd
steps:
- uses: actions/checkout@v4
- 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: ${{ vars.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}