Skip to content

Commit dc6ed87

Browse files
committed
actions
1 parent 7212ce8 commit dc6ed87

File tree

2 files changed

+48
-60
lines changed

2 files changed

+48
-60
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: 'Wait for deployment'
2+
description: 'Wait fr deployment'
3+
inputs:
4+
url:
5+
description: 'URL'
6+
required: true
7+
githash:
8+
description: 'Githash'
9+
required: true
10+
runs:
11+
using: "composite"
12+
steps:
13+
- name: Wait for deployment
14+
run: |
15+
import requests
16+
import os
17+
import time
18+
19+
attempts = 0
20+
new_version_live_counter = 0
21+
while new_version_live_counter < 3:
22+
response = requests.get(os.getenv('URL'))
23+
try:
24+
commit = response.json()['version']
25+
if commit == os.getenv('GITHASH'):
26+
print('New version live')
27+
new_version_live_counter = new_version_live_counter + 1
28+
continue
29+
else:
30+
print('Commit hash does not match. Retrying...')
31+
except Exception as e:
32+
print('Failed to get version', e)
33+
34+
attempts += 1
35+
36+
if attempts > 30:
37+
print('Failed to get new version')
38+
exit(1)
39+
40+
time.sleep(attempts)
41+
shell: python
42+
env:
43+
URL: ${{ inputs.url }}
44+
GITHASH: ${{ inputs.githash }}

.github/workflows/deploy.yml

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -191,37 +191,9 @@ jobs:
191191
needs: [deploy-be, build-be]
192192
steps:
193193
- name: Wait stable deployment
194-
run: |
195-
import requests
196-
import os
197-
import time
198-
199-
attempts = 0
200-
while True:
201-
response = requests.get(f"https://{os.getenv('URL')}/health/")
202-
try:
203-
commit = response.json()['version']
204-
if commit == os.getenv('GITHASH'):
205-
print('New version live')
206-
break
207-
else:
208-
print('Commit hash does not match. Retrying...')
209-
except Exception as e:
210-
print('Failed to get version', e)
211-
212-
attempts += 1
213-
214-
if attempts > 30:
215-
print('Failed to get new version')
216-
exit(1)
217-
218-
time.sleep(attempts)
219-
shell: python
194+
uses: ./.github/actions/wait-for-deployment
220195
env:
221-
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
222-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
223-
AWS_DEFAULT_REGION: eu-central-1
224-
URL: ${{ fromJSON('["pastaporto-", ""]')[github.ref == 'refs/heads/main'] }}admin.pycon.it
196+
URL: https://${{ fromJSON('["pastaporto-", ""]')[github.ref == 'refs/heads/main'] }}admin.pycon.it/health/
225197
GITHASH: ${{ needs.build-be.outputs.githash }}
226198

227199
build-fe:
@@ -350,35 +322,7 @@ jobs:
350322
needs: [deploy-fe, build-fe]
351323
steps:
352324
- name: Wait stable deployment
353-
run: |
354-
import requests
355-
import os
356-
import time
357-
358-
attempts = 0
359-
while True:
360-
response = requests.get(f"https://{os.getenv('URL')}/api/health")
361-
try:
362-
commit = response.json()['version']
363-
if commit == os.getenv('GITHASH'):
364-
print('New version live')
365-
break
366-
else:
367-
print('Commit hash does not match. Retrying...')
368-
except Exception as e:
369-
print('Failed to get version', e)
370-
371-
attempts += 1
372-
373-
if attempts > 30:
374-
print('Failed to get new version')
375-
exit(1)
376-
377-
time.sleep(attempts)
378-
shell: python
325+
uses: ./.github/actions/wait-for-deployment
379326
env:
380-
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
381-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
382-
AWS_DEFAULT_REGION: eu-central-1
383-
URL: ${{ fromJSON('["pastaporto-frontend", "frontend"]')[github.ref == 'refs/heads/main'] }}.pycon.it
327+
URL: https://${{ fromJSON('["pastaporto-frontend", "frontend"]')[github.ref == 'refs/heads/main'] }}.pycon.it/api/health
384328
GITHASH: ${{ needs.build-fe.outputs.githash }}

0 commit comments

Comments
 (0)