Skip to content

Commit

Permalink
Finally fixed gha-4
Browse files Browse the repository at this point in the history
  • Loading branch information
Pythonic-Rainbow committed Sep 27, 2024
1 parent c259fd4 commit e5479c4
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions Bot/hyperstellar.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from urllib import request
import urllib
import json
import os
from zipfile import ZipFile
Expand All @@ -9,6 +10,7 @@
pass

RUNS_URL = 'https://api.github.com/repos/TCLRainbow/Hyperstellar/actions/workflows/82482571/runs'
BRANCH = 'main'


def explode(cond, msg):
Expand All @@ -32,10 +34,8 @@ def build_artifact_url(run_id):
explode(run_count == 0, 'No workflow runs!')
print(f'There are {run_count} runs')

BRANCH = 'gha-4'

for i in range(run_count):
run = result['workflow_runs'][i]
# Get latest run from branch
for run in result['workflow_runs']:
if run['head_branch'] == BRANCH:
break

Expand All @@ -58,7 +58,6 @@ def build_artifact_url(run_id):
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']
Expand All @@ -72,18 +71,21 @@ def build_artifact_url(run_id):
explode(artifact['name'] != 'Bot', 'Artifact name not Bot!')

download_url = artifact['archive_download_url']
print(download_url)
# download_url = f"https://github.com/TCLRainbow/Hyperstellar/actions/runs/11033362227/artifacts/1976833830"

headers = {'Authorization': f'Bearer {token}',
'User-Agent': 'insomnia/10.0',
'header': 'application/vnd.github+json'}
req = request.Request(download_url, headers=headers)
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(f'Downloading {download_url}')
try:
with request.urlopen(req) as resp:
with open('bot.zip', 'wb') as f:
f.write(resp.read())
except urllib.error.HTTPError as e:
redirected_url = e.geturl()
print(f'Redirecting to {redirected_url}')
req = request.Request(redirected_url)
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()
Expand Down

0 comments on commit e5479c4

Please sign in to comment.