From 25ba35b6a82808d1462cca80bb58d3634869b311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gl=C3=B6ckner?= Date: Fri, 9 Aug 2024 00:28:34 +0200 Subject: [PATCH] CI: Download DLLs from other repository release --- .github/workflows/main.yml | 4 ++ dldlls.py | 79 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100755 dldlls.py diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7efcdbbc7..6384a8802 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,6 +25,10 @@ jobs: $Env:FPCDIR = "c:\newpascal\fpcsrc" $Env:PATH = "c:\newpascal\fpc\bin\i386-win32;c:\newpascal\binw32;$Env:PATH" c:\newpascal\lazarus\lazbuild src\ultrastardx-win.lpi --lazarusdir=c:\newpascal\lazarus + - name: Add prebuilt DLLs + run: | + python dldlls.py + 7z x -y usdx-dlls.zip -ogame "*.dll" - name: Create installer run: | del game\*.debug diff --git a/dldlls.py b/dldlls.py new file mode 100755 index 000000000..768199ce1 --- /dev/null +++ b/dldlls.py @@ -0,0 +1,79 @@ +#!/usr/bin/python3 + +import urllib.request +import shutil +import json +import sys +import os + +sha = '97b88f326c429bccab263f809a16798c3e1ec6b5' +filename = 'usdx-dlls-i686' +urlbase = 'https://api.github.com/repos/UltraStar-Deluxe/mxe/' +headers = { + 'Accept': 'application/vnd.github+json', + 'X-GitHub-Api-Version': '2022-11-28' + } + +token = os.environ.get('ARTIFACT_ACCESS_TOKEN') +if token != None: + headers['Authorization'] = 'Bearer ' + token + +print('Searching for binaries built from commit ' + sha) + +def search_releases(): + pagesuffix = '' + page = 1 + links = '"next"' + while links != None and links.find('"next"') != -1: + req = urllib.request.Request(url = urlbase + 'tags' + pagesuffix, + headers = headers) + rsp = urllib.request.urlopen(req) + links = rsp.headers['link'] + for tag in json.load(rsp): + if tag['commit']['sha'] == sha: + req = urllib.request.Request(url = urlbase + 'releases/tags/' + + tag['name'], + headers = headers) + rsp = urllib.request.urlopen(req) + release = json.load(rsp) + for asset in release['assets']: + if asset['name'].startswith(filename): + print('Found binaries in release ' + release['name']) + headers.clear() + return asset['browser_download_url'] + page = page + 1 + pagesuffix = '?page={}'.format(page) + print('No release matches') + return None + +def search_artifacts(): + pagesuffix = '' + page = 1 + links = '"next"' + while links != None and links.find('"next"') != -1: + req = urllib.request.Request(url = urlbase + + 'actions/artifacts' + + '?name=' + filename + + pagesuffix, + headers = headers) + rsp = urllib.request.urlopen(req) + links = rsp.headers['link'] + for artifact in json.load(rsp)['artifacts']: + if artifact['workflow_run']['head_sha'] == sha and not artifact['expired']: + print('Found binaries in workflow run ' + artifact['workflow_run']['id']) + del headers['Accept'] + return artifact['archive_download_url'] + page = page + 1 + pagesuffix = '&page={}'.format(page) + print('No workflow artifact matches') + return None + +dllurl = search_releases() +if dllurl == None and token != None: + dllurl = search_artifacts() +if dllurl == None: + sys.exit(1) +print('Downloading from ' + dllurl) +req = urllib.request.Request(url = dllurl, headers = headers) +shutil.copyfileobj(urllib.request.urlopen(req), + open(filename + '.zip', 'wb'))