Skip to content

Commit

Permalink
Download frontend asset from github
Browse files Browse the repository at this point in the history
  • Loading branch information
sanyatuning committed Dec 19, 2020
1 parent ec58713 commit dfa0fe3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
node-version: '12'
- run: yarn install
- run: yarn build
- run: cd build && tar -zcf ../build.zip *
- run: zip -qq -r build.zip build
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
Expand Down
2 changes: 1 addition & 1 deletion policy/frontend/.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20201219.0
v0.1.4
33 changes: 28 additions & 5 deletions policy/openbot/server/frontend.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
from subprocess import Popen
import urllib.request
import zipfile

from aiohttp import web

Expand All @@ -11,11 +13,24 @@ async def init_frontend(app: web.Application):
await run_frontend_dev_server(app)
return

# todo:
# get version from file
# download from github if needed
# unzip
pass
frontend_dir = os.path.join(base_dir, "frontend")
zip_path = os.path.join(base_dir, "frontend.zip")
version_target = read_version(frontend_dir, ".version")
version_current = read_version(frontend_dir, "build", ".version")
if version_current == version_target:
print("Frontend is up to date!")
return

# todo fix URL
url = f"https://github.com/sanyatuning/OpenBot/releases/download/{version_target}/frontend.zip"
print("Downloading frontend...")
urllib.request.urlretrieve(url, zip_path)
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
zip_ref.extractall(frontend_dir)
with open(os.path.join(frontend_dir, "build", ".version")) as f:
f.write(version_target)
os.unlink(zip_path)
print("Frontend is ready!")


async def run_frontend_dev_server(app: web.Application):
Expand All @@ -28,6 +43,14 @@ async def run_frontend_dev_server(app: web.Application):
)


def read_version(*args):
try:
with open(os.path.join(*args)) as f:
return f.read().strip()
except FileNotFoundError:
return None


def is_port_in_use(port):
import socket
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
Expand Down

0 comments on commit dfa0fe3

Please sign in to comment.