Skip to content

Commit

Permalink
CI: Download DLLs from other repository release
Browse files Browse the repository at this point in the history
  • Loading branch information
s09bQ5 committed Aug 19, 2024
1 parent 9ab102e commit 25ba35b
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
79 changes: 79 additions & 0 deletions dldlls.py
Original file line number Diff line number Diff line change
@@ -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'))

0 comments on commit 25ba35b

Please sign in to comment.