Skip to content

Commit

Permalink
Update GitHub downloading of binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
Labfox committed Sep 11, 2024
1 parent 25c0d1b commit 0527c96
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 34 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ name: Go
on:
push:
branches: [ "main" ]
paths:
- whatsfly/dependencies/**
- .github/workflows/build.yml
schedule:
- cron: "1 1 1 * *"


jobs:

Expand Down
18 changes: 10 additions & 8 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# This file was autogenerated by uv via the following command:
# uv pip compile dev-requirements.in requirements.in
# uv pip compile dev-requirements.in
aiosqlite==0.20.0
# via -r dev-requirements.in
black==24.8.0
# via -r dev-requirements.in
certifi==2024.7.4
certifi==2024.8.30
# via requests
cfgv==3.4.0
# via pre-commit
Expand All @@ -17,7 +17,7 @@ click==8.1.7
# typer
distlib==0.3.8
# via virtualenv
filelock==3.15.4
filelock==3.16.0
# via virtualenv
ghp-import==2.1.0
# via mkdocs
Expand Down Expand Up @@ -53,7 +53,7 @@ mkdocs==1.6.1
# via -r dev-requirements.in
mkdocs-get-deps==0.2.0
# via mkdocs
multidict==6.0.5
multidict==6.1.0
# via yarl
mypy==1.11.2
# via -r dev-requirements.in
Expand All @@ -72,7 +72,7 @@ pathspec==0.12.1
# via
# black
# mkdocs
platformdirs==4.2.2
platformdirs==4.3.2
# via
# black
# mkdocs-get-deps
Expand Down Expand Up @@ -111,10 +111,12 @@ qrcode==7.4.2
# via -r dev-requirements.in
requests==2.32.3
# via -r dev-requirements.in
rich==13.8.0
rich==13.8.1
# via typer
ruff==0.6.4
# via -r dev-requirements.in
setuptools==74.1.2
# via -r dev-requirements.in
shellingham==1.5.4
# via typer
six==1.16.0
Expand All @@ -135,13 +137,13 @@ vcrpy==6.0.1
# via
# -r dev-requirements.in
# pytest-vcr
virtualenv==20.26.3
virtualenv==20.26.4
# via pre-commit
watchdog==5.0.2
# via
# -r dev-requirements.in
# mkdocs
wrapt==1.16.0
# via vcrpy
yarl==1.9.4
yarl==1.11.1
# via vcrpy
28 changes: 6 additions & 22 deletions whatsfly/dependencies/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import subprocess
import platform
import os
from .github_actions_download import download_file


def get_dll_filename(h=False):
Expand Down Expand Up @@ -77,6 +78,8 @@ def build():


def ensureUsableBinaries():
root_dir = os.path.abspath(os.path.dirname(__file__))

try:
import whatsfly.whatsmeow
return
Expand All @@ -96,28 +99,9 @@ def ensureUsableBinaries():
url = f"https://github.com/Labfox/whatsfly/raw/main/whatsfly/dependencies/{get_dll_filename().replace("whatsmeow/", "whatsmeow/static/")}"
h_url = f"https://github.com/Labfox/whatsfly/raw/main/whatsfly/dependencies/{get_dll_filename(h=True).replace("whatsmeow/", "whatsmeow/static/")}"

logging.debug(f"Dowloading {url} and {h_url}")

root_dir = os.path.abspath(os.path.dirname(__file__))

try:
rq = requests.get(url, stream=True)
if rq.status_code != 200:
raise RuntimeError(
f"Server responded with {rq.status_code}, impossible to find the binaries, giving up"
)
open(f"{root_dir.replace("dependencies", "")}/dependencies/{get_dll_filename()}", "wb").write(rq.content)

rq = requests.get(url, stream=True)
if rq.status_code != 200:
raise RuntimeError(
f"Server responded with {rq.status_code}, impossible to find the binaries, giving up"
)
open(f"{root_dir.replace("dependencies", "")}/dependencies/{get_dll_filename(h=True)}", "wb").write(
rq.content
)
except Exception:
raise RuntimeError("Impossible to find the binaries, giving up")
download_file(
get_dll_filename().replace("whatsfly/", ""),
root_dir.replace("dependencies", "")+"/dependencies/whatsmeow/"+get_dll_filename().replace("whatsfly/", "") )


class BuildGoModule(install):
Expand Down
25 changes: 25 additions & 0 deletions whatsfly/dependencies/github_actions_download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import requests
from io import BytesIO
from zipfile import ZipFile


def download_file(file, path):
github_path = "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"

headers = {"Authorization": "token "+github_path}

r = requests.get(f"https://api.github.com/repos/Labfox/whatsfly/actions/artifacts?per_page=1&name={file}", headers=headers)
if r.status_code != 200:
raise FileNotFoundError()

r = r.json()

if len(r["artifacts"]) != 1:
raise FileNotFoundError()


r2 = requests.get(r["artifacts"][0]["archive_download_url"], headers=headers)

myzip = ZipFile(BytesIO(r2.content))

myzip.extractall(path=path)
5 changes: 4 additions & 1 deletion whatsfly/featureflags.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,7 @@ def check_feature(self, feature: Feature) -> bool:
'''
if feature.name in self._features:
return self._features[feature.name].check_feature(feature)
return False
return False

def return_version():
pass

0 comments on commit 0527c96

Please sign in to comment.