Skip to content

Commit

Permalink
web conversion: Convert vial-gui into a web-publisher.
Browse files Browse the repository at this point in the history
Now, all the build does is publish the web version of Vial.
  • Loading branch information
ilc committed Aug 18, 2024
1 parent a8a4d98 commit bafcc5a
Show file tree
Hide file tree
Showing 9 changed files with 1,405 additions and 109 deletions.
119 changes: 10 additions & 109 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,126 +1,27 @@
name: CI

on: [push, pull_request]
on: [push]

jobs:
build-linux:
runs-on: ubuntu-22.04

container:
image: ubuntu:18.04
options: --privileged
env:
LD_LIBRARY_PATH: /__w/vial-gui/vial-gui/util/python36/prefix/lib/
image: ghcr.io/ilc/vial-gui-build:latest

steps:
- uses: actions/checkout@v3

- name: Install dependencies
run: |
apt-get update
apt-get install -y libusb-1.0-0-dev libudev-dev ruby ruby-dev rubygems build-essential desktop-file-utils wget unzip zlib1g-dev liblzma-dev libssl-dev git imagemagick file libfuse2
wget https://github.com/AppImage/pkg2appimage/archive/38603d92359a48189c35debad9005e8e902e6070.zip
unzip *.zip
gem install --no-document fpm
- name: Set up Python 3.6
run: ./util/setup_python36.sh

- name: Setup venv
run: |
./util/python36/prefix/bin/python3 -m venv venv
. venv/bin/activate
pip install -r requirements.txt
- name: Build
run: |
. venv/bin/activate
fbs freeze
fbs installer
deactivate
./pkg2appimage-*/pkg2appimage misc/Vial.yml
mv out/Vial-*.AppImage out/Vial-x86_64.AppImage
- uses: actions/upload-artifact@v3
with:
name: vial-linux
path: out/Vial-x86_64.AppImage

build-mac:
runs-on: macos-11
env:
PYTHON_VERSION: 3.6.8
MACOSX_DEPLOYMENT_TARGET: 10.9

steps:
- uses: actions/checkout@v3

- name: Get Python
run: curl https://www.python.org/ftp/python/${PYTHON_VERSION}/python-${PYTHON_VERSION}-macosx${MACOSX_DEPLOYMENT_TARGET}.pkg -o "python.pkg"

- name: Verify download
run: shasum -a 256 -c <<< '4bcd53faffc98d193ef7cdccd5668de3829c702af4db45258819a84a2cab60d0 *python.pkg'

- name: Install Python
run: |
sudo installer -pkg python.pkg -target /
- name: Setup venv
run: |
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
- name: Add safe directory
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"

- name: Build
run: |
source venv/bin/activate
fbs freeze
hdiutil create -volname Vial -srcfolder "target/Vial.app" -ov -format UDZO vial-mac.dmg
- uses: actions/upload-artifact@v3
with:
name: vial-mac
path: vial-mac.dmg

build-win:
runs-on: windows-2019

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.6.x'

- name: Setup venv
run: |
python -m venv venv
. .\venv\Scripts\activate.ps1
pip install -r requirements.txt
- name: Install NSIS
run: |
Invoke-WebRequest "https://github.com/vial-kb/vial-deps/releases/download/v1/nsis-3.06.1-setup.exe" -UserAgent "wget" -OutFile nsis-3.06.1-setup.exe
if ((Get-FileHash nsis-3.06.1-setup.exe -Algorithm sha256).Hash -ne "f60488a676308079bfdf6845dc7114cfd4bbff47b66be4db827b89bb8d7fdc52") { Write-Error 'SHA256 mismatch' }
Start-Process -FilePath "nsis-3.06.1-setup.exe" -ArgumentList "/S", "/D=C:\Program Files (x86)\NSIS" -NoNewWindow -Wait
- name: Build
run: |
. .\venv\Scripts\activate.ps1
fbs freeze
Compress-Archive -Path "target\Vial" -DestinationPath vial-win.zip
- uses: actions/upload-artifact@v3
with:
name: vial-win
path: vial-win.zip

- name: Create installer
run: |
$env:Path += ";C:\Program Files (x86)\NSIS"
. .\venv\Scripts\activate.ps1
fbs installer
cd web
./build.sh
- uses: actions/upload-artifact@v3
- name: Deploy Web Sit.
uses: peaceiris/actions-gh-pages@v3
with:
name: vial-win-installer
path: target\VialSetup.exe
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./web/build/. # Replace with
23 changes: 23 additions & 0 deletions http-server-cors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python

# Attribution: https://stackoverflow.com/questions/21956683/enable-access-control-on-simple-http-server

try:
# Python 3
from http.server import HTTPServer, SimpleHTTPRequestHandler, test as test_orig
import sys
def test (*args):
test_orig(*args, port=int(sys.argv[1]) if len(sys.argv) > 1 else 8000)
except ImportError: # Python 2
from BaseHTTPServer import HTTPServer, test
from SimpleHTTPServer import SimpleHTTPRequestHandler

