-
Notifications
You must be signed in to change notification settings - Fork 0
150 lines (137 loc) · 5.06 KB
/
fingertips-api-deploy.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
name: Fingertips API Deploy
on:
workflow_dispatch:
workflow_run:
workflows: [Fingertips API Build]
types:
- completed
branches:
- main
jobs:
check-db-changes:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2
ref: ${{ github.event.workflow_run.head_branch }}
- name: Check for changes in database directory
id: check
run: |
if git diff --name-only HEAD~1 HEAD | grep '^database/'; then
echo "DB changes detected"
echo "DB_CHANGED=true" >> $GITHUB_ENV
else
echo "No DB changes detected"
echo "DB_CHANGED=false" >> $GITHUB_ENV
fi
- name: Wait for Database Deployment to Complete
uses: actions/github-script@v7
id: database_status
if: env.DB_CHANGED == 'true'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
retries: 10
script: |
async function waitForDBDeployment() {
const workflowName = 'fingertips-db-deploy.yml';
const headSHA = '${{ github.event.workflow_run.head_branch }}';
const maxRetries = 20;
const delayMs = 30 * 1000; // 30 seconds per check
for (let i = 0; i < maxRetries; i++) {
const runs = await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: workflowName,
head_sha: headSHA,
});
if (runs.data.workflow_runs.length > 0) {
const latestRun = runs.data.workflow_runs[0];
if (latestRun.status === 'completed') {
console.log(`Database deployment completed with status: ${latestRun.conclusion}`);
core.setOutput("db_completed", 'true');
return;
} else {
console.log(`Database deployment is still running. Status: ${latestRun.status}`);
}
} else {
console.log("No database deployment run found yet.");
}
await new Promise(resolve => setTimeout(resolve, delayMs));
}
console.log("Database deployment did not complete within the timeout period (30s).");
core.setFailed("Database deployment did not complete in time.");
}
await waitForDBDeployment();
determine-version:
uses: ./.github/workflows/determine-semver.yml
with:
fetch-depth: 0
gitversion-version: "6.0.x"
api-deploy-development:
needs: [determine-version, check-db-changes]
uses: ./.github/workflows/deploy-container.yml
with:
tf_state_file_name: fingertips.api.tfstate
environment: development
tf_environment: dev
source_branch: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_branch || github.ref_name }}
source_trigger: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.event || github.event_name }}
container_image_tag: ${{ github.event_name == 'workflow_run' && format('dhsc.fingertipsnext.api:{0}', needs.determine-version.outputs.sem-ver) || 'dhsc.fingertipsnext.api:latest' }}
container_name: "fingertips-api"
revision_suffix: ${{ github.run_number }}
container_port: 8080
environment_variables: |
[
{
name = "DB_SERVER"
secret_name = "fingertips-sql-hostname"
value = null
},
{
name = "DB_NAME"
secret_name = "fingertips-db-name"
value = null
},
{
name = "DB_USER"
secret_name = "fingertips-sql-username"
value = null
},
{
name = "DB_PASSWORD"
secret_name = "fingertips-sql-password"
value = null
}
]
container_liveness_probe: |
{
path = "/healthcheck"
port = 8080
transport = "HTTP"
}
secrets:
arm-client-id: ${{ secrets.ARM_CLIENT_ID }}
arm-client-secret: ${{ secrets.ARM_CLIENT_SECRET }}
arm-subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
arm-tenant-id: ${{ secrets.AZURE_TENANT_ID }}
e2e-tests-development:
uses: ./.github/workflows/e2e-tests.yml
if: |
${{
github.event_name == 'workflow_dispatch' ||
(
github.event_name == 'workflow_run' &&
(
github.event.workflow_run.event == 'push' ||
github.event.workflow_run.event == 'workflow_dispatch'
)
)
}}
needs: api-deploy-development
with:
env-url: ${{ needs.api-deploy-development.outputs.frontend-dev-url }}
send-slack-on-fail: "true"
secrets:
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}