Skip to content

Commit

Permalink
[GHA] Finally v4 artifacts + select branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Pythonic-Rainbow committed Sep 27, 2024
2 parents c0a6a90 + e5479c4 commit 3d55a29
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Build
run: dotnet publish -c Release -r linux-x64 --no-self-contained
- name: Upload program
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Bot
path: |
Expand Down
29 changes: 22 additions & 7 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,9 +34,14 @@ def build_artifact_url(run_id):
explode(run_count == 0, 'No workflow runs!')
print(f'There are {run_count} runs')

run = result['workflow_runs'][0]
# Get latest run from branch
for run in result['workflow_runs']:
if run['head_branch'] == BRANCH:
break

gha_title = run['display_title']
print(f'Checking run: {gha_title}')
run_branch = run['head_branch']
print(f'Checking run ({run_branch}): {gha_title}')
explode(run['status'] != 'completed', 'Run is not completed!')

if gha_title == current_title:
Expand All @@ -51,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 @@ -67,10 +73,19 @@ def build_artifact_url(run_id):
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(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 3d55a29

Please sign in to comment.