diff --git a/.github/actions/upload-dated-artifact/action.yaml b/.github/actions/upload-dated-artifact/action.yaml new file mode 100644 index 0000000..7fc3fbe --- /dev/null +++ b/.github/actions/upload-dated-artifact/action.yaml @@ -0,0 +1,26 @@ +name: Upload dated artifact +description: Uploads an artifact with a datetime + +inputs: + name: + description: The name of the artifact + required: true + path: + description: The path to the file/folder to upload + required: true + +runs: + using: composite + steps: + # https://stackoverflow.com/questions/60942067/get-current-date-and-time-in-github-workflows + - name: Get current datetime + id: date + shell: bash + run: echo "::set-output name=date::$(date '+%Y-%m-%d_%H-%M-%S')" + + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: ${{ inputs.name }}_${{ steps.date.outputs.date }} + path: ${{ inputs.path }} + if-no-files-found: error diff --git a/.github/workflows/create-binaries.yaml b/.github/workflows/create-binaries.yaml new file mode 100644 index 0000000..26572bc --- /dev/null +++ b/.github/workflows/create-binaries.yaml @@ -0,0 +1,87 @@ +name: Package using PyInstaller +on: + push: + tags: + - v** + workflow_dispatch: + +jobs: + build-windows: + env: + dist-path: dist/OpenSeeFace + runs-on: windows-latest + steps: + - name: Pull OpenSeeFace + uses: actions/checkout@v3 + + - name: Create binary + shell: cmd + run: | + choco install vcredist140 + + xcopy c:\Windows\System32\msvcp140.dll . + xcopy c:\Windows\System32\vcomp140.dll . + xcopy c:\Windows\System32\concrt140.dll . + xcopy c:\Windows\System32\vccorlib140.dll . + + make_exe.bat + + - name: Move files for uploading + shell: bash + run: | + # Prevents the parent dist/ directory from being included + mv dist/facetracker ${{ env.dist-path }} + cp -r models ${{ env.dist-path }} + + - name: Upload artifact + uses: ./.github/actions/upload-dated-artifact + with: + name: windows + path: dist # Add the parent directory to prevent a tarbomb + + # Files must be packed into a tar in order for file permissions to be preserved + build-unix: + env: + artifact-path: OpenSeeFace + tar-path: OpenSeeFace.tar + strategy: + fail-fast: false + matrix: + include: + - name: linux + os: ubuntu-latest + - name: mac + os: macos-latest + runs-on: ${{ matrix.os }} + steps: + - name: Pull OpenSeeFace + uses: actions/checkout@v3 + + - name: Create binary + shell: bash + run: | + chmod +x make_exe.sh + ./make_exe.sh + + - name: Move files for uploading + shell: bash + run: | + # Prevents the parent dist/ directory from being included + mv dist/facetracker ${{ env.artifact-path }} + cp -r models ${{ env.artifact-path }} + + - name: Fix permissions from PyInstaller + shell: bash + run: | + find ${{ env.artifact-path }} -type f -exec chmod -x {} + + chmod +x ${{ env.artifact-path }}/facetracker + + - name: Pack files into tar + shell: bash + run: tar -cvf ${{ env.tar-path }} ${{ env.artifact-path }} + + - name: Upload artifact + uses: ./.github/actions/upload-dated-artifact + with: + name: ${{ matrix.name }} + path: ${{ env.tar-path }} diff --git a/make_exe.bat b/make_exe.bat index a5ad490..a7b6ef8 100644 --- a/make_exe.bat +++ b/make_exe.bat @@ -1,16 +1,31 @@ -pyinstaller facetracker.spec --onedir ^ - --add-binary dshowcapture/dshowcapture_x86.dll;. ^ - --add-binary dshowcapture/dshowcapture_x64.dll;. ^ - --add-binary dshowcapture/libminibmcapture32.dll;. ^ - --add-binary dshowcapture/libminibmcapture64.dll;. ^ - --add-binary escapi/escapi_x86.dll;. ^ - --add-binary escapi/escapi_x64.dll;. ^ +echo "Started" + +:: A venv is used so it's easy to add the onnxruntime dll to the binary + +echo "Creating venv" +python -m venv venv + +echo "Activating venv" +call venv\Scripts\activate.bat + +echo "Installing dependencies" +pip install wheel + +pip install onnxruntime opencv-python==4.5.4.60 pillow numpy pyinstaller + +echo "Running pyinstaller" +pyinstaller facetracker.py --clean ^ + --onedir ^ + --add-binary dshowcapture/*.dll;. ^ + --add-binary escapi/*.dll;. ^ + --add-binary venv/lib/site-packages/onnxruntime/capi/*.dll;onnxruntime\capi ^ --add-binary msvcp140.dll;. ^ --add-binary vcomp140.dll;. ^ --add-binary concrt140.dll;. ^ --add-binary vccorlib140.dll;. ^ --add-binary run.bat;. -del dist\facetracker\cv2\opencv_videoio_ffmpeg420_64.dll +echo "Deleting opencv dll" +del dist\facetracker\cv2\opencv_videoio_* -pause \ No newline at end of file +echo "Finished" diff --git a/make_exe.sh b/make_exe.sh index dd2fd70..834d486 100755 --- a/make_exe.sh +++ b/make_exe.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e + PYTHON_BINARY=$(which python3) if [[ -z "$PYTHON_BINARY" ]]; then @@ -12,18 +14,18 @@ if [[ -z "$PYTHON_BINARY" ]]; then fi echo "Creating venv" - "$PYTHON_BINARY" -m venv venv source venv/bin/activate echo "Installing packages" +pip install wheel # Make sure this is installed beforehand pip install onnxruntime opencv-python==4.5.4.60 pillow numpy pyinstaller echo "Creating binary" - -pyinstaller --clean facetracker.py +pyinstaller --onedir --clean facetracker.py \ + --add-binary venv/lib/python3.*/site-packages/onnxruntime/capi/*.so:onnxruntime/capi echo "Files should be available in the dist/ folder" echo "Done!"