Skip to content

Commit

Permalink
Run tests on already deployed
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-dubinin committed Oct 8, 2024
1 parent 2291cff commit e0b8605
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions .github/await_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

def wait_for_deployment(timeout):
branch_name = os.getenv('BRANCH_NAME')
print(f"Wait for a deployment for a branch name: {branch_name}")
time.sleep(30)
print(f"Wait for a deployment for a branch name: {branch_name} to start.")
time.sleep(20)
bearer_token = os.getenv('VERCEL_TOKEN')
project_id = os.getenv('VERCEL_PROJECT')
target = os.getenv('VERCEL_TARGET', 'preview')
Expand All @@ -16,22 +16,26 @@ def wait_for_deployment(timeout):
url = f"https://api.vercel.com/v6/deployments?projectId={project_id}&target={target}&state=BUILDING"
response = requests.get(url, headers=headers)
deployments = response.json()['deployments']
print(f"Found {len(deployments)} deployments.")
print(f"Found {len(deployments)} deployments in BUILDING state.")

if len(deployments) == 0:
raise Exception(f"No Vercel deployments in state=BUILDING for {branch_name}!")
vercel_uid = ""
vercel_url = ""
for deployment in deployments:
if deployment['meta']['githubCommitRef'] == branch_name:
vercel_uid = deployment['uid']
vercel_url = deployment['url']
# Check for the latest deployment
url = f"https://api.vercel.com/v6/deployments?projectId={project_id}&target={target}&limit=1"
response = requests.get(url, headers=headers)
deployments = response.json()['deployments']
if len(deployments) == 0:
raise Exception(f"No Vercel deployments found for {branch_name}!")
print("No deployments in BUILDING state. Using the latest deployment.")

vercel_uid = deployments[0]['uid']
vercel_url = deployments[0]['url']
gh_out = f"environment_url={vercel_url}"
os.system(f'echo "{gh_out}" >> $GITHUB_OUTPUT')
os.system(f'echo "{gh_out}" >> $GITHUB_ENV')
os.system(f'echo Vercel deployment: "{gh_out}" >> $GITHUB_STEP_SUMMARY')
for i in range(1, timeout):
print(f"Sleep for 15 seconds and get deployment uid {vercel_uid} and url: {vercel_url}")
time.sleep(15)
print(f"Sleep for 20 seconds and get deployment uid {vercel_uid} and url: {vercel_url}")
time.sleep(20)
current_url = f"https://api.vercel.com/v13/deployments/{vercel_uid}"
ui_url = f"https://vercel.com/osmo-labs/osmosis-frontend/{vercel_uid}"
current_response = requests.get(current_url, headers=headers)
Expand All @@ -45,4 +49,4 @@ def wait_for_deployment(timeout):
return f"environment_url={vercel_url}"


wait_for_deployment(80)
wait_for_deployment(30)

0 comments on commit e0b8605

Please sign in to comment.