class CORSRequestHandler (SimpleHTTPRequestHandler):
def end_headers (self):
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Cross-Origin-Embedder-Policy', 'require-corp')
self.send_header('Cross-Origin-Opener-Policy', 'same-origin')
SimpleHTTPRequestHandler.end_headers(self)

if __name__ == '__main__':
test(CORSRequestHandler, HTTPServer)
100 changes: 100 additions & 0 deletions web/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/bin/bash

set -e

source /vial-web/version.sh
source /vial-web/emsdk/emsdk_env.sh

mkdir -p build
rm -rf build/*

pushd build

VIAL_VER=$(git rev-parse HEAD)
WEB_VER=$(git rev-parse HEAD)
VIA_STACK_VER="UNKNOWN"
UNIQVER=$(echo ${VIAL_VER} ${WEB_VER} ${VIA_STACK_VER} | sha256sum | awk '{print $1}')

cp ../icon.png .
cp -r /vial-web/deps/cpython/builddir/emscripten-browser/usr .
cp /vial-web/via-keymap-precompiled/via_keyboard_stack.json usr/local/via_keyboards.json
cp ../../src/main/resources/base/qmk_settings.json usr/local
cp ../../src/build/settings/base.json usr/local/build_settings.json
cp -r ../../src/main/python/* usr/local/lib/python3.11
cp ../simpleeval.py usr/local/lib/python3.11
emcc \
--preload-file="./usr/local" \
-I /vial-web/deps/cpython/Include/ \
-I /vial-web/deps/cpython/builddir/emscripten-browser/ \
-I /vial-web/deps/cpython/Include/internal/ \
/vial-web/deps/cpython/builddir/emscripten-browser/libpython3.11.a \
/vial-web/deps/cpython/builddir/emscripten-browser/Modules/_decimal/libmpdec/libmpdec.a \
/vial-web/deps/cpython/builddir/emscripten-browser/Modules/expat/libexpat.a \
-sALLOW_MEMORY_GROWTH \
-sTOTAL_MEMORY=20971520 \
-sFORCE_FILESYSTEM \
-sTEXTDECODER=0 \
-lidbfs.js \
-lnodefs.js \
-lproxyfs.js \
-lworkerfs.js \
-O2 -g0 \
-o main-${UNIQVER}.js \
-ldl \
-lm \
-sUSE_ZLIB \
-sUSE_BZIP2 \
-sUSE_ZLIB \
-L /vial-web/deps/PyQt5-${PYQT5_VER}/QtCore \
-L /vial-web/deps/qt5/qtbase/lib \
-L /vial-web/deps/PyQt5_sip-${PYQT5SIP_VER} \
-L /vial-web/deps/PyQt5-${PYQT5_VER}/QtGui \
-L /vial-web/deps/PyQt5-${PYQT5_VER}/QtWidgets \
-L /vial-web/deps/qt5/qtbase/plugins/platforms \
-L /vial-web/deps/PyQt5-${PYQT5_VER}/QtSvg \
-L /vial-web/deps/qt5/qtbase/plugins/iconengines \
-L /vial-web/deps/qt5/qtbase/plugins/imageformats \
-l QtCore \
-l Qt5Core \
-l sip \
-l QtGui \
-l QtWidgets \
-l Qt5Core \
-l Qt5Gui \
-l Qt5Widgets \
-l qwasm \
-l Qt5FontDatabaseSupport \
-l qminimal \
-l Qt5EventDispatcherSupport \
-l qoffscreen \
--bind \
-l qtharfbuzz \
-l QtSvg \
-l qsvgicon \
-l qjpeg \
-l qsvg \
-l Qt5Svg \
-s USE_FREETYPE=1 \
-s USE_LIBPNG=1 \
-lqtpcre2 \
-pthread \
-sDISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=0 \
-s EXTRA_EXPORTED_RUNTIME_METHODS=\["UTF16ToString","stringToUTF16","getValue","setValue"\] \
-sEXPORTED_FUNCTIONS=\["_PyRun_SimpleString","_vialglue_set_response","_vialglue_set_response_error","_vialglue_set_device_desc","_main"\] \
-sPROXY_TO_PTHREAD \
-sOFFSCREENCANVAS_SUPPORT \
-L /vial-web/deps/xz-${XZ_VER}/prefix/lib/ \
-llzma \
../main.c
cp ../index.html .
cat ../worker.js >> main-${UNIQVER}.worker.js
sed -i 's+err("worker sent an unknown command+my_onmessage(e);return;err("worker sent an unknown command/+g' main-${UNIQVER}.js

rm -rf usr

sed -i "s/@VIAL_VER@/${VIAL_VER}/g" index.html
sed -i "s/@WEB_VER@/${WEB_VER}/g" index.html
sed -i "s/@VIA_STACK_VER@/${VIA_STACK_VER}/g" index.html
sed -i "s/@UNIQVER@/${UNIQVER}/g" index.html

popd
Binary file added web/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit bafcc5a

Please sign in to comment.