From 89c68570208225175a680938f38d43fbb8d068b9 Mon Sep 17 00:00:00 2001 From: Pythonic-Rainbow Date: Wed, 25 Sep 2024 20:48:46 +0800 Subject: [PATCH 1/3] [GHA] Try using upload-artifact v4 again --- .github/workflows/bot.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bot.yml b/.github/workflows/bot.yml index 7374ccd..0f16b7e 100644 --- a/.github/workflows/bot.yml +++ b/.github/workflows/bot.yml @@ -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: | From c259fd42c1cf959c37a3c3fb9ebd70043d49203a Mon Sep 17 00:00:00 2001 From: Pythonic-Rainbow Date: Sat, 28 Sep 2024 01:22:20 +0800 Subject: [PATCH 2/3] Test --- Bot/hyperstellar.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/Bot/hyperstellar.py b/Bot/hyperstellar.py index 3da2e98..d876043 100644 --- a/Bot/hyperstellar.py +++ b/Bot/hyperstellar.py @@ -32,9 +32,16 @@ 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] +BRANCH = 'gha-4' + +for i in range(run_count): + run = result['workflow_runs'][i] + 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: @@ -51,7 +58,7 @@ 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['head_branch'] != 'main', 'Branch not main') explode(run['pull_requests'], 'Triggered by PR') run_id = run['id'] @@ -65,7 +72,13 @@ def build_artifact_url(run_id): explode(artifact['name'] != 'Bot', 'Artifact name not Bot!') download_url = artifact['archive_download_url'] - req = request.Request(download_url, headers={'Authorization': f'Bearer {token}'}) + 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) os.chdir('./Hyperstellar') print('Downloading') with request.urlopen(req) as resp: From e5479c4b4f4899494289545001d4a2dc32d61776 Mon Sep 17 00:00:00 2001 From: Pythonic-Rainbow Date: Sat, 28 Sep 2024 03:20:42 +0800 Subject: [PATCH 3/3] Finally fixed gha-4 --- Bot/hyperstellar.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/Bot/hyperstellar.py b/Bot/hyperstellar.py index d876043..1b0d87e 100644 --- a/Bot/hyperstellar.py +++ b/Bot/hyperstellar.py @@ -1,4 +1,5 @@ from urllib import request +import urllib import json import os from zipfile import ZipFile @@ -9,6 +10,7 @@ pass RUNS_URL = 'https://api.github.com/repos/TCLRainbow/Hyperstellar/actions/workflows/82482571/runs' +BRANCH = 'main' def explode(cond, msg): @@ -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 @@ -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'] @@ -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()