Skip to content

Commit

Permalink
[DPL] Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Pythonic-Rainbow committed Sep 23, 2024
1 parent d5b5e40 commit 3e1de5b
Showing 1 changed file with 42 additions and 39 deletions.
81 changes: 42 additions & 39 deletions Bot/hyperstellar.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,49 +36,52 @@ def build_artifact_url(run_id):
gha_title = run['display_title']
print(f'Checking run: {gha_title}')
explode(run['status'] != 'completed', 'Run is not completed!')
explode(gha_title == current_title, 'Already downloaded!')

req = request.Request(run['jobs_url'])
with request.urlopen(req) as resp:
result = json.loads(resp.read())
jobs = result['jobs']
build_ok = False
for job in jobs:
if job['name'] == 'build':
build_ok = True
explode(job['conclusion'] != 'success', 'Build failed!')
break
explode(not build_ok, 'No build job found!')
explode(run['head_branch'] != 'main', 'Branch not main')
explode(run['pull_requests'], 'Triggered by PR')
if gha_title == current_title:
print('Already downloaded.')
else:
req = request.Request(run['jobs_url'])
with request.urlopen(req) as resp:
result = json.loads(resp.read())
jobs = result['jobs']
build_ok = False
for job in jobs:
if job['name'] == 'build':
build_ok = True
explode(job['conclusion'] != 'success', 'Build failed!')
break
explode(not build_ok, 'No build job found!')
explode(run['head_branch'] != 'main', 'Branch not main')
explode(run['pull_requests'], 'Triggered by PR')

run_id = run['id']
print('Checking artifact')
req = request.Request(build_artifact_url(run_id))
with request.urlopen(req) as resp:
result = json.loads(resp.read())
run_count = result['total_count']
explode(run_count == 0, 'No artifacts found!')
artifact = result['artifacts'][0]
explode(artifact['name'] != 'Bot', 'Artifact name not Bot!')
run_id = run['id']
print('Checking artifact')
req = request.Request(build_artifact_url(run_id))
with request.urlopen(req) as resp:
result = json.loads(resp.read())
run_count = result['total_count']
explode(run_count == 0, 'No artifacts found!')
artifact = result['artifacts'][0]
explode(artifact['name'] != 'Bot', 'Artifact name not Bot!')

download_url = artifact['archive_download_url']
req = request.Request(download_url, headers={'Authorization': f'Bearer {token}'})
os.chdir('./Hyperstellar')
print('Downloading')
with request.urlopen(req) as resp:
with open('bot.zip', 'wb') as f:
f.write(resp.read())
print('Unzipping')
with ZipFile('bot.zip') as f:
f.extractall()
print('Removing zip')
os.remove('bot.zip')
download_url = artifact['archive_download_url']
req = request.Request(download_url, headers={'Authorization': f'Bearer {token}'})
os.chdir('./Hyperstellar')
print('Downloading')
with request.urlopen(req) as resp:
with open('bot.zip', 'wb') as f:
f.write(resp.read())
print('Unzipping')
with ZipFile('bot.zip') as f:
f.extractall()
print('Removing zip')
os.remove('bot.zip')

os.chdir('..')
with open('hyperstellar-token.txt', 'w') as f:
f.write(f'{token}\n{gha_title}')
print('Updated token.txt')
os.chdir('..')
with open('hyperstellar-token.txt', 'w') as f:
f.write(f'{token}\n{gha_title}')
print('Updated token.txt')

os.chdir('./Hyperstellar')
print('Running')
os.execv('Bot', ['./Bot'])

0 comments on commit 3e1de5b

Please sign in to comment.